LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Labview serial communication with RS 232

Solved!
Go to solution

Scan from string takes data that looks like a number and converts it to a number.  If you have binary data, which seems to be the case since the string shows data this is not readable to humans, Scan from String is the wrong function.  You might need to use typecast.

 

But you need to figure out what is the format of the data being sent in order to know how to convert it to a number.

 

As for your error 1 jpeg, the error is probably coming from the property node where you set the RS-485 wire mode.  For some reason your control doesn't show all the options that you could get if you right clicked on that property node and created a constant.  That isn't the reason for the error.  Are you using an RS-485 port?  Is it a device created by NI?  According to the help for that property node, it is only for an NI developed RS-485 driver.  I'm betting you are using something else and that is why that property node is not supported and raises an error.

0 Kudos
Message 11 of 56
(3,456 Views)

Thanks for the reply RAVENS FANS.

 

Indeed the data input to the communication port is in binary form.  By format what are you implying, please?  Also can you please guide me through the process of typecast because i am not very familiar with this.  I am infact using the example avaible from the labview examples for serial communication.  However, data is being processed on a microcontroller (PIC) and then transferred along a RS 232 cable.  The RS 232 cable is coupled with a serial to USB converter.  Labview is reading the USB port set as communication port in MAX.

 

I am also attaching a serial read file which i wrote.  Would you please go through it and check for possible problems?  Also, i have no driver for communicating with the USB converter.  All i have is LABVIEW 7.1.

 

It would be very grateful if you could spare your precious time helping me.

 

Thanks.

 

Kind regards

 

Kunal

0 Kudos
Message 12 of 56
(3,436 Views)

What is the format of the data?  Does one byte represent a piece of data?  Two bytes?  4?  8?  For example, if it is two bytes, is it a U16 format or an I16 (signed vs. unsigned 16 bit integer).  Is the most signifcant byte (MSB) first (big endian) or last (little endian).  Are the bytes combined to represent an integer or a floating point value.

 

Type cast takes the data coming in and converts it to another datatype based on the type of data wired into the top.  So if you send in a string and it consists of 2 bytes, and you have a U16 constant wired into the top of the typecast, then those two bytes get reinterpreted as a U16.  Wire in an I16 constant, the bytes are reinterpreted as a signed 16-bit integer.

 

Driver for your USB device?  A lot of USB devices have drivers that cause them to show up as a com port in Windows device manager.  A USB to RS-232 converter certainly does this.  I doubt you need to worry about the driver.  Just see how the device shows up in Windows Device manager.

 

As for your VI, it doesn't look different than what you had before.  You need to get rid of the scan from string and replace with a typecast function.

Message 13 of 56
(3,430 Views)

Thanks again for your advices RAVENS FAN.

 

The data format is Non Return to Zero with 8 bits.  The data bytes are meant to represent an integer.  Regarding the device, it is being displayed as a communication port. 

 

However will you please guide on where to find the typecast function? I have the RS 232 to USB converter and I am using the same to do the communication.

 

What if I16 and U16?  Can you please clarify on this? 

 

Kind regards

 

Kunal

0 Kudos
Message 14 of 56
(3,418 Views)

Typecast is under Numeric > Data Manipulation palette.  Or you could use the search function on the palette.

 

I have no idea what "Non return to zero" means.

 

If it is a single byte, then the data is either the value of 0 to 255 (U8) or -128 to 127 (I8).  Wire a U8 constant (or I8) into the top of the typecast function and it will turn the string character into a numeric value.

 

I16 is a signed integer of 16 bits, or 2 bytes.  U16 is an unsigned integer of 16 bits (or 2 bytes).

 

If you are not familiar with how data is represented in a PC, then I suggest doing some more research.  http://en.wikipedia.org/wiki/Unsigned_integer

0 Kudos
Message 15 of 56
(3,402 Views)

Thanks for the informations RAVENS FAN. 

 

I have found the type cast and i am still working on it. 

 

Non Return to Zero is a line coding technique for coding digital data.  You can get more information at the following link:

http://en.wikipedia.org/wiki/Line_code

 

I will update you with the progress on the program.

 

Kind regards

 

Kunal

0 Kudos
Message 16 of 56
(3,384 Views)

Hi RAVENS FAN

 

Firstly thanks everyone who gave me their views for my problem since your advices led me through the solution.

 

I implemented  your solution using the typecast.  The program is now reading the com port and displaying the value obtained as hexadecimal.  However i am at a loss since i am unable to know how to :

 

1) to make the data be converted into decimal form from the typecast function.  I tried using hexadecimal to decimal function but when i tried wiring these up, it showed me broken wires

 

2) generate a graph or table from the information i am actually reading.

 

It would be very grateful if you folks can help. 

 

Kind regards

 

 

Kunal

0 Kudos
Message 17 of 56
(3,340 Views)

You'll need to attach your latest VI so I can figure out what you are or aren't doing now.

0 Kudos
Message 18 of 56
(3,335 Views)

Here is the VI that i am currently working on with required modifications to do the read buffer.  From the buffer i want to display decimal values on a graph.  However i am unable to figure the way to do this. 

 

It would very grateful if you could please help.

 

Kind regards

 

Kunal

0 Kudos
Message 19 of 56
(3,332 Views)

You didn't use typecast correctly.  I said to wire a U8 numeric constant into the top.  You wired a string control.  So you managed to typecast a string into a string, which means you didn't really do anything.

 

You also need to get the serial configure and VISA close out of the loop like you had earlier.  There is no need to reconfigure the port and close it on every loop iteration.

 

Since you are dealing with binary data, any byte can come through and be valid data.  So you need to disable the termination character on the serial port configure.

 

I have two variations in the fixed VI.  One converts the string to a single byte.  The second assumes multiple bytes have come in and will convert them to an array of U8 to be passed into a waveform chart.

 

0 Kudos
Message 20 of 56
(3,328 Views)