07-12-2023 01:00 PM
Hi, I'm having a strange issue while serially communicating with a device.
I'm using the enlosed VI and trying to simply get the command prompt read from the device with a carriage return.
This works intermittently, at times it returns the prompt. Other times it outputs an error that I can replicate using Tera-Term my sending a break command.
Any idea of how I can fix my vi to make it more stable and avoid the error? Thanks!
Solved! Go to Solution.
07-12-2023 01:09 PM
DO NOT USE THE BYTES AT PORT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! (still not enough emphasis)
You are using a termination character, so just tell the VISA Read to read more data than you ever expect to be returned. This will also eliminate the need for the wait immediately after your write.
07-13-2023 09:54 AM
I was afraid you were going to suggest that 😞
I read in many of the discussion groups to not use the Bytes At Port. Unfortunately that is the only way I was able to get the VI to run without a run error.
I can not set the Byte Count input to a high number as then I get a Visa Read Error and a long ~10 second time out.
The only way I can get the VI to run successfully without an error is to enter the exact number of bytes at the VISA Read input as I am getting as a Return Count output.
Hopefully there is just something fundamental that I am missing. This is my first go at a serial port VI. 😖
Enclosed is my screenshot from today's trial.
Thanks
07-13-2023 10:17 AM
So this is interesting....
I made some changes to my VI to keep it simple (stupid=me) 😂 and now I can get a stable response to my commands..BUT I have to wait for the 10 second time out as I still get the read error. If I can get past the error/delay I'll be in business!
07-13-2023 10:27 AM
tom.pascente@gmail.com wrote:
So this is interesting....
I made some changes to my VI to keep it simple (stupid=me) 😂 and now I can get a stable response to my commands..BUT I have to wait for the 10 second time out as I still get the read error. If I can get past the error/delay I'll be in business!
It's timing out because you are never getting 2000 bytes. Try just enabling your termination character and it should work.
07-13-2023 10:49 AM - edited 07-13-2023 10:50 AM
tom.pascente@gmail.com wrote:
I was afraid you were going to suggest that 😞
I read in many of the discussion groups to not use the Bytes At Port. Unfortunately that is the only way I was able to get the VI to run without a run error.
I can not set the Byte Count input to a high number as then I get a Visa Read Error and a long ~10 second time out.
The only way I can get the VI to run successfully without an error is to enter the exact number of bytes at the VISA Read input as I am getting as a Return Count output.
What I generally do for serial terminals is read 1 line at a time (Line Feed, 0x0A, is the termination character), using a queue to pass each line elsewhere for processing. There is actually a lot more functionality I put into the terminal library (logging, handling errors, etc.), but the core is a queue to sending commands through the serial port and a different queue(s) for sending the data to where it is needed.
Here is a snippet of the VI I use for reading a line of data. I am using the Bytes At Port only to see if there is data to read. I am not using it to tell the VISA Read how many bytes to read. The timeout here is typically 50ms. This is to handle the terminal prompt.
07-13-2023 12:59 PM
Thanks for your replies. Seems the issue may be with my termination character.
The Enable Termination was set to False by accident, as I was changing various things to troubleshoot my issue.
When infact the Enable termination was set to True, I still have the timeout...thus my character is not correct.
I have two prompts on the device I'm connecting to. My Pre-Login prompts:
ab-c-02 Login:
Password:
Then my logged in prompts
ab-c-02:~$
In the pre-login prompt when I set my termination character to :, it is not working
In the post -login prompt, $ does not work either
If I set the login prompts to the enter prompt character (ie ab-c-02 Login:), I no longer have the timeout but do not receive the right output I'm expecting.
Am I barking up the right tree in terms of chasing my issue down?
PS: thanks for your VI to read a line of data. In my application unfortunately it didn't provide any output. But it may be the termination character issue that may be preventing it from working?
07-13-2023 01:38 PM
tom.pascente@gmail.com wrote:
I have two prompts on the device I'm connecting to. My Pre-Login prompts:
ab-c-02 Login:
Password:
Then my logged in prompts
ab-c-02:~$
In the pre-login prompt when I set my termination character to :, it is not working
In the post -login prompt, $ does not work either
This goggles my mind. There has something else happening. Any other errors other than the timeout?
07-13-2023 03:04 PM
No other errors.
In fact, I can hack my way to getting my VI to work by setting the timeout from 10 seconds to 500 or 250 ms and accepting the error that is caused most likely by my prompt issue.
The output data is stable and duplicates what outputs from a tera-term connection. I just have an ugly error red x to see on my VI panel.
I'd like to figure out what is going on, but for now I'll need to run with the bandaid to meet a schedule. (I feel dirty)