From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to make program for RS-232

Solved!
Go to solution

The MODBUS library makes this a lot easier. It builds theses messages for you, and computes the CRC value automatically.

 

Thought I should mention it.:smileyhappy:

---

Peter Flores
Applications Engineer
0 Kudos
Message 21 of 37
(1,904 Views)

DevinChen wrote:

Thanks for your response Ravens. I have looked over the vis for the MB library, but i was suggested that the pre-made "advanced serial write and read vi." should do the trick.  I tried the vi as it is with the corresponding setting for my device, but there appears an error of "timeout expires".  Does anyone know how I can get the right timeout and rather this method really works? 


Things to check:

1.  You have selected the correct Com port. 

2.  You are using the right kind of cable.  Null modem vs. a straight through.

3.  You have the baud rate, parity, and stop bits set correctly.

4.  You have the slave address set correctly.

5.  You are using the correct command for the type of register you are reading.

6.  You are trying to read a valid address.  Note that if an address is 40003, you drop the 4.  And generally you will use 2 because LV addresses are 0 based while the addresses in the device begin at 1.

7.  You are reading the correct number of address registers.    (i.e you are not starting at 2 and trying to read 10 addresses when only 5 addresses exist overall.)

8.  You using the correct implementation of Modbus.  RTU seems to me to be the most common, but some devices use ASCII.

 .......

 

Check your device's communication manual.  Often times they will give a couple of examples as to how a typical modbus command and response will look.

Message 22 of 37
(1,895 Views)

Thanks everyone and sorry that I was away from my project for awhile.  Anyways, I took all your suggestions in mind and made the following vi, but I'm still getting a timeout error. 

According to the communications guide:

 

  Reading the temperature


An 8 byte message must be transmitted to the Controller as follows:
byte 0 : Slave address xx
byte 1 : Read Register Function code 03 hex
byte 2 : High Byte of Register address 00 hex
byte 3 : Low byte of Register address 1C hex
byte 4 : Number of Registers to read (high byte) 00 hex
byte 5 : Number of Registers to read (low byte) 01 hex
byte 6 : CRC lo byte xx
byte 7 : CRC hi byte xx

 

It seems that I'm receiving signal from my device as I tried highlighting.  I really appreciate it if someone can help me.  

Thanks,

 

0 Kudos
Message 23 of 37
(1,832 Views)

DevinChen wrote:

 

It seems that I'm receiving signal from my device as I tried highlighting.  I really appreciate it if someone can help me.  


How do you know you are receiving a signal from the device?  What is the data that you are receiving?  What is highlighting showing.  If you are receiving something, you shouldn't be getting a timeout error.

 

Check your Register address.  Your Low Byte according your description is 1C (28), but your control shows 1B (27).  Byte 1C would be address 40029, Byte 1B would be address 40028.

Message Edited by Ravens Fan on 03-28-2009 08:50 PM
0 Kudos
Message 24 of 37
(1,830 Views)

Thanks for your reply, Ravens Fan. Sorry, the device is not receiving any bytes from the port.  I used address 1B(27) by subtracting 1 from the address in the communications guide since Labview starts address with 0 instead of 1, right?  In any case, I tried both 1B and 1C, but still no response.  The baud rate is 9600.  Do you see any problem with my vi?  Thanks again and please excuse my inexperience.

0 Kudos
Message 25 of 37
(1,795 Views)

Just checking on the address.  It was good that you tried a couple other registers around it.

 

I just picked up on something.  In your MB Serial Init.VI, you don't have anything wired to the parity input.  It looks like it would default to None.  What is the parity setting that your device is expecting?

 

Otherwise, I just am not seeing anything else that could be wrong.

0 Kudos
Message 26 of 37
(1,783 Views)
Thanks for your quick repsonse Ravens Fan.  The device uses a CRC-16 calculation that should already be embedded in the master query, and the communications guide does not specify the need of parity check; I tried all the options on parity with combinations of 1B and 1C address (and 1D as well, just for fun), but still got no response.  Do you have any more suggestions?  I read on your previous post that noise could be a problem, but do you have a way around that as I need to conduct my instrument in lab and hence, noisy enviornment is inevitable.
0 Kudos
Message 27 of 37
(1,762 Views)

Not parity check.  Parity Bit.  It should be listed with the serial specifications of baud rate, data bits, and stop bits.  It could be 8, none, 1.  But it could also be 8, Even, 1.  If the device is expecting a parity bit, but not getting it, it might think it is receiving a corrupted message and not sending any kind of reply in return.

 

For noise, it is unlikely, but an oscilloscope on the communication lines should show whether you are getting a clean signal or something with noisy spikes.

 

Does the device come with any software of its own such as a sample program?  If so, try that to use that.  If that doesn't work, then you know the problem is in the cabling or serial port setup.  If it works, then you have confirmed the cabling and serial settings and just need to make sure LabVIEW is using the same.

 

Does the device have any means of configuring it from its front panel?  Double check the baud rate and other serial settings from there.  There might be a setting you have to make to tell it to use ModBUS rather than some other communication scheme.  What is the device you are using including make and model number?  Does it have a users guide or communications manual online that you can post a link to?

 

Are you sure it is using RS-232 and not RS-485?

Message 28 of 37
(1,749 Views)
Thanks Ravens Fan, I will attach the communications guide and manual below; the device is the Omega Engineering CN9600 series temperature controller.  The default setting for the device is: address-0, baud-9600, parity-18n1(none and stop bit 1), and I confirmed with the omega engineer when I started this project that the device does communicate via RS-232.  I  tried changing the default setting and ran the program using those settings, but was no use.  I don't think there're other settings, but please help me check; I'll try to find the software.  Really appreciate your help.
Download All
0 Kudos
Message 29 of 37
(1,742 Views)

Try changing your slave address to 1 instead of the 0 that is the default value according to the controller manual.  (You said you changed from default values, but I'm not sure whether you changed the slave address.)

 

Your VI is set for slave address 1 as it is.

 

Omega should never have made the default address 0 as that address is reserved for broadcast messages.  That means all devices (which would happen if you had several devices on a single RS-485 line) would listen to a message sent to slave address 0,  but not respond to the message.  You can see in the MB WR VI that if the slave address is 0, it doesn't do a MB Read, but if it is any other slave address, then it will do a Modbus read.

 

I've used Omega controllers before, but I used their ASCII protocol and not the Modbus protocol.  I know that to use the modbus protocol, I would have to enter the front panel and set a serial setting to tell it to use Modbus.  I don't see that setting in the manual for this particular controller.  It seems to use Modbus only.

 

Are you using their cable to connect to your PC or your own?  I can't determine from their manual whether they expect the cable to be null modem or straight through.

Message 30 of 37
(1,730 Views)