05-18-2017 09:42 PM
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.
05-18-2017 10:13 PM
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.
05-18-2017 11:12 PM
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 🙂
05-18-2017 11:16 PM
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 !
05-19-2017 07:06 AM
@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.
05-19-2017 08:13 AM - edited 05-19-2017 08:16 AM
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.)
05-21-2017 08:39 PM - edited 05-21-2017 08:40 PM
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.
05-21-2017 08:44 PM
Btw Raven, I have set my Init settings to the ones specified by my controller, thus I believe it is already in serial settings.
05-21-2017 10:30 PM
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.
05-21-2017 11:58 PM
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.