LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

labview program working in highlight mode and not working in normal mode

Solved!
Go to solution

Hi All,

 

I would like to explain my program first,

 

I wrote a program where trying to establish communication between Labview and microcontroller. By this program I am trying to select the serial com port automatically. I have attached VI which clearly shows the logic which I have used. Labview checks each and every port which are working on the computer, visa write 's' and waits to read 's' . If 's' is recived  then loop ends here and diplays the right port where the microcontroler is connected. Otherwsie it continues to search...... every logic is working I tried to check for all cases it is working but it is only working in Highlight mode. When I try to run in normal mode the loop is continuously running not able to read microcontroller properly. I have checked for the Baud rate,no of bytes ect.,,, tried out somany ways....but still it is not working.

 

I have checked with all the delays but i couldn't figure where the problem is coming from. I don't have much expirence with Labview......Can any one please help me to solve this problem?

 

Thankyou

Deepthi

0 Kudos
Message 1 of 22
(5,174 Views)
Solution
Accepted by topic author Deepthi23

I see a lot of possible race conditions in your code and no delay between writing an "S" and reading the port.

 

 

 

Also don't do this:

 

D1.PNG

 

Do it this way:

 

D2.PNG

 

You may have to invert your logic too.

 

D3.PNG

========================
=== Engineer Ambiguously ===
========================
Message 2 of 22
(5,161 Views)

Thankyou for your response.

 

I have made the changes as per your suggestions and also tried to insert a delay for the while loop. But still it is not working. I have the same problems as before logic is working but not in the normal mode. I have attached the modified vi.

 

Please check

0 Kudos
Message 3 of 22
(5,146 Views)
Solution
Accepted by topic author Deepthi23

Maybe your delays are still too short or maybe you need a delay elsewhere.

 

Why are you configuring the serial port with every iteration of the loop? You only need to do that if one of the parameters changes. Do they ever?.

 

While you are at it, try to eliminate all these "equal TRUE" Rube Goldberg code fragments. All it returns is the original boolean so a simple wire would be equivalent. Keep it simple! 😄

Message 4 of 22
(5,143 Views)

Is 100mS long enough delay?

 

Also listen to 

 

========================
=== Engineer Ambiguously ===
========================
Message 5 of 22
(5,137 Views)
Solution
Accepted by topic author Deepthi23

You're kind of convoluting the code too much. You can simplify it to just attempting to initialize the serial port which, if it is not the correct port, will merely return an error which you clear and continue the search. If it manages to make a correct connection, it sends S and tries to read back an S which, if succesful, sends a true to the stop condition and delivers the correct port and the read S.

 

EDIT: I forgot to add a for loop instead of a while, so it will take the auto-indexed input and attempt once with each iteration.

 

COMcast.png

Message 6 of 22
(5,130 Views)

Thankyou somuch Daikataro.

 

I have tried out the code you have posted. It is working fine in the Highlight mode as before but showing a wrong resourcename as out put and not reading 's' in the normal mode. I couldn't find out the problem. I need to run the program without stopping untill it finds a right port without exiting the program but this code will not run the program untill we find the right port. Do you have any mopre suggestion for the code?

 

Please help to find the solution....

 

May  be my next update will 3 days later as  I am in holiday......I am sorry!!!

 

0 Kudos
Message 7 of 22
(5,110 Views)

Don't follow Daikataro's VI because he failed to do several of the things that Altenbach pointed out.

 

1.  A wait AFTER the VISA Write before checking the Bytes at Port to give the instrument time to handle the message and send the response.

2.  Getting the Serial Port configuration OUT of the loop.

Message 8 of 22
(5,097 Views)

Who even needs the Bytes At Port?  Just let the Timeout come into play!  When I had to do an auto detect, I did something similar to this:


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
Download All
Message 9 of 22
(5,077 Views)
Solution
Accepted by topic author Deepthi23

@Deepthi23 wrote:

Thankyou somuch @Daikataro

 

I have tried out the code you have posted. It is working fine in the Highlight mode as before but showing a wrong resourcename as out put and not reading 's' in the normal mode. I couldn't find out the problem. I need to run the program without stopping untill it finds a right port without exiting the program but this code will not run the program untill we find the right port. Do you have any mopre suggestion for the code?

 

Please help to find the solution....

 

May  be my next update will 3 days later as  I am in holiday......I am sorry!!!

 


What do you expect? Bytes at serial port will return the numbers of bytes in the buffer at the moment it is executed. Not the number of bytes the device might send or not send in the future.

In Highlight node there are many 100ms between the time VISA Write sends the command and Bytes at Serial Ports deterimines the number of bytes received in the receive data buffer by the COM port driver. When executing normally there is not even 1ms between the two and that is for most serial instruments not even enough to decode the command and decide what to return, and then returning the data takes even longer depending on the baudrate (your 9600 baudrate means at least 1ms per character also for sending, so from the moment your VISA Write returns, which only places the data into a buffer and doesn't wait until the data is actually sent to the device, it takes already at least 1ms before the actual character is transmitted to the device, some more ms for the device to decode the command and decide what to do and then again 1ms before the first character is received at your computer). LabVIEW can in that time execute Bytes at Serial Port a few 100 times and do in parallel some number crunching and graphic calculations too.

 

And again my pet topic about VISA communication: DO NOT USE "Bytes at Serial Port" EVER. It is in 99.9% of the cases not only not necessary but even outright wrong! If you believe it is necessary think again, chances are almost 100% that you are wrong especially if you haven't already written a few 100 instrument drivers in LabVIEW or even just using VISA.

Rolf Kalbermatter
My Blog
Message 10 of 22
(5,036 Views)