Modbus Example Ethernet Adapter

From Digi Developer

Jump to: navigation, search

Contents

Modbus Bridge Example - Ethernet Adapters

This is the XBee to Ethernet node portion of an Modbus Bridge example using a Digi ConnectPort X4 as the central Modbus/TCP bridge and a collection of serial and Ethernet nodes.

This page shows how to enable XBee wireless to be bridged to Modbus/TCP servers (or slaves). This is NOT directly related to use of Modbus/TCP to query remote nodes via XBee wireless.

To see how to Bridge mesh to Modbus/RTU serial slaves, see this web page: Modbus_Example_Serial_Adapter

Supported Models

  • Digi ConnectPort X2 when loaded with firmware 82001596 (Ethernet model) or 82001630 (Wi-Fi model), which supports Python.

Product Installation

Confirm that you have the correct power for your ConnectPort X2 - probably 9 to 30vdc. If you want to use an existing shared 12vdc or 24vdc supply, Digi sells a power-pigtail with the correct locking barrel connector - details are here: Locking_Power_Connecter

You'll also need to make sure the appropriate antenna is installed - and if the CP-X2 is to be installed inside of a metal enclosure, you'll need to plan to mount the appropriate external antenna options.

Reflash the CPX2's XBee Module

To allow Modbus/RTU traffic on the XBee wireless to bridge to local Ethernet servers, you'll need the XBee module to be flashed with the XBee Router API firmware (such as 0x2364) - NOT the default XBee Coordinator API firmware. Quite literally, you need the CPX2 to be a member of the central CPX4 bridge's mesh, so the CPX4's XBee is to be the Coordinator; NOT the CPX2's XBee.

You can either:

  • use the Web UI to upload the EBL file (such as XB24-ZB_2364.ebl or XBP24-ZB_2364.ebl)

Image:X2_xbee_firmware.jpg‎

If you instead dissemble the CPX2 unit and manually reflash the XBee using a serial or USB development board, then make sure you enter the settings below. These should already be handled if you used the Web UI:

  • Load Destination Address High (DH) with the upper 4 bytes of your CPX4 gateway XBee address
  • Load Destination Address Low (DL) with the lower 4 bytes of your CPX4 gateway XBee address
  • Set the lower 16-bits of the Device Type Identifier to 0x0003 to define this as a CPX2

As a second step, enter this Setting:

  • Set the Baud Rate to 115200 (BD=7). This will have defaulted back to 9600 after you reflashed the XBee firmware, plus XCTU might give you an error as you try to set this.

Configure the CPX2's XBee Module

If the CPX2 and XBee are properly configured, then the CPX2 will show up on both the "Network View" of the Digi ConnectPort X4 (the central bridge) and on that of the Digi ConnectPort X2. You can configure the following settings via either the CPX4 or the CPX2:

Image:X2_xbee_disp.jpg

Click on the appropriate Extended Address (MAC address) link and you will see the Basic settings page:

Image:X2_basic.jpg‎

On the XBee Configuration - Basic Settings page:

  • Confirm the Extended Address, Product Type and Firmware are appropriate.
  • Manually force the Extended PAN ID to be your fixed value. As long as this value is zero (0x0000000000000000), then your CPX2 may associate with any ZigBee coordinator within RF range. True, it will "prefer" to remain associated to the current CPX4, yet someday it will move. So always hard-code your desired PAN ID. A phone number is a good, memorable PAN ID.
  • Add a user-friendly Node Identifier - by default this will be a single SPACE character. If you are doing low-level API message formatting, then you can query device addresses based on this name, however for most users it only makes the gateway XBee display more useful.

Enabling the Python application to do the bridging

To enable the bridging of XBee wireless packets to local Modbus/TCP server/slaves, you'll need to upload the appropriate python files to your CPX2.

Create the address.txt file

The first generation of this tool supports a single Modbus/TCP server/slave, and its IP address must be uploaded in the text file named "address.txt". The ":502" at the end is optional, but can be used to change the default TCP port number to use.

192.168.196.6:502

Uploading the Files

Click the Python Application link, then upload the three files: mbus_bridge.py, crc16.py and address.txt. They are contained in this ZIP file: Media:X2_mbus_2009Sep13.zip

The file list should look similar to that below, however the file sizes may vary:

Image:X2_python_files.jpg‎

Enable auto-start of the bridging

After uploading the files, click the Auto-Start Settings section and enter the mbus_bridge.py.

Image:X2_python_start.jpg

Note that this Python application closes all sockets and sleeps for 60 seconds anytime there is a fault. So if you are moving Ethernet cables around or doing other disruptive things, the CPX2 might not appear to function for a minute or two.

Personal tools
Wiki Editing