LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

RS232 and how to increase bit read size

Hello,
My program is reading values through the com port. The only problem is that it will only read 1 bit at a time and I need to read up to 6 bits, for example 1.2345. I will use this value in a calculation with another rs232 read. I am currently using numeric box's to read the data into. I looked at the NI rs232 example and I see that it is using a textbox to read the data into, and a numeric to control the number of bytes to read. Is this what I will have to create for my numeric boxes?  Should I use text boxes instead of numeric boxes? Is there an easier way to set the default bits higher?
 
The config panel In use defaults to 8 data bits, similarly to the NI example.
 
Thanks
0 Kudos
Message 1 of 4
(3,405 Views)

The RS232 library function ComRd() takes a "count" value.  This determines how many bytes you will try and read into your buffer.  Each character in your 1.2345 example is 1 byte long.  Note that if you input only the 6 characters of your example the buffer will not be null terminated.

The number of  bits per byte is set by the config panel you describe, it determines how many bits are used by the serial UART for a character,  8 bits is by far the most common value these days but would depend on the type of serial hardware you are trying to communicate with.

Message Edited by mvr on 01-08-2007 11:17 AM

0 Kudos
Message 2 of 4
(3,402 Views)
RS-232 communication on a PC Com port is done one byte (7 or 8 bits) at a time.  Typically (as in the NI sample program), numbers will be transmitted as ASCII strings, byte by byte.  You can use the ANSI C sscanf function to read the numeric string into a number.  You would need to know where each number starts and stops, typically defined with delimiters, end of line characters, etc.
 
Numbers may be transmitted in binary, but it's still 8 bits at a time.  For a floating point number, you would need to select a format to represent the number, e.g. IEEE Floating Point, and then define the byte order within that representation.
 
The 8 bit byte is a limitation of the Com port UART hardware, not of CVI.
0 Kudos
Message 3 of 4
(3,394 Views)

Ok that helps. Got it working.

 

Thanks

 

0 Kudos
Message 4 of 4
(3,384 Views)