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.

Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial communication blocks my while loop

Solved!
Go to solution

Hi everyone. I need your help with my program. I am using LabView2014 and an Agilent B2902A.
I want to measure current value with my instrument continuously, store values every second and display messages received through the serial port when I get some. 
Everything works perfectly separately but when I put everything together I have this problem: my instrument is waiting for a message from the serial port to take (and display) a measure. 
Do you have any idea to save my problem? 
Thank you ! 

 

Pauline

(Please find attached a screenshot of my program)

0 Kudos
Message 1 of 10
(4,951 Views)
Solution
Accepted by topic author Oxydroid

Use bytes at serial port to check if a message is available and only read when a message is available.

greetings from the Netherlands
0 Kudos
Message 2 of 10
(4,946 Views)

@Albert.Geven, thanks for the fast reply. 

I don't know how to test if there is a message before reading. Could you give me more details to do it? 

0 Kudos
Message 3 of 10
(4,940 Views)
Solution
Accepted by topic author Oxydroid

@Oxydroid wrote:

@Albert.Geven, thanks for the fast reply. 

I don't know how to test if there is a message before reading. Could you give me more details to do it? 


Use the Bytes At Port property and test to see if there are more than 0 bytes available (Greater Than 0?).  Use a case structure to conditionally read the serial port.


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 4 of 10
(4,920 Views)

@crossrulz and Albert.Geven

I tried it as you can see on the new screenshot attached to this message but it is not working better... Maybe I did it wrong? 

0 Kudos
Message 5 of 10
(4,911 Views)

@Oxydroid wrote:

@crossrulz and Albert.Geven

I tried it as you can see on the new screenshot attached to this message but it is not working better... Maybe I did it wrong? 


Post your VI not a screenshot

0 Kudos
Message 6 of 10
(4,908 Views)
What is your second instrument and how is its reading related to the 2902? How many bytes are you trying to read?
0 Kudos
Message 7 of 10
(4,894 Views)

You only should read when bytes at port>= bytes to read

because if the message is not completely available it will block the other process

 

And indeed don't send pictures but the vi then we can eventually update it in a correct way

greetings from the Netherlands
0 Kudos
Message 8 of 10
(4,884 Views)

@Albert.Geven wrote:

You only should read when bytes at port>= bytes to read

because if the message is not completely available it will block the other process


My thought on that is that if there is data there, the rest of the message will be there shortly.  There may be a brief blocking, but not likely enough to matter, depending on how long your message really is.


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 9 of 10
(4,880 Views)

Thanks to all of you, I solved my problem. First, it was what you said (test to read only if there is a message available) and then it was that my excel file was full (I guess so because it didn't want to store my variables anymore and block the all process).
Next time, I will send the VI and not screenshot as you asked.

0 Kudos
Message 10 of 10
(4,877 Views)