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

Hello,

 

I am reading data byets coming to my COM port using VISA read function.

 

Is it necessary that my LabVIEW code always should be in receving mode first and then only I can transmit the data?

 

I am asking this because; when I executed my VI after transmitting data bytes there was no data byets received ; instead there was an error saying Timeout has expired before operation could be completed.

This case is not desired for my application.

 

Isn't any Buffer kind of thing where all data byets get stored once I trasmit them and get displayed all at once when  I run the VI ??

and if not is it possible to achieve such kind of synchronisation in LabVIEW?

 

Kindly help.

 

Best Regards,

Snehal

 

 

0 Kudos
Message 1 of 16
(3,738 Views)

Lots of ground to cover.  Most importantly, have you read the manual?  It gives you the COM port settings.  It also shows you what the command structure looks like.  We can't even guess on what is going on until you can give us more information.

 

With the type of questions you are asking, be prepared for a steep learning curve.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 2 of 16
(3,737 Views)

Hi,

 

One thing I forgot to mention is  that I am using an USB to Serial Converter for my comminication.

 

Please find my VI attached herewith.

 

Best Regards,

Snehal

0 Kudos
Message 3 of 16
(3,732 Views)

VI is in LV 2010

0 Kudos
Message 4 of 16
(3,730 Views)

@SuLAB wrote:
I am reading data byets coming to my COM port using VISA read function.

 

Is it necessary that my LabVIEW code always should be in receving mode first and then only I can transmit the data?

 

I am asking this because; when I executed my VI after transmitting data bytes there was no data byets received ; instead there was an error saying Timeout has expired before operation could be completed.

This case is not desired for my application.

 

Isn't any Buffer kind of thing where all data byets get stored once I trasmit them and get displayed all at once when  I run the VI ??

and if not is it possible to achieve such kind of synchronisation in LabVIEW? 


 

There is no such thing as a "receiving mode" when it comes to serial ports.  There are totally seperate lines for transmit and recieve.

 

Where is this data supposed to be coming from?  Instrument?  Loopback cable?  Microcontroller?  Another computer?

 

Are you trying to use the serial port as a place to hold data?  That isn't how it works.  When you transmit the data, it is gone to whatever is on the other side of the serial cable.

 

What EXACTLY are you trying to accomplish here?


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 5 of 16
(3,728 Views)

Hi Snehal,

 

on your VI:

so you initialize a serial port, which most often also clears any buffered data (if they even existed before).

Immediatly after initialization you check the number of bytes in the read buffer: that should be zero nearly all the times. At 19200baud it takes ~500µs to send a byte…

Then you try to read those zero bytes from the buffer to close the serial port immediatly after.

 

Is there any sense in doing so?

Best regards,
GerdW


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

Hello,

 

This data is coming from another PC which has a uitility called Docklight from where I transmit the data bytes.

 

Afterwards this simulation will be replaced by a microcontroller which transmits some data after receiving certain command.

 

I right now don't have that micro-controller hence I am sending those data bytes through Docklight to LabVIEW.

 

By writing "Receiving mode" I was trying to ask that whether my LabVIEW VI should be Running before I start sending any data?

 

This is my flow-

 

1. I create a frame in docklight and say Send

2.Then I run the UART_Rx.vi

 

Where I get a time out error with no data.

 

So what I am wondering is that where this data has gone ? If I have transmitted it;it should be there somewhere on the port

Then why I am not able to retreive it?

 

I hope I have cleared myself to you

 

Regards,

Snehal

0 Kudos
Message 7 of 16
(3,716 Views)

Hi Snehal,

 

If I have transmitted it;it should be there somewhere on the port

No, as you initialize that port after the data has been sent!

First start the receiver (your UART.vi), then send the message data. A serial cable is no data buffer!

 

But you also need to change your UART.vi, mainly by getting rid of "Bytes at Port"…

 

 

Best regards,
GerdW


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

Hi GerdW,

 

I just referred to the Basic serial read write VI in NI Example Finder .

 

I don't need Write part of it hence I just followed the part of the code where there is "Read" performed.

That's it!!

 

Regards,

Snehal 

0 Kudos
Message 9 of 16
(3,708 Views)

Hi Snehal,

 

the Basic example also includes a Wait function - for a special reason. You didn't get that reason, don't you?

 

Better use the Advanced example. It also includes a loop and works without BytesAtPort…

Best regards,
GerdW


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