Industrial Communications

cancel
Showing results for 
Search instead for 
Did you mean: 

Communication with modbus devices

Hello All,

 

My name Peter, I am currently exploring what LabVIEW has for instrument communication. I have explored a little on NI-Visa and used it for instrument communication through USB and Ethernet. My next task just now is to see how I can communicate with Modbus devices. I have done some background reading on modbus communication protocol and now have some level of understanding of what it is about. I hope to understand more as I continue to read more materials.

 

I came across an NI-Tutorial  titled Connect LabVIEW to any PLC with Modbus. It is about communicating with a networked PLC using modbus. I followed all the steps described for creating Modbus master I/O Server, Binding shared variables to Modbus Address through the I/O Server and writing to Modbus Addresses in LabVIEW. On running my VI to deploy the shared variable, the following error occured.

 

Untitled.png

 

 

Can anyone please guide me on what to do because I do not know exactly what is going ON. I engaged in this excercise with the hope of getting to understand more about Modbus communication and then see how I can apply thesame idea to communicate with the Modbus device available in my Laboratory. Please note that I do not yet know much about modbus communication and I am just learning about it now. I do not have any PLC connected to the network. Could that be the reason for the error? If anyone has got any other relevant document to help me get started with modbus communication I will be happy to have them posted here.

 

Thanks very much for taking time to read through my post message. Hope to hear a quick response from you.

 

Regards

 

Peter

 

 

 

 

 

 

 

 

 

 

 

0 Kudos
Message 1 of 16
(9,880 Views)

Hi Peter,

 

This error is related to the Shared Variable Engine not working, which your modbus application depends on to deploy it's variables.

 

As a starting point, please see this article to see if you can get this service up and running again: Why do I Receive Error -1967362042 (0x8ABC7006) When Deploying a LabVIEW Library?

0 Kudos
Message 2 of 16
(9,859 Views)

Hi AranS,

 

Thanks so much for your reply. I was getting a bit worried that no body responded to my post message. I have looked at the link you sent and have confirmed that the shared variable engine is running. I have been able to follow through the example in the NI tutorial and was able to use the shared variable to turn on and off all the Bolean in the Modbus simulator example.

 

My latest challenge is reading the holding register of a modbus device with a shared variable bound to the modbus address. I have never done this before, neither have I seen any working example on this. This device has been connected to my pc using a USB-RS485 cable and  COM3 was assigned to the serial port. Following the approach detailed in NI Tutorial  http://www.ni.com/white-paper/13911/en/, I have created a modbus master I/O server and bound some modbus shared variable to the modbus addresses (400050 - 400060) with the hope of having direct access to the information contained in the holding register of the device. I don't know whether I am in the right line of thinking right now because it is not working. The configuration for my I/O server is as shown below

 

IO Server.png

 

The modebus slave device holding register has previously been read (by someone else) using the QModMaster application. From that, I know the decimal value to expect from the addresses selected. The configuration  used with the QModMaster application is,

 

MODBUS MODE:  RTU

COM PORT:   COM3

BAUD:  9600

DATA BITS:  8

STOP BITS:  1

PARITY:  None

RTS:  Disable

SLAVE ID:  3

SCAN RATE:  1000

FUNCTION CODE: Read Holding Register (0x03)

FORMAT:  Decimal

START ADDRESS: 0

NUMBER OF REGISTERS: 99

 

The error I am getting right now on running the VI i created (shown on the previous picture) is as shown below

 

Error.png

 

Can someone please tell me what I am not doing right? I need an urgent response please.

 

Thank you.

 

PETER.

0 Kudos
Message 3 of 16
(9,852 Views)

It looks like you fixed the SV Engine issue, but now you're just having a modbus issue. You'll see on that dialog that some common settings are exposed like baud rate and parity. Other settings, like if the 485 port is in 2-wire mode for example, are not set. You can fix this by dropping down a visa property node as shown. I believe this setting must be changed before the I/O server runs, so you may need to undeploy, change the setting using a VI, redeploy, and then itll work.

1111.png

 

You can also change this setting from MAX, either on the main page or using the test panels:

2222.png

0 Kudos
Message 4 of 16
(9,843 Views)

I stumbled into an example that I think would be a good working example to get me started. The example can be found at http://forums.ni.com/t5/LabVIEW/DSC-module-and-Modbus-RTU/td-p/484621. On running this example VI I could see that the master Request is (03030032000B) - I understand exactly what this means. Then it passes through the CRC VI and what comes out of this (I do no understand) is shown on the snap shot below (Probe 5). The VI finally returns an error after going through the COM port VI. The error is also shown on the snap shot. I am just thinking of what to do right now. Kindly leave a message for me if anyone has got an answer to my problem. I am still interested in achieving thesame task using the I/O server.

 

error.png

 

 

0 Kudos
Message 5 of 16
(9,839 Views)

Hi Smithd,

 

I am so glad you reponded to my post message. Thanks alot for letting me know that the serial wire mode have to be set. I never knew that before!

 

I have however done as you suggested but that didn't solve the problem. I got another error as shown below. I have tried all the available RS 485 settings on the instrument property node and none seem to be working.

 

What else could be the way out of this?

 

