LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

read byte by byte

Hi. I'm using the module "bytes at serial port" to read the answers of my robot, but i do not want to read all bytes at the same time. I want to read byte by byte. How can i do it?

Thanks.

Ivan.
0 Kudos
Message 1 of 11
(3,858 Views)

Put your VISA Read inside a for loop and specify 1 byte to read. Wire the output of VISA Bytes at Serial Port to the count terminal of the for loop.

Message Edited by Dennis Knutson on 06-08-2006 10:18 AM

0 Kudos
Message 2 of 11
(3,851 Views)
Hi Dennis. Perhaps it was a solution, but i'm making a verification with read bytes. I'm verificating if some byte is like '>', like the picture.

How can i do it?

Thanks for all.
0 Kudos
Message 3 of 11
(3,841 Views)
It seems that what you are doing now is terminating the read when the ">" is detected. If you want to stop reading as soon as the character is found as opposed to maybe reading in some characters after the ">", then replace my for loop with a while loop. Terminate the while loop if the character is found or if the iteration count is greater than/equal to the byte count. If there's the possibility that there are extra characters in the serial buffer, you will want to flush the buffer before you do another read.
0 Kudos
Message 4 of 11
(3,834 Views)
I'm a bit curious... Is there a special reason why you want to read the port byte-by-byte? 
0 Kudos
Message 5 of 11
(3,828 Views)

or enable and use the '>'  (x3E) as the termination character

 

Greetings from Germany
Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'


0 Kudos
Message 6 of 11
(3,805 Views)
Yes. Because if i read all bytes at the same time, does not work correctly. if i send, for example, "open", i have to read Done>. The first instruction works, but if i send other instruction from a file, for example "open", "close", i have an infinite loop, because i do not read ">", Do you understand?

Thanks for all.
0 Kudos
Message 7 of 11
(3,805 Views)

So it seems as if ">" is the character that signals the termination of a command.  Use this as your termination character, and initialize the serial port that way.  See picture of how to do this (">" is ASCII 62 in decimal).  When reading, the ">" character will signal the termination and the reading will stop.  Other characters afterwards will remain in the buffer until the next read.

You should fix your code to prevent infinite loops in case the termination character is not received.  What happens if the character is never sent due to some glitch in the sending system, or if some glitch causes a different character to be received instead of ">", or if the comm link breaks before ">" is received?  Your program will get stuck.  You need to fix this by putting a timeout or something that will abort or end the code in case something goes wrong.

 

Message Edited by tbob on 06-12-2006 10:25 AM

- tbob

Inventor of the WORM Global
Message 8 of 11
(3,786 Views)

Thanks pti-bob!  🙂

I could not have said it better myself.  Glad to see you back & contributing.  Does this mean that the health has improved?

JLV

Message 9 of 11
(3,777 Views)
Merci, mon cousin.  I'm about 90% recovered and back at work full time.  It was a nice break while it lasted but I wouldn't want to go through that again.
- tbob

Inventor of the WORM Global
Message 10 of 11
(3,775 Views)