LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

RS232 in LabVIEW

Hey folks,

 

I have a motor controller which I want to control with a RS232 using LabVIEW. I have the hardware all setup, but I want to know how to be able to use the LabVIEW program to transmit my program data to the RX port of my RS232 as well as receiving the data from the TX port of my RS232.Can anybody help me out with this?

 

Regards,

 

butterwaffle

0 Kudos
Message 1 of 19
(4,037 Views)

Search the forums for either "RS-232" or "Serial".  There are thousands of messages where people had questions regarding the same topic.

 

Search the example finder for "serial".  There are two examples such as Basic Serial Read and Write, and Advanced Serial Read and Write to get you started.  They aren't the best examples.

 

I feel their use of the "Bytes at Port" property node is the wrong thing to use about 95% of the time.

 

You need to know whether your serial communication is based on sending ASCII strings of human readable characters, or uses a binary format where any of the 256 values from 0 to 255 could be used.  Using ASCII human-readable characters is usually easier for a new programmer because it is easier to see and compose the data.  Also, know what a termination character is, which is usually a byte such as a carriage return or line feed that will end the commands you send to the device, or end the responses you get from the device.

0 Kudos
Message 2 of 19
(4,023 Views)

Last night I was controlling my motor using an executable file from the company using RS232 and sending out commandsof hexadecimal format in 9-byte addresses.

 

Now I want to be able to try and use a numeric control(using a slider or dial or something) in order to control where I want my motor to be positioned. I have looked at the examples, but I'm fairly new to LabVIEWsoIamquite confused.

 

For this I was thinkingabout having 2 VISAConfigure Serial Ports, one VISA write(which will go to the RX port of RS232), and one VISA read(which goes to the TX port of RS232). I was wondering how can Iconnect my VISA write/read to the RX port and TX port of my external RS232?

 

Also for the write buffer I noticed it only takes a string. I am trying to use a slider and convert it into a string in order to write my data to the VISA write.

0 Kudos
Message 3 of 19
(4,016 Views)

You should only have 1 VISA Configure Serial Port.  You RX and TX are both controlled with a single serial port.  So you only need to control the one port.

 

As far as what you should write out of the port, you need to be a little more specific on the exact details of the protocol the motor wants.  What bytes mean what?  Is there a checksum?  Is there a sync byte?


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 19
(4,002 Views)

Generally the RS-232 port handles both directions - TX and RX - in one port. So you only need one Configure VI. If for some reason the settings are dfifferent for read and write you would need two ports.

 

When you say "external RS-232" do you mean RS-232 to USB adaptor? Or does the device connect to your computer by some other means? Most adaptors come with USB drivers which make them appear to be virtual serial ports to the OS. That driver needs to be installed.  Some types are more friendly to LabVIEW than others. What is the manufacturer and model of the device?

 

As for the string, you need to know exactly how the commands are formatted. That information should be in the manual of the controller. Which of the 9 bytes are related to the position and which are command identifiers, framing bytes, and so on?  How is the decimal value from the slider mapped into hexadecimal for the controller?

 

Lynn

0 Kudos
Message 5 of 19
(3,996 Views)

So since my RXand TX are controlled with a single serial port, I just follow the example programs from the example slides, and my data should be transferred correctly provided my hardware connection is correct?

 

So my motor takes in a 9byte frame. Where the first byte is the address of the motor controller, and the second is the command I wish to execute, the 3rd is my motor number. The rest are variable positions based on the command. I was wondering what would be the easiest way of going through this? I am more confortable with a writing programming language such as C, so I was wondering if there was a way that I could make a for loop and iterate through the entire frame?

0 Kudos
Message 6 of 19
(3,993 Views)

Yes I have a USB to RS232 adapter, which is connected to a couple of terminal blocks which then connects to my motor controller. Here is my device:

http://www.trinamic.com/products/discontinued-products/sixpack-2

 

I was wondering if it's possible to use a for loop with a series of if-statements in LabVIEW in order to iterate through the entire frame. Sort of like this in a written programming language

 

for(i=0; i<9; i++){

   if(i==0){

      read address

   }

   if(i==1){

      read command number

   }

   ....

}

0 Kudos
Message 7 of 19
(3,989 Views)

You could use 9 comparisons but autoindexing would be much more efficient. Convert the string to an array of U8 using the String to Byte Array primitive, then wire the array to the for loop.

 

Lynn

 

Read and Parse.png

0 Kudos
Message 8 of 19
(3,968 Views)

From here the output of the for loop should then be convereted to a string to be written to the TX?

0 Kudos
Message 9 of 19
(3,959 Views)

Your write commands will probably be built somewhat differently. The address and command bytes will be fixed and known in advance.  I did not try to interpret that entire manual, which is not too well written, to determine what command you need. How many bytes of the 7 parameter bytes does your slider generate? Are the rest zeros?

 

You can probably use one of the number to string conversion functions and Concatenate Strings to generate the write commands.

 

Lynn

0 Kudos
Message 10 of 19
(3,955 Views)