From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using VISA Read Function to read bytes on the serial port

Hi GerdW,

 

First start the receiver (your UART.vi), then send the message data

 

So that is what I was asking ; is it necessary always to run my receiver (any receiver VI ) first and then transmit?

 

I know serial cable is not a data buffer; but there are UART buffers on the PC motherboard right???

 

So can't I retrieve the data from those buffers?

 

Regards,

Snehal

 

0 Kudos
Message 11 of 16
(484 Views)

SnehalLVLover wrote:

So can't I retrieve the data from those buffers?


Only data that gets recieved can you get from a buffer.  The transmit buffer is purely for the transmitter to read.

 

Do you have a format figured out for how the data will look like coming from your microcontroller?  Are you sending and recieving ASCII data or raw binary data?  This makes a big difference in how I would set this up.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 12 of 16
(480 Views)

Hi Snehal,

 

those buffers are maintained in the hardware drivers. When you initialize the serial port the hardware driver initializes the port chip/hardware - this will clear any data in the buffer. Afterwards that buffer is used to minimize CPU load by enabling event based data transfers instead of relying on polling…

 

You need to start the receiver first!

 

@Crossrulz:

Look at Snehals yesterdays post on data format…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 13 of 16
(478 Views)

Hi GerdW,

 

Yes I noticed that function also and when I hovered the mouse over that Wait function it says that- Delay between the write and when read should occur. This gives devices the time to respond.

 

And this is the same how I interpreted it literally.

 

So, if I my program flow is not like - Write first and then Read, why would I add a wait function?

 

Regards,

Snehal

0 Kudos
Message 14 of 16
(475 Views)

Hi Snehal,

 

you would add a wait function because of the reasons I tried to examine by analyzing your VI in a recent post (message #6)…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 15 of 16
(472 Views)

@SuLAB wrote:

Hi GerdW,

 

Yes I noticed that function also and when I hovered the mouse over that Wait function it says that- Delay between the write and when read should occur. This gives devices the time to respond.

 

And this is the same how I interpreted it literally.

 

So, if I my program flow is not like - Write first and then Read, why would I add a wait function?


If you are not writing, then you don't need to wait as much.  However, you may have to wait just for data to come in from the microcontroller.

 

Is the data message from the microcontroller always going to be the same length?  If so, there is no need for the wait at all.  You just set the VISA Read to read the number of bytes in a message.  You will get a timeout error if those bytes don't come in.

 

So your setup should really be Initialize Serial Port, loop{ read data }, close serial port.  You should only initialize the port at the very beginning of your program and the close it at the very end.  This will keep you from clearing those buffers and missing data.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 16 of 16
(465 Views)