05-12-2020 07:19 AM
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
Solved! Go to Solution.
05-12-2020 07:37 AM
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
05-12-2020 08:01 AM - edited 05-12-2020 08:03 AM
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.
05-13-2020 08:16 AM
Please consider and vote for this Idea Exchange Entry:
05-13-2020 08:50 AM
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.