error2.png

 

Don't mind the port number (COM4) at some point I changed the number assigned to the port from COM3 to COM4.

0 Kudos
Message 6 of 16
(9,838 Views)

Hi everyone here,

 

I have tried yet another idea. This time around I am using the Modbus Library which I downloaded from https://decibel.ni.com/content/docs/DOC-30140 and this is what I did with it.

 

Error3.png

 

{I used a create serial master VI to create a serial master instance using the appropriate input terminal specifications.

Then a read holding register VI used to read the register of interest using the serial master instance together with the

Start address and number of registers to read. I expect that this will give me an output which is the values on these registers.

I have also included a shudown VI to shutdown the modbus instance and release the COM4 port.}

 

I thought this was a good idea but, I am afraid I yet to get things working. The VI returned the error shown above.

 

Please someone help me out! Tell me what I have not done well and how I can resolve these problems. It is my first modbus communication and I am yet to get things right.

 

 

 

 

 

0 Kudos
Message 7 of 16
(9,818 Views)

For the first issue, you can only set the port settings when the I/O server is not running.  To stop it you can use Distributed System Manager (just use the windows start menu search functionality to find it). You'll see the process under your computer and can right click to stop it. Then you should be able to use the property node. Then you can right click and start the process again.

 

For the second case, my guess is its the same problem. Error 56 just means the slave never responded. Here, add the property node for wire configuration between your unbundle and the modbus create instance VI. Unlike I/O servers, which run constantly, the library only locks down the VISA resource after you initilaize the library. However, you need to make sure you have the I/O server stopped in order to use the library. Otherwise you'll see the same issue (the library is trying to change settings on a port controlled by the I/O server).

 

 

0 Kudos
Message 8 of 16
(9,804 Views)

Hi SmithD,

 

I would like to say thank you very much for making out time to respond to my queries. I have done as directed but still not getting result. Following the wire mode port setting configuration, I stopped the process and then selected the RS485/wire4 as the wire mode. On running the VI, an error pops up with the information that the Visa resource is Valid but the port cannot be accessed. I noticed that If I undeploy the shared bound variable the error does not pop up anymore. I concluded that maybe I was not supposed to have added the VISA configure Serial port in the first place.

 

Kindly tell me what to do.

 

My task is to read the holding register from a Modbus device. I have the register map with me, and know the TCP and RTU settings for this device. After the attempts I have made so far I was forced to believe that perhaps the device was not responding. I then resolved to using the QModbusMaster which was previously used to read the holding register. For reasons I don’t not know, It worked well with the TCP communication and returned an error that read " slave threw exception > unknown error". With that, I am now sure that the device is functioning properly, at least with the TCP.

 

Having obtained result from the TCP using QModbusMaster application, I want to simply do the same using LabVIEW.

 

Some few questions for which I would want to ask for clarification are:

 

1.)  When using the Modbus Library, do I need to create both master and slave instance to be able to read the holding register? My attempt was to create a Master instance with the RTU parameters. The starting address and number of registers were specified at the input terminals of the Read Holding Register VI. This VI immediately followed the Create Master Instance VI. I was expecting that that would read the information contained in the specified registers and output it at the register value terminal. One challenge with this attempt was that with RTU it didn't work. I tried selecting TCP as the VISA resource. But the device was not showing on the list. I went to MAX to create a new VISA TCP/IP resource under the network devices but MAX could not detect the presence of the device. I am now thinking maybe the device is not supported by NI-VISA and so it will not be possible to use the Modbus Library with it.

 

2.) If the device is actually not compatible with NI-VISA, can DSC I/O server be used to read the information on the holding register?

 

3.) Do I need an intermediate device between a Modbus device and the PC to be able to read its holding register?

 

 

Please if anybody has got a good suggestion as to what to do to  get my task achieved, kindly leave me a post.

 

Thanks

 

PETER

0 Kudos
Message 9 of 16
(9,768 Views)

 Wow! I have been able to read the Holding Register of my Modbus slave device. Smiley Very Happy

 

I simply used the Modbus library VIs (Create Modbus Instance VI with TCP configuration, Read Holding Register VI and a Shut down VI). All values read corresponds with that read using QModMaster Smiley Happy

 

I am now trying to do the same using the DSC I/O server. I am getting zeros all through.

 

Can someone please take a close look at my approach and tell me what I am not doing right?

 

My approach:

 

1.)  I created a new project and a TCP Modbus Master I/O server

2.)  I created bound variable 400001 - 400099 to read the registers in that range

3.)  I then deployed the library

4.)  I created a NI VI, drag and drop some of the bound variable on the block diagram windows of the new VI after which I created an indicator to view their values

5.)  On running the VI it gave an error that there is no connection with the slave

6.) Then I decided to create a new slave I/O server and bound exactly the same range of  variables to the Modbus slave library.

7.)  I deployed the library and then re-run the VI I created before, at this time it was running without any error but all values remain zero.

 

Please I need the support of those who have used the I/O server to read holding registers before. I will appreciate all suggestions that will get me towards obtaining the values held in the holding registers.

 

Thanks to all of you here

 

PETER

0 Kudos
Message 10 of 16
(9,749 Views)