LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial port Write then Read issue

Greetings all:

In LV 7.0 I have a serial port Write/Read problem.I am attempting to
communicate with a fairly "dumb" instrument of custom design. In
testing my LV program (with nothing connected to the serial port), I
try to write a string "blah blah blah". No problem, far as I can tell.
Then I attempt a read, which in my mind should give me an error since
nothing is connected to the serial port. However, I get the original
message "blah blah blah"! I was under the impression based on the
documentation that the receive and transmit buffers in the serial port
were separate, and never the twain shall meet. Yet, I appear to be
reading the write buffer! WTF?

Using the VISA Clear function between the write and read operation
appears to give
me what I want, since nothing is returned and the VISA
read operation times out. However, in my application this means data
could be lost if data is cleared while the "dumb" instrument is trying
to write to the serial port. A colleague suggested offsetting the read
operation by the write string length to weed out the write string, but
this seems like the long way home. Also, the issue remains: aren't the
serial port's transmit and receive buffers separate? What to do?

Another issue: the VISA Flush operation mode masks list two modes, 16
and 64 that appear to do the same thing, flush and discard the receive
buffer. Trying to do both thru an OR function yields an error that
flags it as an invalid mask. Also, none of the mask combinations seem
to really get rid of any data. ????

Art
0 Kudos
Message 1 of 7
(3,894 Views)
The serial port transmit and receive buffers are separate. They are not tied together. If you have nothing connected to the serial port and you write something to the port, you will not receive anything. You obviously have a loopback somewhere in your system. I am using LV7 and I have written a program to communicate with a device through the serial port. When I unplug the serial cable, write something, I receive nothing. Your problem lies within your system.
The way I do it is to write the serial data, then call the Bytes at Serial Port function in a while loop. The loop contains a timer. The loop exits when either Bytes at Serial Port returns a positive number or the loop iteration count reaches a certain value. If the Bytes at Serial Port number is pos
itive, I call the Serial Read function. If no bytes, I display a message or set a flag that nothing was received.
- tbob

Inventor of the WORM Global
0 Kudos
Message 2 of 7
(3,894 Views)
Afaik, the two buffers are separate and I've never seen the problem you describe. Do you get the same thing when you run one of the shipping examples? There's one called LabVIEW <-> Serial.vi that you could try. If you don't get anything in the serial read of the example, could you post your VI so someone could look at it?
0 Kudos
Message 3 of 7
(3,894 Views)
Question: did you check your serial port setup to make sure that local echo was turned off? I see this kind of thing in my machine when I have local echo turned on. It could be turned on in the LabVIEW serial port setup or in the Windoze setup.

Rob
0 Kudos
Message 4 of 7
(3,894 Views)
Robert Cole wrote in message news:<506500000005000000F2730100-1079395200000@exchange.ni.com>...
> Question: did you check your serial port setup to make sure that local
> echo was turned off? I see this kind of thing in my machine when I
> have local echo turned on. It could be turned on in the LabVIEW serial
> port setup or in the Windoze setup.
>
> Rob
Hi! Rob,
How do you turn off the local echo? My program seem to have the same
issue of reading back whatever string was send on the serial
port...and bytes to read does not return the correct number of bytes
to be read. With hyperterminal it works fine and even with MAX.
I am using LV7.0 and Serial compatibility VIs.
TIA
0 Kudos
Message 5 of 7
(3,894 Views)
It is device dependent. It may be turned off but may not. Some devices will return the user input as part of the output, for example, cell phones. If it can be turned off, the manual should tell you. If not, most likely it won't be mentioned. Of couse, you can always deal with it in your software (strip off the typed commands).

-Joe
0 Kudos
Message 6 of 7
(3,894 Views)
Depending on the driver in use - there may be a setting in the hardware settings/device manager in Windoze control panel. My system allows me to turn on local echo through the driver in the device manager. Annoying since my program does that function automatically.

Rob
0 Kudos
Message 7 of 7
(3,894 Views)