I am trying to use a Raspberry Pi 3 Model B to read values from an Allen Bradly PLC. I'm using the Pymodbus Modbus TCP protocol to communicate between them.
When I run a test client I get the following error:
pi#raspberrypi:/var $ python test1.py
Got here 1
Traceback (most recent call last):
File "test1.py", line 12, in <module>
request = client.read_holding_registers(0,1)
File "build/bdist.linux-armv7l/egg/pymodbus/client/common.py", line 109, in read_holding_registers
File "build/bdist.linux-armv7l/egg/pymodbus/client/sync.py", line 82, in execute
pymodbus.exceptions.ConnectionException: Modbus Error: [Connection] Failed to connect[10.0.0.237:502]
Here is the code for the test client:
from pymodbus.client.sync import ModbusTcpClient
#modbus connection
client = ModbusTcpClient(host='10.0.0.237')
connection = client.connect()
#test print
print "Got here 1"
#read register
request = client.read_holding_registers(0,1)
print request
client.close()
I can ping the IP address of the PLC's ethernet card (10.0.0.237) just fine. (The PLC is on and shows up in RSLinx and RSLogix5000.) But when I try to check port 502 (which Modbus uses) with the command:
telnet 10.0.0.237 502
I get the error:
Trying 10.0.0.237...
telnet: Unable to connect to remote host: Connection refused
The research I've done told me to check whether that port is open, but that is for PCs, I don't know how you check/configure the ports on a PLC.
In addition, I am wondering if the problem is that I am trying to just use Modbus to go between the Raspbery Pi and PLC. I have found prosoft gateways that do the interfacing. But I couldn't find any information on whether those were just another option or whether they were required.
I am new to PLCs and networking, so any help would be appreciated.
I have not used Allen Bradley myself but I do use a multitude of other PLCs though and they all work more or less the same.
You dont open the port as you would in a router but rather activate modbus connectivity in the PLC. Most often its a setting but if Allen Bradley use their own proprietary bus system (e.g Saia S-Bus) you sometimes need a specific function block to enable modbus.
A quick google search for example showed that in micrologix 1400 theres a checkbox to enable modbus tcp under some channel setting.
Check in the PLC if there is a setting to enable modbus master/client (master=serial or RTU, client=TCP but sometimes manufacturers dont differentiate them).
To test the Raspberry Pi you can download a modbus server simulator and poll that.
To test the PLC with something other then the Pi you could download a modbus client/master. I personally use QmodMaster which is free and works well for testing purposes (search google).
Also, make sure youre polling using the right function code. This can be confusing as holding registers (which are addressed 4xxxx) use function code 03. Input registers (which are addressed 3xxxx) use function code 04.
A modbus gateway is used to enable serial modbus (RTU or ASCII) to communicate via TCP.
If both devices do have modbus tcp theres no need for a gateway. If for example you have a device which only has wired modbus (RS232/485/422) you can connect that to a gateway and the gateway to TCP.
Related
My question is quite simple. Is it possible to communicate TwinCat PLC simulation (TwinCat 3 on normal PC) with real siemens S7-1200 over MODBUS TCP?
From what I've gathered, PC without Intel chipset network card prevents you from using protocols like EtherCat or Profibus. Nowhere in documentation is stated that Modbus TCP requires such card.
I've been trying to use Modbus TCP sample program from Beckhoff site for two days now, with no success. TCPView shows that connection between server (PC with TwinCat) and client (S7-1200) is "established" and even some packets are being exchanged. I'm pretty sure that the adressess and lengths and all that stuff are correct, yet TwinCat still gives me ERROR 26.
On the Siemens side MB_Client shows 7004 then 7005 and 7006 one after the other with no data coming to my array.
Is there something to do on the TwinCat side other than coping the sample code and changing the parameters, that i need to do? (I also set up the server with TcModbusSrvCfg.exe)
Sorry for the long post. If you have any ideas about what else i can do, plaase share.
Like Kolyur said, please check that TF6250 is installed on your machine.
As complement of Cliff response here are 3 tools to check your Modbus protocol on both sides :
Ananas,
Modbus Doctor,
Modbus Twin Request
Which Modbus function did you implement you could just try a simple Modbus write register (function 16).
My question is quite simple. Is it possible to communicate TwinCat PLC
simulation (TwinCat 3 on normal PC) with real siemens S7-1200 over
MODBUS TCP?
In answer to your question. Yes!! Absolutely you can!!
Is there something to do on the TwinCat side other than coping the
sample code and changing the parameters, that i need to do? (I also
set up the server with TcModbusSrvCfg.exe)
So part of your problem may be in this statement here. Using TcModbusSrvCfg.exe sets up the TwinCat PC Modbus TCP server, but the sample code provided in the manual is the TwinCat program acting as a Modbus TCP client. From your question it isn't 100% clear to me what you are trying to achieve.
The manual in section 2 (page 8 at the time of writing) shows the two different ways it can be setup. In the picture below;
the red line with a (1) next to it shows TwinCAT acting as a Modbus TCP Server, and
the red line with a (2) next to it shows TwinCAT acting as a Modbus TCP Client.
From your question it sounds like you have setup a Modbus Client on your siemens. If this is the case, you do not need to implement any example code in your TwinCAT program. The example code provided in the manual is for when Twincat is acting a Modbus Client. I think what you are probably looking for is to follow what is in section 4.
From a high level, the TwinCAT Modbus TCP server maps Modbus Registers to TwinCAT Memory areas. You would need to create TwinCAT tags and assign these tags to the appropriate memory areas. You can view the default mapping in section 4.3 or you can use the "Export Configuration" function on the Configuration tool to export an XML file where you can customize your mapping, and then import it again and apply the changes.
I don't know a lot about seimens, but to me it sounds as if your siemens client is actually connecting to the TwinCAT modbus server, however you have not created the relevant TwinCAT tags at the appropriate memory areas/address. If you want the seimens to read data from TwinCAT, then you will need to populate data in tags assigned to the memory areas in TwinCAT. If you want the siemens to write data to TwinCAT, then you will need to add tags in TwinCAT (again at the correct memory area) to view the data.
If however you do want TwinCAT to act as a client connect to a modbus server, you would need to following section 6.
Seems like the problem has to do directly with the configuration of your conection, the hardware itself shouldn't cause any problems with the connection and just like -kolyur said, for test you should deactivate the pc firewall.
As for the modbus server setup, you have to run the "TcModbusSrcCfg.exe"in your computer and set default parameters (to use your computer as server trough port 502), once you make a sucessfull conection with the PLC Siemens at port 502 (default configuration) you can try to modify the program.
The Beckhoff documentation already tells you the libraries, functions and values you should use for a default connection, just make sure you follow the server configuration steps, cause' in the past I had many issues with modbus just for not setting the modbus server right
I used this sample FB for modbus communitation to read from a Modbus Festo Master for IO Modules if you want to compare your variable values.
I need to communicate with several modules and devices using the ModBus Protocol and the Raspberry Pi.
I am using PyModBus on Raspberry Pi to read/write Modbus function codes. (https://pymodbus.readthedocs.io/en/latest/readme.html)
I was able to communicate Modbus RTU over RS485 with the device but now that I am trying to communicate ModbusTCP over a Ethernet cable and keep running into the following error:
import pymodbus
from pymodbus.client.sync import ModbusTcpClient
client = ModbusTcpClient('127.0.0.1')
connection = client.connect()
Output:
ERROR.pymodbus.client.sync: Conection to (127.0.0.1, 502) failed: [Errno 111] connection refused
Any tips or explanation for the error?
127.0.0.1 is a loopback address; this means that ModbusTcpClient('127.0.0.1') will attempt to establish a connection to the Pi iteslf. Unless there is a Modbus server running on the Pi the error you received is to be expected.
"I am trying to communicate ModbusTCP over a Ethernet cable" indicates you are communicating with another device which should have it's own IP address. You need to work out what that address is and use that when attempting to connect (as well as ensuring your network setup is valid). The method used to set/determine a devices address varies from device to device so you would need to check the documentation (you did not specify what the device is).
I have managed to use node-red to simulate a slave device using a TCP connection, but now I want to do it via serial connection. I am using a dell gateway running mbpoll to simulate the master connected to a raspberry pi running node-red to simulate the slave via RS485. Is it possible for me to use node-red on the raspberry pi to simulate the slave device, so it responds to requests from the gateway with values like a sensor would?
Based on your previous questions you are using node-red-contrib-modbus; this node does not support Modbus RTU as per the node descriptions:
modbus-server - Node to provide a Modbus TCP server based on node-modbus (jsmodbus) for testing.
modbus-flex-server - Node to provide a flexible Modbus TCP server based on modbus-serial for testing.
There may be another module out there that does support RTU slaves but I am not aware of one. As such I think your options are:
Modify the existing note to add support for RTP.
Use a gateway. There may be software that will do this (its not all that complicated) but I've not found anything freely available. There are a range of hardward gateways (some fairly cheap) that support comms between an RTU master and a TCP slave - e.g. 1 or 2.
I am trying to connect a WiFi module (ESP8266) to a "funduino" development board (Arduino Nano) but I have no success. Since I tried so much schematics I've found on the internet about the connection between them two, I kindly ask here if is anyone who succeed in "pairing" this two devices.
I am asking for the schematic and a functional source code.
Regards
The ESP-01 by default comes with nonOS SDK bootloader that communicated via AT commands, you can find the complete command set from Expressif here. This is designed for an MCU (like Arduino Nano) to use it purely as an WiFi module rather than using it as a stand-alone MCU (for which it will require NodeMCU SDK).
If you ever upload an Arduino sketch up to the ESP-01, it will erase the AT Command firmware.
Assuming your ESP-01 is still having the AT Command firmware. What #Ben provided is a sketch that allows you to type AT commands via the Serial Monitor to internact with the ESP-01, it is manual, and good for testing if ESP-01 is working (you type AT and press return on Serial Monitor, the ESP-01 will ack with Ok) but not practical as a real application. The minimum commands required to established an WiFi connection with ESP-01 is listed below.
AT+CIPMUX=1 - Enable single (0) or multiple connection (1) to the web server.
Multiple connection is a good option if you are repeatedly sending
out or reading data from the Internet.
AT+CWMODE=3 - Set WiFi mode: 1 is station mode (ESP8266 is client), 2 is AP mode
(ESP8266 acts like a WiFi router where your phone or PC can connect),
3 is AP+station mode (make the ESP8266 do both)
AT+CWJAP=“<your-ssid>”,”<your-pw>” - Connect to your WiFi. Provide your SSID name
and password inside the double qoutes.
AT+CIFSR - This returns the IP address of the module, indicating that it has
successfully connected to your WiFi router.
Once the WiFi connection is established, you can further communicate with the ESP-01 via the connection, like accessing a website for example:
AT+CIPSTART=0,"TCP", "www.example.com","80” - Start TCP or UDP connection. The
0 is the id of the connection.
AT+CIPSEND=0,16 - Command to tell the module data is ready to be sent. 0 is the
connection id, and 16 is the length of the data to be sent.
After this command, the ESP8266 will reply with the “>”
character to tell us that it will be waiting for the data to be
sent. If successful, the module will reply with “SEND OK”
GET / HTTP/1.1 - Send the http header, and other data, etc...
You can write your own sketch to automate those AT commands for interacting with with ESP-01 once you understand the AT commands required for establish a WiFi connection.
Here are two resources that I personally found extremely useful for doing more than connecting to WiFi.
STM32-ESP-01 Web Server - although this is for interfacing with STM32, the main difference is the pin assignment, so you should be able to port to Arduino easily.
MQTT via ESP-01
As for hardware interface, please noted that what #Ben provided is correct in principle, but you need to be aware that the ESP-01(ESP8266 to be precise) is a 3V3 MCU, so the connection is depended on what kind of host board you are using. If you are using Arduino Uno/Nano, both are having a 5V MCU, you will need a voltage divider (two resistors to drop the voltage to 3v3 before connecting to ESP-01) or a level shifter chip at least for the ESP-01 Rx pin to avoid the potential damage to the ESP-01.
my company uses the application PRTG from paessler.com to monitor several SNMP sensors, I need to monitor the voltage of some devices and transmit it to the manager.
I was going to use an ESP8266 programmed via arduino to do it.
So far I've been able to send data to the ESP via UDP, and I configured it in the manager so it can retrieve the information from it and ping it.
The ping tests are successful however the monitoring does not work, by using the serial interface I can see that the ESP is receiving the data from the manager, with the OID that was set up. But the monitor shows it as inactive, I set up the ESP to send a simple string in the response.
When using a program called Packet Sender I am able to send the udp packets and receive the response as well, and everything works fine.
The ports I am using is 161 to receive in the ESP and I made it send to the 161, 123, 1023 as i saw specified in the prtg site
I may be sending the packets trough a port that is not the right one, or maybe I have to put a header before the message so the controller can Interpret it. I am not sure what the error can be. Any help will be apreciated
pretty easy - simply use the http push sensor from PRTG:
https://www.paessler.com/manuals/prtg/http_push_data_sensor
All best
Christian