LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Visa serial vs hyperterminal

Solved!
Go to solution

Hi

i have a problem using visa serial with my IoT device. when i connecting it to the hyperterminal its working fine.  When i entering ttt command without pressing Enter button , my device shows in the hyperterminal window terminal commands menu about 25-30 lines of commands at the end it shows Cmd> .

when i enter Battery 1(Enter pressed) command at the prompt, my device replies with these lines:

Battery connectedCRLN

LN

Battery Done!!!CRLN

LN

Cmd>

------------------------------------------------------------------------------------

when i'm trying to use this algorithm with visa serial it's not working. I can send through visa write command ttt and i see the terminal menu and Cmd> prompt in the buffer output. When i'm trying to send Battery 1 command, it's shows me only 4-7 bytes of some ascii code not the output i need.

i have tried to add '\r\n' , '\r' to the command string of Battery 1. but it did nothing. also i have tried to change visa serial config termchar enabling add cr or ln. but these changes are also did nothing. NI Trace also gives some garbage and couple of dots at the and of the outputs this all. may be you have some advice

Message 1 of 5
(2,169 Views)

Hello, Arbo.

 

     You've been active on the Forum for several years.  Several times a month for the past 4-5 years, someone, as you did, posts a problem involving LabVIEW VISA, and gets exactly the same advice -- Do Not Use Bytes-at-Port, especially if (as in your case) the VISA Configure Serial Port is left in its default setting, "Use Termination Character", and the VISA Device being read (as yours does) sends text commands terminating them with a "Termination Character" (by default, <NL>, again as you demonstrate yours does).

 

     This is almost certainly the problem with your code.  Remove the "Bytes at Port" function, and change your VISA Read to read 1000 characters (or any other number that you are sure is larger than the largest string you expect to receive -- my "magic number" is 1024).  You will get 10-40 characters back (depending on your device and how verbose it is), and you can just process them, knowing you have "all the data".

 

     But all is not lost -- at least you attached your code, so finding the problem was very easy and quick.

 

Bob Schor

0 Kudos
Message 2 of 5
(2,153 Views)
Solution
Accepted by Arbo

1. You are looking only at what happens to be in the buffer at the moment you check the Bytes At Port.  You can't know if the line is complete, so it is very easy to split the string you are looking for.

2. I don't see anywhere in the protocol you listed where the device outputs "Done".

 

As Bob already stated (enter my macro):

DO NOT USE THE BYTES AT PORT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! (still not enough emphasis)

You expect your device to output lines.  So let's use that to our advantage.  Just tell the VISA Read to read more bytes than you expect in a single line.  You could do that in a loop until you have a timeout or you get the response you expect.

 

You could also use a bunch of cleaning up of your code in general.  Here is a quick cleanup I did with your code.


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 3 of 5
(2,143 Views)

Please consider and vote for this Idea Exchange Entry:

 

https://forums.ni.com/t5/LabVIEW-Idea-Exchange/Add-regex-based-termination-string-option-to-NI-VISA/...

 


Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
If you don't hate time zones, you're not a real programmer.

"You are what you don't automate"
Inplaceness is synonymous with insidiousness

0 Kudos
Message 4 of 5
(2,082 Views)

Thanks very much. it works

 

by the way i found also the problem with reading data after the Battery 1\r command. it must be by character. i have splited Battery 1\r command in to the characters and passed all one by one in to the Visa Write.  after this process, i got the appropriate answer from the device.

Message 5 of 5
(2,077 Views)