LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Communication between Controller and Labview through RS-232

Hi there,

 

I am trying to communicate with my controller through an RS-232. I am currently using Labview 2016 and would like some advice on how to go about doing it. This is what I have as of now and I hope someone can let me know if I am on the right track.

 

In my program, I need to extract some information from the holding register of the controller (40001 to 40009) and generate a report from the extracted data, but I am not sure how to let the controller know that I would like to access that register.

Appreciate it. 

0 Kudos
Message 1 of 17
(3,331 Views)

If you want to read a holding register, then make sure you set the polymorphic VI to be Read Holding Registers.  Your screen shot shows Read Input Register.

 

For 40001 to 40009,  you drop the 4 from the front and subtract 1, so you are looking for starting at 0 and going for 8 registers.  So wire 0 for starting address and quantity 8.  You will get an array of 8 U16 elements, one for each register.  Just index array to get the register you want.

 

Get rid of that VISA Read.  That will just complicate things.  The modbus subVI's already do the VISA reads and decoding the modbus protocol.

0 Kudos
Message 2 of 17
(3,312 Views)

Thanks for the prompt reply, mate.

 

However, after modifying the code. I am currently facing with timeout errors. 

 

Attached is the current code.

 

Looking forward to your replies 🙂

0 Kudos
Message 3 of 17
(3,287 Views)

Hi Raven, 

 

One more thing, because I am connecting it to my laptop. I am unsure if the same code can work because I am converting the RS-232 to a USB port before plugging into my laptop. Can you advise?

 

Appreciate it !

0 Kudos
Message 4 of 17
(3,284 Views)

@Jarrold wrote:

One more thing, because I am connecting it to my laptop. I am unsure if the same code can work because I am converting the RS-232 to a USB port before plugging into my laptop. Can you advise?


What USB-RS232 adapter are you using?  There are a lot of cheap ones out there that just do no work well.  Typically, an FTDI adapter works well.


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 5 of 17
(3,218 Views)

Are you sure you have the serial parameters correct?

 

Open up the subVI for Init and make sure it is setting the serial parameters correctly.  It makes some assumptions for data bits and stop bits that may or may not match the ones your device is actually using.  I never use the Modbus Init subVI and just explicitly set all of my serial settings using the regular Serial Configure.

 

Are you sure you are using the modbus slave address that is assigned to the device?  (I can't see what you used because the screenshot of a block diagram doesn't show what data is in the controls on the front panel.)

0 Kudos
Message 6 of 17
(3,205 Views)

Hi there Raven, 

 

I opened up my Init and took a look inside. Care to teach me how do you identify if my settings are in serial or not? (Front Panel of Init & Block Diagram of Init)

 

Aside from that, attached is also my latest version of codes with front panel image

(Block diagram is under diagram 1 and 2, pardon me because the image can't be fitted in one screen). 

 

The idea of my project is to extract parameters such as voltage directly from the controller that I am dealing with. 

 

As for the modbus slave address, I am trying to communicate with the holding registers from 40001 to 40009. I am still trying hard to figure it out and hope you can provide me any advice.

 

Appreciate your help, Raven. Cheers. 

0 Kudos
Message 7 of 17
(3,173 Views)

Btw Raven, I have set my Init settings to the ones specified by my controller, thus I believe it is already in serial settings. 

0 Kudos
Message 8 of 17
(3,171 Views)

That VI shows you are trying to read 20 registers starting at 3000 which means 43001.  Is that what you want?

 

What does the device's manual say?  Do you have a link to it?

 

It has nothing to do with a timeout error, but it is very strange you are using Decimate Array to get smaller arrays and coercing them into strings.  You should be using Index Array to get the individual U16 registers.

0 Kudos
Message 9 of 17
(3,163 Views)

Attached is the register that I am suppose to read from. What kind of information do you need? 

I know that the information that I am extracting is from a "WORD" type. I am unsure of how to handle from here. Can you advise me please.

0 Kudos
Message 10 of 17
(3,155 Views)