LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with serial read

Hi! All,
I am using serial compatiable VIs from serial.llb to read the data from COM1 port. My VI does not read the data correctly and the behaviour is not consistent.
On writing the command "st\n" the hardware actually sends back "ET,100.00,120.25" followed by carriage return.
When I exectute the serial VI then it returns the following string "st\r\n\rET,100.00,120.25\s\r\n".
Now the above string is rturned in every Consecutive runs for example on the first execution it returns the string "st\r\n\rET,100.00,120.25\s\r\n". Then on the second execution it returns empty string and again on third execution it returns the string and so forth.
Any suggestions why is it behaving in this manner?
0 Kudos
Message 1 of 6
(3,654 Views)
Hey Rachana,

The first thing that I noticed that was wrong with your VI is that you had no flow control in your program. You can't tell if the Read, Close, Write, or Init function is going to be called first. I took your VI and put it into a sequence structure and it works fine now.

However, I wouldn't suggest using the compatibility VIs. I would use the VISA commands. They are faster and provide more functionality and NI will continue to support them in future versions of LabVIEW.

I have attached the fixed version of your VI. Note port 1 is COM2 and I added indicators for the errors.

JoshuaP
National Instruments
0 Kudos
Message 2 of 6
(3,654 Views)
Hi! JoshuaP,
The reson I am using the compatibility VIs is b'coz my application will be deployed on PDA.
I used the VI you had fixed and changed it with sertain requirements but still I do not get the desired behaviour.The VI- "Bytes at serial port" always return 4 bytes and displays the same string which is written on the port using Serial Write.vi
The changes made are:
1. concatenated the command string with termination character(\n) and then sending it to the Serial Write VI.
2. Added the timeout feature in the while loop of Serial Read.vi.
3. In the while loop I am getting the Bytes at serial port and then reading 128 bytes everytime as the data will be of 512 bytes.
I am attaching changed VI.
TIA
Rachana
0 Kudos
Message 3 of 6
(3,654 Views)
Hi! JoshuaP,
Attached is another VI which I tried but the same issue.
For details see the comments on the block diagram.
TIA
Rachana
0 Kudos
Message 4 of 6
(3,654 Views)
Hey Rachana,

Did you try the VI that attached? You should be able to connect pins 2 and 3 together for a standard RS-232 port and see the data that is written out read back. Check to verify that you are using the correct port. The program should have worked perfectly. If not you might have some of the settings wrong in the device manager.

I would suggest taking one step back and see if you can use the hyperterminal to loop back the port.

http://zone.ni.com/devzone/conceptd.nsf/webmain/D48BA43C59B60277862569EE000501FD?opendocument

If you are connected to an instrument, then it is possible that it has echo mode turned on.

http://digital.ni.com/public.nsf/websearch/6C6322FF8F9B790486256D6B0069D281?OpenDocument

I hope th
is helps out.

JoshuaP
0 Kudos
Message 5 of 6
(3,654 Views)
Use Port 0. Port 1 may not exist on all PDAs.
0 Kudos
Message 6 of 6
(3,654 Views)