LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

The serial port is not sending all of the chars.

I'm using CVI serial port functions OpenComConfig, ComWrt and ComRd. I have a separate thread that reads input from the port (ComRd) and displays it in a text box. The main thread accepts text input from the user and sends it (ComWrt) out the serial port. What I'm seeing at the other side of the rs232 serial link is that about 50% of the time not all of the characters I send are showing up. On the other hand, I don't seem to see any characters dropped on the input side. The CVI help files indicate that different threads can access the same port, and since one thread is only reading and the other is only writing, I would think this should work. Any help would be greatly appreciated.
0 Kudos
Message 1 of 5
(3,839 Views)
Hello,

It is possible that you are only reading up to a termination character in the read buffer, which would make it appear as though you are only receiving half the data. What termination character have you set (if you are using termination at all)? It sounds like you may be performing a loopback test; if not, to verify things are working correctly, simply open, write, read, and then close a given serial port, where you have connected pins 2 and 3 of the serial cable connected to the serial port. This way you should read back exactly what you wrote. Try reading precisely the number of bytes your write, and don't include termination characters in the write string; you should get all the data. Now try writing once, with some text separated by a termination character (with termination enabled) and you should be able to perform multiple reads, where the data remaining each time will be all that came after a given terminataion character, but it is not lost until you empty the buffer or close the serial resource.

It seems like you may be having this subtle termination and read issue; feel free to get back to me if you have further questions. Also, you seem to be using a serial specific API and not NI-VISA; can you attempt to use NI-VISA?

I look forward to your repost!

Best Regards,

JLS
Best,
JLS
Sixclear
0 Kudos
Message 2 of 5
(3,823 Views)
Hi!
I've got the same kind of problem as you do, Geco.
I use two serial links and have some scheduling between the two links. One thread is dedicated for each link.
In some case, I receive two consecutive messages for one link. The timing between these two messages is very short (from the distant side, it could be considered as two consecutive ComWrite).

After having read the buffer, I called for a PostDefferedCallToThread so I would suppose that the scheduling is then assumed. But it seems that when two messages are very close, I can't read all of them each time (sometimes it works, sometimes not).
Any idea to solve my problem?

I just use LabWindows / CVI with the rs232 include

Thanks
0 Kudos
Message 3 of 5
(3,723 Views)
I have expereinced something similar to this I thought I would post here.
I looped my serial port and when I send something I always get back but sometime I get 2 times. Upon further investigation what I found is if I use USB to serial convertor it happens but If I use native serial port it works fine. Means no problem in my code. Those USB to serial does not work well. It sometimes crash my computer. (Complete restart after blue screen)

Sheetal
Thanks.
CVI 2010
LabVIEW 2011 SP1
Vision Builder AI 2011 SP1
0 Kudos
Message 4 of 5
(3,716 Views)
Good remark Sheetal! I do use USB/RS232 interface.
I solved my problem by dealing with timeouts...

Thanks anyway
0 Kudos
Message 5 of 5
(3,708 Views)