Instrument Control (GPIB, Serial, VISA, IVI)

Showing results for 
Search instead for 
Did you mean: 

Serial com with USB485 - ModBUS

Hi everyone, first post!


My problem is: I have a slave that is communicating modbus RTU / serial RS485. I got myself a USB-485 because my representative told me that is what I need to communicate with modbus.


Now, what would be my first steps ? All I tried by my own didn't work (not even able to read the serial port on a buffer). I think I just don't start the process adequatly. Please tell me what would be my first step.


I don't need detailled steps, but a high level view of those steps.


Thank you



0 Kudos
Message 1 of 30

Hi Eric,


Get a feeling that you miss some knowledge about your problem.


First of all RS-485 is a hardware type interface. Regardless of the data type.

ModBus is a data protocol. Regardless of the hardware interface.


You have a RTU / RS485 slave. So your USB interface is correct.


Now you need to handle the ModBus protocol. Simple writing something (and reading) is not enough.


Use the ModBus library from NI. You can find it here.


0 Kudos
Message 2 of 30



Thank for the reply.


I do know difference between serial and ModBUS. I have already tried the ModBUS lib, but can't make it works and this is hard to debug myself because there is no help detail with that lib (well it has, but do not work, when I open help on a VI's, return me a blank/error internet page on the help window), maybe you have this help written somewhere else so I could use it.


That is why I decided the start from the beginning by opening a serial com and just look if I can see data at my port. I see nothing.




0 Kudos
Message 3 of 30

Please forget about the help issue, I just resolved this issue, I will give another try to the modbus lib now I have the help.

0 Kudos
Message 4 of 30

Whenever I have to talk to a ModBus device I do not use the MB lib. I just create my own ModBus messages.

During testing it was easier to use my own VI's and after that it was easier for me to keep using them.

MB is rather simple to use.


It also depends on what MB commands you need to use.




0 Kudos
Message 5 of 30

The only command I need to do is read and write holding registers, nothing to much complicated. I have my table of registers and I do have suceed in the past to communicate with my actual slave with another device via modbus.


If you tell me the MB lib from NI isn't appropriate (as I tough at first) I will write my own protocole, but never did it before, this is why I asked what would be the steps to acheive it from the beginning and what method could be used to test my serial com is actually working.


Thank you



0 Kudos
Message 6 of 30

Hi Eric,


It is not that the MB lib is not appropriate, but for me it is better and easier to construct the MB messages myself.


You can start with the MB loopback command. Every MB slave should support this command.

If you send the following 8 bytes:


             0108 0000 8844 8638


you should receive the same bytes back from your slave.


01 is slave address

08 is the loopback command

0000 is data of the LB command (must be zero)

8844 is custom data can be anything

8638 is the CRC of this command


The bytes are in hex so you must set your string control to hex


Let me know what you can do with this command.



0 Kudos
Message 7 of 30

Good afternoon,


Please have a quick look at the test VI I quickly built. How I understood it, I write the loop back command at the serial port and I should read it at the read buffer, am I right? This does not work, read buffer's always empty '' ''.


If yes, I will start looking at my hardware slave... maybe my problem lays there.


Thanks again



0 Kudos
Message 8 of 30

Good evening (for me),


Add some time between the send and receive. Your cannot reply that quick. See modified file.



Good night, Kees

0 Kudos
Message 9 of 30

Hi Kees,


Did some works... finally found the problem was not software, but hardware. I did a loopback (shorting Tx - Rx) with my USB-485. Works very well. Doing so I realized the pinout of the DB9 connector was not as I tought it was (pdf joined).


I need to build a new cable to interface the USB485 to my slave. My question is the following:


I am not sure which pin of the USB485 i should use. My slave pinout is only RS485+, RS485- and shield. I do not have Tx+ Tx- Rx+ Rx-.


How do you think I should make the connection between my slave and the USB485????


Thanks again.



0 Kudos
Message 10 of 30