LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to compare an Input signal (String from Serial Port)

Hi National Instruments Community, as you can see in the next picture I'm using Ni-Visa to get an string by serial port, after that I'm dividing the string in parts (pairs) and putting them into an Array.  the real answer here is how can I get a boolean True when I get a different string on my "Input Signal".

I'm sending by Serial Port a String every 1 second, and when I send a different string intro my "INPUT SIGNAL" I want to get a boolean TRUE. 

If you can tell me how or send me an example it would help me a lot. Thank you.

(sorry for my english)

capture.PNG

0 Kudos
Message 1 of 9
(4,217 Views)

First of all, remove big STOP hex. It aborts the VI and prevents clearing VISA (3 VIs after loop become useless).

 

To compare values at different iterations, you use shift register and comparison palette (not equal function). "Input signal" into shift register and compare with string from shift register

 

Message 2 of 9
(4,190 Views)

A couple more style enhancements

Match regular expression.vi  understands "[0-9]{2}" - match 2 digit number. Match pattern does not.

I guess you can connect error cluster directly to case selector, it will remove 2 nodes and make a nice visual appearance of the case. But it depends on LV version

Also, if your version allows, it is generally better to attach snippets. We are too lasy to recreate all your code to show changes to answer your question.

Message 3 of 9
(4,187 Views)

You are right, I didn't know their name, so I coudn't search how to put them xD thank youSnippet Input Signal.png

0 Kudos
Message 4 of 9
(4,183 Views)

I did not use VISA events before, is it better than regular functions? 

 

I increased timeout a little - exact period of input can lead to false timeouts (data received 0,5 ms after timeout).

Also it would be nice to monitor errors inside loop and discard only timeout if you are not sending pulses

Detect string change.png

0 Kudos
Message 5 of 9
(4,135 Views)

Hope its good to use Number of bytes at serial port and then you can read if the Number of bytes at serial port is greater than 0

The same value can be feed to Read VISA Function

----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------
0 Kudos
Message 6 of 9
(4,132 Views)

I do not like bytes at serial port, because it generally requires polling. I would say it is usefull when you do not know how often messages are arriving, how long they are and without terminating character. It looks like a bad designed instrument.

I did not like Event "Serial Character", because it may (or may not) generate multiple events per message. Then you need to discard events after you have read full message. But this VI might be usefull when period is not fixed.

VISA read timeout will indicate incomplete message and for fixed period does the same as Wait for event, then Read. 

0 Kudos
Message 7 of 9
(4,128 Views)

@PalanivelThiruvenkadam wrote:

Hope its good to use Number of bytes at serial port and then you can read if the Number of bytes at serial port is greater than 0

The same value can be feed to Read VISA Function


Assuming the instrument uses a termination character (as the OP currently has set up), you do NOT want to use the Bytes At Port to tell the VISA Read how many bytes to read.  Tell it to read more than the longest message you would expect.  This way the read will stop when it encounters the termination character and you therefore know you got the entire message.


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 8 of 9
(4,125 Views)

@Alexander_Sobolev wrote:

I do not like bytes at serial port, because it generally requires polling. I would say it is usefull when you do not know how often messages are arriving, how long they are and without terminating character. It looks like a bad designed instrument.


What I do for instruments that randomly send data (no real timing between messages) is use the Bytes At Port to see if there is any data in the port (count is greater than 0).  If there is data, I can assume that a message has at least started to come in, so I use VISA Read to read the entire message (count > longest message expected).  If there is no data, I typically throw in a wait.  I do this because I have ran into the situation where the timeout on my read happened before the entire message was read, giving me only part of the message (the message was sent by the instrument right when the read timeout was about to complete).  This is the only true legitamite time I have used Bytes At Port.  I am sure there are other places where it makes sense, I just haven't found it.

 

Note: The above scenario is only valid for ASCII data that has a termination character.


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 9
(4,120 Views)