10-08-2019 09:28 AM
@crossrulz wrote:
@ShotSimon wrote:
I would also be interested to see where and how you implement the fake timeout error.
I have just set the timeout to something short (500ms, at least long enough to read an entire message) and let the VISA Read time out. It will return whatever was already in there. You can choose to throw that away or add the CRLF yourself on the timeout. I have done both methods.
I meant that if you never get anything (always the "0" case) you probably don't want to keep trying forever.
10-08-2019 10:15 AM
@billko wrote:
@crossrulz wrote:
@ShotSimon wrote:
I would also be interested to see where and how you implement the fake timeout error.
I have just set the timeout to something short (500ms, at least long enough to read an entire message) and let the VISA Read time out. It will return whatever was already in there. You can choose to throw that away or add the CRLF yourself on the timeout. I have done both methods.
I meant that if you never get anything (always the "0" case) you probably don't want to keep trying forever.
With my set ups, yes, I do try forever. That is because I make my serial communications its own loop to act as the terminal interface. It will constantly try to read and it will write if it gets a command to (via a queue). This loop does not care if the instrument responds or if it is constantly spitting out data. Any data it reads gets logged (with a date/time, great for debugging) and optionally sent through any number of queues (each command gives a queue reference and an expected pattern for the return data).
10-08-2019 11:15 AM
@crossrulz wrote:
I'm going to put some people into shock here...Do use the Bytes At Port. I haven't had much luck with the VISA Events, so what I do is use the Bytes At Port to see if any message has started. I can then read a full line. If there is no data (bytes = 0), then I use a short wait (50ms) before checking again. This allows the loop to handle the stop button or messages coming from other loops fairly often while also keeping the serial port as a priority.
NOTE: The "0" case just wires the error and VISA Reference through along with a 50ms wait.
I am in shock.
Now, I KNOW that not every interface designer follows the following:
10-08-2019 12:00 PM
@JÞB wrote:
Declare Size of Package- yup ACSII STX Followed by 4 hex characters that define the size of the Text Block (Yeah, STX means "Start Of Text") so just look for STX then grab 2bytes then grab the rest. <These developers need to throw out their ASCII billboards and get a ASCII Chart on a mouse-pad>
The only time I have seen the STX character used is in a raw/hex/binary data format. Any ASCII based protocol I have seen has no start character, only a termination character.
Now in the case of this thread, we are dealing with a terminal. Terminals just write raw strings back and forth because there are an infinite number of possible commands. So the only real way to state that a command or data is done is to write a new line. Therefore, the termination character is very important.
Yes, I deal with Linux terminals constantly.
10-08-2019 02:00 PM
I definitely want to write out whatever comes over the serial port so a constantly running terminal is mostly like the best solution for my application. I have seen some protocols that are very strict like GPS ASCII data but the Command-Line-Interface (CLI) that I have worked with lately typically put out anything they see fit or even worse no response at all. Which usually leaves me with a follow-up command to get the data to confirm it was received. That is if they have written a "get" to get the information back.
I think Crossrulz has a solution to my initial problem (if you take out the caveat of the ">" character. Others have suggested solutions that I might investigate further when time permits. I do want to follow-up with how to handle a state machine in this event structure or outside of it in some event controlled fashion? Do you recommend I start a new thread, marking Crossrulz solution complete or continue here with the remainder of my application design question?
-SS
10-08-2019 02:40 PM
@ShotSimon wrote:
marking Crossrulz solution complete
Absolutely! ![]()
@ShotSimon wrote:
I do want to follow-up with how to handle a state machine in this event structure or outside of it in some event controlled fashion? Do you recommend I start a new thread
Probably best to start a new thread.
07-19-2020 10:57 PM
This solution works great for VISA read but I am not able to figure out how to add VISA write to the code based on user events on the UI like clicking specific buttons to send commands over VISA. Any help will be much appreciated.
07-20-2020 06:42 AM
@SpaceTrek wrote:
This solution works great for VISA read but I am not able to figure out how to add VISA write to the code based on user events on the UI like clicking specific buttons to send commands over VISA. Any help will be much appreciated.
VIWeek 2020/Proper way to communicate over serial
There are examples available that show this.
07-20-2020 10:16 PM
Thank you for your reply. I looked at the video, I am not familiar with action framework. How would you recommend I hand the data coming in and commands being sent by user clicks on buttons. I have an Arduino MCU controlling my device, and the UI is for getting stream of status updates, and then bursts of recorded data from sensors based on user commands sent. I am attaching the VI that I have put together, the button click latches on for too long, and sometimes sends multiple characters over the serial port with just one click.
07-20-2020 11:04 PM
Duplicate Message.
Continue conversation in its own new thread.
https://forums.ni.com/t5/LabVIEW/VISA-Read-Write-and-User-Events/m-p/4068772