LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VISA Read Serial for X seconds and stop

Solved!
Go to solution

Hello to all!

 

Goal: Launch a .vi that starts reading from COM port X for 5 seconds and automatically stop, save the read data to a text file

Hardware: generic UART to USB serial converter

Software: Win10 + LabView 2017 + TestStand 2017

 

Additional Info:

COM port X is an debug UART that spits out information regarding a device. Some commands are sent to device through COM port Y, but results are shown in COM port X.

The flow of data being read from this COM port X is not constant. Data might not show up for 30 seconds at a time.

 

What I achieved so far:

Flush buffer of COM port X is done prior to opening the Debug_UART_Results.vi

I can start the reading, and after the loop ends, the data is stored in the text file as intended.

 

The issue:

The timer counts down only while actual data is read from COM Port X.

If data isn't read at any point, the timer pauses and waits infinitely for new data, therefore the loop does not stop.

If COM port is not active \ connected, the elapsed time boolean successfully stops the loop and the .vi closes as intended.

 

Work around - not acceptable:

To send additional dummy commands on COM port Y to keep data coming to COM port X so that the elapsed time closes the loop.

 

Alternative solution: I tried with two separate loops connected via channel writer - reader, but I just cannot make the Read debug UART loop to stop.

 

I'm sure the solution is simple and staring me in the face, but I just can't see it.

Any hints would be really appreciated.

 

Best Regards,

John

0 Kudos
Message 1 of 7
(1,706 Views)

Hi John,

 


@pinkman_john wrote:

Goal: Launch a .vi that starts reading from COM port X for 5 seconds and automatically stop

 

Additional Info:

The flow of data being read from this COM port X is not constant. Data might not show up for 30 seconds at a time.


So you want to read data for just 5s, but the device might not send new data for ~30s?

Which condition should start your countdown and which condition should end that countdown?

 

Comments on your VI:

Please use AutoCleanup to ensure basic style guidelines like "wires from left to right"…

You initialize the VISA connection to use the default timeout: VISARead might wait for 10s until it gives a timeout error in case no data arrived…

You don't seem to handle timeout errors at all!?

What's the point of this 10ms wait in the Read case? This wait belongs into the FALSE case!

I recommend to use a shift register, tied to the outer loop, to store the "read buffer" data (instead of the feedback node inside the case).

 

Example:

 


@pinkman_john wrote:

The issue:

The timer counts down only while actual data is read from COM Port X.

If data isn't read at any point, the timer pauses and waits infinitely for new data, therefore the loop does not stop.


The ElapsedTime will only update, when the loop is iterating: this is basic THINK DATAFLOW!

The loop can only iterate when the code within is finished: this is basic THINK DATAFLOW!

The code can only finish when VISARead finished (on Timeout, data read or TermChar): when no data is received it will wait for (default) 10s timeout!

I don't think your loop (aka timer) "pauses and waits infinitely"…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 7
(1,697 Views)

Hi GerdW,

I'm sorry for my poor choice of words, I am not an native English speaker.
I am also a beginner with Labview and I have much to learn.

To answer your questions:

 

So you want to read data for just 5s, but the device might not send new data for ~30s?

If the device behaves normal, it will respond within 1-4 seconds.
If the device is not responding to commands (test will FAIL), then yes, data might not be available up to 30s when other processes output their status.


Which condition should start your countdown and which condition should end that countdown?
The 5s countdown should start as soon as the .vi opens.
The VISA Read should stop after the time has elapsed, log the data (if any) and close the .vi

 

I believe my problem is with this part: "The code can only finish when VISARead finished (on Timeout, data read or TermChar)"

I can't use the ThermChar, as I might get multiple messages depending on the command.
I can't rely on data read, as there might not be any data available.
I can't rely only on Timeout, as there might be a massive data read due to other processes \ errors, which might keep the loop running for a long time.

I am relying first on the Elapsed time boolean to stop the Read Debug UART loop.
If there is more data to be read, the current iteration should finish and stop the loop.
If there is no data available, the Timeout (set to 1s) should stop the loop.

pinkman_john_0-1604258531066.png

 

If you have any other ideas or suggestions I would really appreciate it.

 

Best regards,

John

0 Kudos
Message 3 of 7
(1,618 Views)

Hi pinkman_john,

I think you should monitor the serial port for any bytes during the wait of 30 seconds using the 'bytes at port' property.If the bytes are more than zero ,then you have to read that many bytes from the serial port and log the data during those 5 seconds and stop the loop.

Also i think the read timeout from a serial port cannot be changed once configured.

 

 

Regards,
Srikrishna


0 Kudos
Message 4 of 7
(1,596 Views)
Solution
Accepted by topic author pinkman_john

Hi John,

 

what's the point of that channel wire and separate loop?



@pinkman_john wrote:

I can't use the ThermChar, as I might get multiple messages depending on the command.


Then you should disable the TermChar - you did not so far…

 

Btw. there is a VISA property node for "TimeOut" so you can change it at any time.

Do you really need this "default if unwired" tunnel in the case structure?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 5 of 7
(1,590 Views)

Hello Srikrishna, thank you for the reply.

 

The whole .vi should execute in less than 7 seconds.

The response if available is read in less than 5 seconds.

I mentioned that the device may not respond to the particular command, therefore there won't be any data read.

Once every 30 seconds the device will send some data related to other processes, but this data is not relevant.

 

The 'bytes at port' property is a good idea. Thanks!

 

Ionut

0 Kudos
Message 6 of 7
(1,580 Views)

Hi GerdW,

 

The separate loop is just to display the "timer" and elapsed time boolean in real time on the front panel (it's visible during the test in debug mode so I can see the response in real time).

Also being new to Labview, I am trying different techniques to get familiar with them.

 

Yes, I should disable the ThermChar. Thanks!

 

Btw. there is a VISA property node for "TimeOut" so you can change it at any time.

I have it as a controll and it can be adjusted from TestStand for any particular case.

 

Do you really need this "default if unwired" tunnel in the case structure?

You mean for the string in "False" case? I guess not. I connected the in and out directly.

 

Thank you all for the support and feedback.

Best regards,

 

John

0 Kudos
Message 7 of 7
(1,577 Views)