05-07-2010 12:34 PM
05-07-2010 01:26 PM
Luis,
from your last post I cannot see if your question/problem is solved.
If so please label a message as solution (not this one).
If the problem is not solved, please post your code.
Ton
05-10-2010 07:55 AM
Luis,
Without a wait the serial read loop may iterate faster than data appears at the port. Make the wait slightly longer than the time it takes to transmit one byte. Wait ~= 1/(10*baud).
As Ton requested, please post your code.
Lynn
05-10-2010 10:04 AM - edited 05-10-2010 10:05 AM
Hi Lynn, Hi Ton
so far im trying now only to guarantee a proper reading, the code im using is next, i have to question. first one is how i calculate the bytes per second or milisecond that serial can read at 9600 baud rate, second one, does the Read block use a buffer? since sometimes i stop de vi, when i start it again i see more data than should be, like previous data storage.
Edit: the time wait used is 200miliseconds so far read well but not always sometimes looses half string
the code is the next
05-10-2010 10:33 AM
Luis,
Baud = bits per second. With the settings you are using, 8 data bits, one start bit, no parity, one stop bit, each character requires 10 bits. So 1 byte of data requires 10 bits transmitted at 9600 bits/second. Thus 9600/10 = 960 is the maximum number of bytes which can be sent in one second. One bytes takes about 1 millisecond. Your 28-byte message will take at least 28/960 = 29.2 ms. You will notice that I used words like "maximum" and "at least." While most systems transmit successive bytes without delay, an asychronous system is not required to do so.
Your program will stop after any (non-zero) number of bytes is received. The delay will probably run after the read. So if one byte is present when the loop starts running, it will read that and wait 200 ms then stop. Do you want to wait until 28 bytes are present before reading? What if some bytes are left from the previous message when you start?
I modified your program slightly. It now only reads if some bytes are actually present. If you change the numbers in the selector label, you can change the number of bytes which must be present for a read to occur.
Lynn
05-10-2010 11:11 AM - edited 05-10-2010 11:17 AM
Lynn,
since the data string wont be always 28bytes long i cant wait till it read 28bytes, the string usually change 16-28bytes, but yes i need whole string be present before reading it, thats my main issue, i cant do a partial read, when i set the label in 16,20,24,28 and some data arrive with 28bytes it will set first to 16 or i can make my "16" label be the last to check?
edit: the label selector should be like 28.. 24.. 20.. 16.. ?
05-10-2010 12:11 PM
Luis,
That is not the best way to make this work. Look at the VI I posted last week. In that I build a string in a shift register. You can read any number of bytes and build the string with them.
In the analysis VI you search for the "7E" byte. Then you examine length bytes and use the String Subset function to get the 16-28 bytes as appropriate for that message. You will often have some characters left over. Those are saved as the first part of the next message.
Lynn
05-10-2010 04:06 PM
Lynn,
i manage to build a simple shift register, i have notice that for some weird reason the inside loop is taking around 12-15seconds to complete a cycle. so i guess is necesary to just build a buffer inside the loop and use a new parallel loop to break it? am i right? or the reason of the delay is another?
05-11-2010 12:55 AM
You finish the inner while loop only if there is no 7E inside your buffer.
And you start checking at the second character (offset 1 byte), any reason why?
Here's a snippet that shows how to get a full message:
Ton
05-11-2010 04:35 PM
Hi Ton,
Since i need to read a complete string always, 7E is the only constant data and it will always mark when a new string begins so i check second byte so i recover first string and cut it from buffer that way i will read all strings at buffer but the last will not be readed.