Monday, October 10, 2016

WAGO 750-843 Controller using Python and Modbus.


It took me ages to get everything up and running, so i hope i can save you some time.

Ethernet:

All TCP/IP stuff of the 750-843 is not configured by default, so there is no Ethernet connection possible. To fix that, use the following steps;

Bootp server: http://global.wago.com/download.esm?file=\download\00174968_0.zip&name=BootPS_en.zip
Assign IP:  http://global.wago.com/appnoteadmin/appnotes/a202001/public/a202001_en%20-%20IP-Address%20assinging%20for%20WAGO%20Ethernet-Controller.pdf

  1. Connect the controller to the same subnet as you.
  2. Read the mac address from the sticker on the Wago device 00:30:DE:##:##:##
  3. Start a bootp server on Windows/Linux with the mac of the Wago device and a static ip address for the device.
  4. Power up the Wago
  5. Wait until the ip address assignment is confirmed by the bootp server.
  6. Browse to the Wago's ip address with a web browser**
  7. click "ports"**
  8. login with: user: admin password:wago**
  9. On the webpage, uncheck the Wago bootp client to stop the bootp server.**

ModBus: 

The addresses/ registers for modbus are quite a complex mismatch. But can be found by simulating the device in Codesys or using a Wago software tool.

pymodbus: https://github.com/bashwork/pymodbus
pymodbus docs: http://pythonhosted.org/pymodbus/index.html
Codesys with wago lib: http://global.wago.com/download.esm?file=\download\00366630_0.iso&name=CODESYS_2.3.9.49_DEMO_BUILD_20160224.iso
Modbus pdf : http://www.wago.us/appnoteadmin/appnotes/a300003/public/a300003_en%20-%20Modbus%20with%20WAGO%20Ethernet%20Couplers%20and%20Controllers.pdf
  1. Browse to the Wago's ip address with a browser**
  2. Click "ports"**
  3. Login using: user: admin password:wago**
  4. Make sure modbus TCP is enabled in the table.**
  5. Now on the connected pc install the required python packages https://pypi.python.org/pypi/pymodbus by typing: sudo pip install pymodbus
  6. Check if there is a connection by reading the slaves connected to the controller:
    import sys
    from pymodbus.client.sync import ModbusTcpClient
    client = ModbusTcpClient(host='192.168.1.1',port=502)
    client.connect()
    bus = client.read_input_registers(0x2030, 65)
    
  7. 'bus' should contain the connected slave devices.
  8. To find the addresses of the slave devices install Codesys, and add the devices in the correct order to generate the correct image.
  9. Now we can read and write to to correct addresses:
    value = client.read_holding_registers(addres, data)
    value = client.write_register(addres, data)
    value = client.write_coil(addres,bit)
    
  10. Some clear examples can be found at http://pythonhosted.org/pymodbus/examples/custom-message.html

** Somehow my device doesn't have a working web interface. So the bootp client of the Wago is always running. Since I'm directly connected to the device i didn't bother updating or checking any further, but this is an issue..
***Python stuff is copy pasted html using http://hilite.me/