01-23-2016 05:01 PM - edited 01-23-2016 05:05 PM
Hi all,
I am using Labview to receive data from a serial port in RS232 protocal.
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?
01-23-2016 05:22 PM
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.
01-23-2016 05:30 PM
@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).
01-23-2016 05:47 PM
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
01-23-2016 05:58 PM
01-23-2016 06:10 PM
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.)
01-23-2016 06:21 PM
@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?
01-23-2016 06:24 PM
@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.
01-23-2016 06:29 PM
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.
01-23-2016 06:37 PM