TCP/IP CONNECTION using MODBUS PROTOCOL
According to the National Instruments website (http://www.ni.com), LabVIEW 8 has the possibility to communicate through TCP/IP using the Modbus Protocol.
In an example on the website, it shows how a server can be build by using the Modbus protocol. The way the server was built, is exactly the way we are trying to set up a server for our project.
We also simulated the server/client example from the Getting Started Menu. Open the folder Find Example>>Toolkits and Modules>>Datalogging and Supervisory Control>>Servers>>Modbus Demo & Modbus Simulator.
The communication between the server and the client was perfect. But by reproducing the example, it was not possible to set up a communication between the server and a client.
Even though we followed all the steps that were illustrated, it still was impossible to receive any data from the client.
Next, will the set up of the client/server communication be explained.
The way the server and the client project was built, will be shown in steps below:
BUILD SERVER/CLIENT
Step 1. Create an Empty Project from the Getting Started Menu.
Step 2. The opened Project, will be the “Server”.
Step 3. Right click on My Computer, Select>>New>>Library
Step 4. Save the Library with the name ModbusServer. ModbusServer.lvlib will appear.
Step 5. Create a Modbus I/O Server. Right click the Library (ModbusServer.lvlib), select I/O Server, choose Modbus and click Continue.
In the Configue Modbus Instance Window, select Modbus Ethernet. In the I.P address box, fill in 127.0.0.1 and OK.
Step 6. Create Shared Variable. On the Toolbar select Tools>> DSC Module>> Multiple Variable Editor…
When the Window opens, select from the Toolbar Edit>>Create Bindings.
From the “Project Items” open the ModbusServer Library.
For a simple test, we will only use four addresses.
Add four addresses and press OK.
Step 7. Save the added variables with the name “server” and close the application.
Step 8. Repeat step 1 through 7 to build the “Client/Slave” with some adjustments. These adjustments will follow below:
ADJUSTMENTS:
Step 2. The opened project will be the “Client/Slave”.
Step 4. The new Library will be named ModbusClient. (ModbusSlave.lvlib will appear).
Step 5. Create a Modbus Slave. Right click the Library (ModbusClient.lvlib), select I/O Server, choose ModbusSlave and click Continue.
In the Configue Modbus Slave Instance Window, select Modbus Ethernet and press OK.
Step 6. Create Shared Variable. On the Toolbar select Tools>> DSC Module>> Multiple Variable Editor…
When the Window opens, select from the Toolbar Edit>>Create Bindings.
From the “Project Items” open the ModbusClient Library.
Add the same four addresses that were used in the ModbusServer and press OK.
Step 7. Save the added variables with the name “client” and close the application.
When finished, the projects will appear as followed:
The left project is for the Server and the right one is the Client. Both with four addresses added.
CREATE VI's
Next we create a simple VI to test the application. First we construct the VI from the client. Next we will use two digital inputs and two analog inputs.
The Block diagrams of the server and the client/slave was constructed as followed. See figure below.
Addresses 000001 and 000002 are both Boolean True/False Variables.
Addresses 400001 and 400002 are both Double Bytes Variables.
The digital inputs are the two toggles referring to addresses 000001 and 000002
The analog inputs are the Knobs referring to addresses 400001and 400002.
Block diagram of Client
Front Panel of Client
Block Diagram of Server
Front Panel of Server
RUNNING THE VI's
Before running the VI's, a download process has to be made. First run the client VI and next the server VI. After a successful downloading, it is ready for the client to communicate with the server.
But no communication was established. By switching the toggle on, the led on the server diagram was not switched on. Even when the values of the knobs were changed, no value was shown on the server diagram.
The only change that can be seen on the server VI is that the arrows are turned green. But nothing else could be observed.