07-05-2016 03:18 PM
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)
07-05-2016 04:54 PM
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
07-05-2016 05:09 PM
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.
07-05-2016 05:37 PM
You are right, I didn't know their name, so I coudn't search how to put them xD thank you
07-06-2016 08:37 AM
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
07-06-2016 08:42 AM
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
07-06-2016 08:59 AM
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.
07-06-2016 09:06 AM
@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.
07-06-2016 09:12 AM
@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.