LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

the serial communciation receives wrong data

Hi all,

  I am using Labview to receive data from a serial port in RS232 protocal.

 

Untitled.png

 

The source of data is generated by external circuit board which is running at BAUP 9600. The board will send out a text  contains 30 to 70 characters at every 1 second. The above labview code is working perfectly.

 

But if I let the circuit board generate the same data but in the interval of 10 seconds or longer, the labview code works for a while but after it always receive somehting weird, the indicator shows blank string. I am thinking if it is because the code try to read out something but the source is not yet ready to produce any?

 

Also, since the text sent out is of different length, so how do we know in advance what's the correct "read count" should be? 

 

I also wonder what will Labview do when the source is not ready to send the next data, will it just try and wait for next commuication so will ready anything from buffer no matter if it is empty or not? Is it anyway we force labview to pause and wait until the data is ready to read?

 

0 Kudos
Message 1 of 11
(4,770 Views)

First, get rid of the shift register on the error wire.

 

If there is no data to send, then the VISA read will timeout.  If you don't get 100 characters or a linefeed as the termination character (the default settings for serial configure), the you get a timeout.  When you get a timeout, that error will go into the shift register, and the VISA read will never execute again.

 

As to how much you should read, that depends on the data the device is sending.  What is this device?  How do they have it programmed?  Does it send a termination character?  We can't answer those questions because we have no clue as to what you are communicating with.  Only you can answer those questions.

0 Kudos
Message 2 of 11
(4,750 Views)

@RavensFan wrote:

First, get rid of the shift register on the error wire.

 

If there is no data to send, then the VISA read will timeout.  If you don't get 100 characters or a linefeed as the termination character (the default settings for serial configure), the you get a timeout.  When you get a timeout, that error will go into the shift register, and the VISA read will never execute again.

 

As to how much you should read, that depends on the data the device is sending.  What is this device?  How do they have it programmed?  Does it send a termination character?  We can't answer those questions because we have no clue as to what you are communicating with.  Only you can answer those questions.


Thanks, it works by removing the shift register. I don't know much on the device. But the engineer said it use STM32 to send the data. The format of the data is string ended with "carriage return" (\n).

0 Kudos
Message 3 of 11
(4,740 Views)

try to use byte at port to monitor number of data for each loop also use wait with appropriate time to control data flow or if you know more about the termination character you can use case structure to read data from your hardware after any termination character that you receive from your hardware

0 Kudos
Message 4 of 11
(4,721 Views)
Do NOT use the Bytes at Serial Port, a wait, or a case statement when there is a termination character. That is just bad advice. With a termination character, you just need a read with a high byte count specified. You might need a write to tell the instrument to send something.

The stm32 is a micro, I hope you know. That says nothing about the serial protocol that was written for it.
0 Kudos
Message 5 of 11
(4,711 Views)

A carriage return is "\r".  A linefeed character is "\n".  If it is linefeed, you are fine right now.  If it actually is a carriage return, wire a 13 into the termination character input of the VISA configure (13 decimal or 0A hex.)

0 Kudos
Message 6 of 11
(4,698 Views)

@RavensFan wrote:

A carriage return is "\r".  A linefeed character is "\n".  If it is linefeed, you are fine right now.  If it actually is a carriage return, wire a 13 into the termination character input of the VISA configure (13 decimal or 0A hex.)


Oh, yes, my bad. It is linefeed. So do you mean if it is  linefeed, we don't have to worry about the actual number of bytes being read?

0 Kudos
Message 7 of 11
(4,685 Views)

@Dennis_Knutson wrote:
Do NOT use the Bytes at Serial Port, a wait, or a case statement when there is a termination character. That is just bad advice. With a termination character, you just need a read with a high byte count specified. You might need a write to tell the instrument to send something.

The stm32 is a micro, I hope you know. That says nothing about the serial protocol that was written for it.

Thanks for the reply. I just ask him again, he said the chip is stm32, and the board supported mbed, and he gave me a link for more information. https://developer.mbed.org/handbook/Serial, I am not sure if that tell the protocal or not. I will figure it out later.

0 Kudos
Message 8 of 11
(4,677 Views)

By default, the VISA config is set to use the termination character and it is by default line feed.  So just read a large enough number of bytes and it will return the response as soon as it gets the linefeed character.

 

Anything about STM32 and embed is just noise and has absolutely nothing to do with serial communication.

0 Kudos
Message 9 of 11
(4,662 Views)
You can't wait until later. You need to know the baud rate, parity, hand shaking, stop bits, etc. You need to know the format of the data being sent (hex, ascii). You need to know whether to use a null-modem or straight through cable. Doors the micro continuously send data or does it require a query.

You would be just spinning your wheels until you get this basic information. If the engineer can't provide it, he's incapable of doing his job.
0 Kudos
Message 10 of 11
(4,653 Views)