LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

bytes to read function? is it slow?

well, i try the way u told me, only for reading data from serial port com1, and i have check that still using a while loop still get error using  byte at serial port function, when i use a fixed constant it doesnt appear. besides i have to use some delay or timetowait so the reading is succesfull
0 Kudos
Message 11 of 24
(1,960 Views)

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

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 12 of 24
(1,950 Views)

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 

0 Kudos
Message 13 of 24
(1,921 Views)

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 


Mensaje editado por Luis Bertel
0 Kudos
Message 14 of 24
(1,910 Views)

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 

Message 15 of 24
(1,901 Views)

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.. ? 

Mensaje editado por Luis Bertel
0 Kudos
Message 16 of 24
(1,895 Views)

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 

0 Kudos
Message 17 of 24
(1,872 Views)

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?

 

 

Download All
0 Kudos
Message 18 of 24
(1,855 Views)

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:

GetMessage.png

 

Ton

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 19 of 24
(1,828 Views)

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.

0 Kudos
Message 20 of 24
(1,817 Views)