by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 14:46
    bsuiram commented #485
  • 13:00
    bsuiram commented #485
  • 12:57
    bsuiram commented #485
  • May 24 12:04
    dhoomakethu commented #485
  • May 22 04:40
    dcneeme commented #226
  • May 21 12:29
    dhoomakethu commented #226
  • May 20 18:01
    Cougar commented on 0fd3870
  • May 20 18:01
    Cougar commented #226
  • May 20 17:58
    Cougar commented #226
  • May 20 08:25
    erlend-aasland commented #504
  • May 20 08:25
    sonarcloud[bot] commented #504
  • May 20 08:25
    sonarcloud[bot] commented #504
  • May 20 08:24
    erlend-aasland edited #504
  • May 20 08:24
    erlend-aasland synchronize #504
  • May 20 08:21
    erlend-aasland edited #504
  • May 20 08:19
    erlend-aasland closed #505
  • May 20 08:19
    erlend-aasland commented #505
  • May 20 07:45
    bsuiram commented #485
  • May 20 07:34
    bsuiram commented #485
  • May 20 07:34
    bsuiram commented #485
dhoomakethu
@dhoomakethu
👍
Andreas Freytag
@Wurzeltroll
Hello. I'm trying to use the Serial Forwarder Example, but I cant figure out how the client has to look like. I tried with from pymodbus.client.sync import ModbusTcpClient. When I execute the same Test (reading one coil) instead directly with ModbusSerialClient, it works.
dhoomakethu
@dhoomakethu
Are you trying to modify the code for any particular use case? The example should work as it is provided you are using correct ports and parameters
Andreas Freytag
@Wurzeltroll
I only added the baudrate and adjusted the port but everything else is original.
Andreas Freytag
@Wurzeltroll
This is my test client
import logging
logging.basicConfig()
log = logging.getLogger()
log.setLevel(logging.DEBUG)

from pymodbus.client.sync import ModbusTcpClient

c = ModbusTcpClient(host="169.254.117.35", port=5020)
c.connect()
rr=c.read_coils(0x4e,1,unit=3)
This produces this log:
DEBUG:pymodbus.transaction:Current transaction state - IDLE
DEBUG:pymodbus.transaction:Running transaction 1
DEBUG:pymodbus.transaction:SEND: 0x0 0x1 0x0 0x0 0x0 0x6 0x3 0x1 0x0 0x4e 0x0 0x1
DEBUG:pymodbus.client.sync:New Transaction state 'SENDING'
DEBUG:pymodbus.transaction:Changing transaction state from 'SENDING' to 'WAITING FOR REPLY'
DEBUG:pymodbus.transaction:Transaction failed. (Modbus Error: [Invalid Message] Incomplete message received, expected at least 8 bytes (0 received))
DEBUG:pymodbus.framer.socket_framer:Processing:
DEBUG:pymodbus.transaction:Getting transaction 1
DEBUG:pymodbus.transaction:Changing transaction state from 'PROCESSING REPLY' to 'TRANSACTION_COMPLETE'
dhoomakethu
@dhoomakethu
Can you share the server code as well please ?
Andreas Freytag
@Wurzeltroll
Hi. Sorry for the delay. Here is the code
#!/usr/bin/env python
"""
Pymodbus Synchronous Serial Forwarder
--------------------------------------------------------------------------

We basically set the context for the tcp serial server to be that of a
serial client! This is just an example of how clever you can be with
the data context (basically anything can become a modbus device).
"""
# --------------------------------------------------------------------------- # 
# import the various server implementations
# --------------------------------------------------------------------------- # 
from pymodbus.server.sync import StartTcpServer as StartServer
from pymodbus.client.sync import ModbusSerialClient as ModbusClient

from pymodbus.datastore.remote import RemoteSlaveContext
from pymodbus.datastore import ModbusSlaveContext, ModbusServerContext

# --------------------------------------------------------------------------- # 
# configure the service logging
# --------------------------------------------------------------------------- # 
import logging
logging.basicConfig()
log = logging.getLogger()
log.setLevel(logging.DEBUG)


def run_serial_forwarder():
    # ----------------------------------------------------------------------- #
    # initialize the datastore(serial client)
    # ----------------------------------------------------------------------- #
    client = ModbusClient(method='rtu', port='/dev/serial0')
    store = RemoteSlaveContext(client)
    context = ModbusServerContext(slaves=store, single=True)

    # ----------------------------------------------------------------------- #
    # run the server you want
    # ----------------------------------------------------------------------- #
    StartServer(context, address=("169.254.117.35", 5020))


if __name__ == "__main__":
    run_serial_forwarder()

I really just adjusted the address for the TCP part and the serial port of the serial part
This is the produced log:

DEBUG:pymodbus.server.sync:Started thread to serve client at ('169.254.117.34', 50584)
DEBUG:pymodbus.server.sync:Client Connected [169.254.117.34:50584]
DEBUG:pymodbus.server.sync:Handling data: 0x0 0x1 0x0 0x0 0x0 0x6 0x3 0x1 0x0 0x4e 0x0 0x1
DEBUG:pymodbus.framer.socket_framer:Processing: 0x0 0x1 0x0 0x0 0x0 0x6 0x3 0x1 0x0 0x4e 0x0 0x1
DEBUG:pymodbus.factory:Factory Request[1]
DEBUG:pymodbus.datastore.remote:validate[1] 78:1
DEBUG:pymodbus.transaction:Current transaction state - TRANSACTION_COMPLETE
DEBUG:pymodbus.transaction:Running transaction 3
DEBUG:pymodbus.transaction:SEND: 0x0 0x1 0x0 0x4e 0x0 0x1 0x9c 0xc
DEBUG:pymodbus.framer.rtu_framer:Changing state to IDLE - Last Frame End - 1579188682.378896, Current Time stamp - 1579188742.256109
DEBUG:pymodbus.client.sync:New Transaction state 'SENDING'
DEBUG:pymodbus.transaction:Changing transaction state from 'SENDING' to 'WAITING FOR REPLY'
DEBUG:pymodbus.transaction:Incomplete message received, Expected 6 bytes Recieved 0 bytes !!!!
DEBUG:pymodbus.transaction:Changing transaction state from 'WAITING FOR REPLY' to 'PROCESSING REPLY'
DEBUG:pymodbus.transaction:RECV:
DEBUG:pymodbus.framer.rtu_framer:Frame - [b''] not ready
DEBUG:pymodbus.transaction:Changing transaction state from 'PROCESSING REPLY' to 'TRANSACTION_COMPLETE'
ERROR:pymodbus.pdu:Exception Response(129, 1, IllegalAddress)
DEBUG:pymodbus.server.sync:send: b'000100000003038102'
DEBUG:pymodbus.server.sync:Handling data:
DEBUG:pymodbus.framer.socket_framer:Processing:
DEBUG:pymodbus.server.sync:Client Disconnected [169.254.117.34:50584]

Andreas Freytag
@Wurzeltroll
I guess I will just write something with xmlrpc
ujwalashirodkar21
@ujwalashirodkar21
Serial rtu communication for server.async library is not implement....is there any alternative to have async modbus communication
Rosario Iameo
@RosarioIameo_twitter
hi all
Matt Sargent
@mcsarge
Hi, Is this were I can ask a question about an error in pymodbus?
Matt Sargent
@mcsarge
I am attempting to read registers from a device and it works perfectly when the addresses are in the 4000-4900 range, but as soon as I try to read register from the device at location 16384 I get the following error:
...\Python\Python38\lib\site-packages\pymodbus\payload.py", line 316, in fromRegisters
raise ParameterException('Invalid collection of registers supplied')
pymodbus.exceptions.ParameterException: Modbus Error: [Invalid Parameter] Invalid collection of registers supplied
Any ideas on this? These registers are successfull read from another program using the Java Modbus Library (jamod).
Matt Sargent
@mcsarge
Cancel the above question. It was pilot error.
dhoomakethu
@dhoomakethu
@ujwalashirodkar21 It should be available, check the example https://github.com/riptideio/pymodbus/blob/master/examples/common/asyncio_server.py
gunner009
@gunner009
i am creating modbus sync tcp server
can anyone help me to to get Modbus RTU conversion to Modbus TCP server
i am reading data from energy meter using RS485 to serial convertor and want to format it into tcp server
i have created server but values read from energy meter are not updating in tcp server
can anyone tell me hoe can i run tcp and rtu at same time without effecting anyone
dhoomakethu
@dhoomakethu
There are examples in the repo called serial forwarder which does what you are looking for
gunner009
@gunner009
thank you have anyone tested it
i have connected two temprature sensor through rtu to raspi
and using easymodbus client to read modbus data
gunner009
@gunner009
getting Exception respones (131,3,IlleagalAddress)

ModbusSerialClient(rtu baud[19200])
Remote Slave Context(ModbusSerialClient(rtu baud[19200]))

<pymodbus.datastore.context.ModbusServerContext object at 0x763249d0>
DEBUG:pymodbus.server.sync:Started thread to serve client at ('192.168.1.227', 50671)
DEBUG:pymodbus.server.sync:Client Connected [192.168.1.227:50671]
DEBUG:pymodbus.server.sync:Handling data: 0x0 0x7 0x0 0x0 0x0 0x6 0x1 0x3 0xc 0x1b 0x0 0x2
DEBUG:pymodbus.framer.socket_framer:Processing: 0x0 0x7 0x0 0x0 0x0 0x6 0x1 0x3 0xc 0x1b 0x0 0x2
DEBUG:pymodbus.factory:Factory Request[ReadHoldingRegistersRequest: 3]
DEBUG:pymodbus.datastore.remote:validate[3] 3099:2
DEBUG:pymodbus.transaction:Current transaction state - IDLE
DEBUG:pymodbus.transaction:Running transaction 1
DEBUG:pymodbus.transaction:SEND: 0x0 0x3 0xc 0x1b 0x0 0x2 0xb6 0x8d
DEBUG:pymodbus.client.sync:New Transaction state 'SENDING'
DEBUG:pymodbus.transaction:Changing transaction state from 'SENDING' to 'WAITING FOR REPLY'
DEBUG:pymodbus.transaction:Transaction failed. (Modbus Error: [Invalid Message] Incomplete message received, expected at least 2 bytes (0 received))
DEBUG:pymodbus.framer.rtu_framer:Frame - [] not ready
DEBUG:pymodbus.transaction:Getting transaction 0
DEBUG:pymodbus.transaction:Changing transaction state from 'PROCESSING REPLY' to 'TRANSACTION_COMPLETE'
ERROR:pymodbus.pdu:Exception Response(131, 3, IllegalAddress)
DEBUG:pymodbus.server.sync:send: [Exception Response(131, 3, IllegalAddress)]- 000700000003018302

gunner009
@gunner009
@dhoomakethu is there is other possible method
ujwalashirodkar21
@ujwalashirodkar21
@dhoomakethu checked out the link already...it says serial server not implemented.
gunner009
@gunner009
server is created but data forwarding is working
sorry Not working
dhoomakethu
@dhoomakethu
@ujwalashirodkar21 it is implemented as far as I know, the examples have the asynchronous serial server commented out
barisserbay
@barisserbay
Hi everyone. Is there any sample code for Modbus RTU. I'm working on ubuntu core and modbus energy analyzer. I want to read analyzers data with pymodbus. Thanks
dhoomakethu
@dhoomakethu
@barisserbay check the examples on the GitHub repo
barisserbay
@barisserbay
@dhoomakethu which example?
George-Cristian Bîrzan
@gcbirzan
@dhoomakethu You closed #495, but I don't see any commit about it.
Asad
@asadali84

Hi guys. Just a quick question on add_bits when it comes to the payload builder.
I want to write a row with [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] into the first register with big endian byte order. This is the code I use to build the payload:

builder = BinaryPayloadBuilder(byteorder=Endian.Big, wordorder=Endian.Little)
builder.add_bits([True] + [False] * 7)
builder.add_bits([False] * 8)
print(builder.to_registers())

The output is 256. This means that the left byte contains [0, 0, 0, 0, 0, 0, 0, 1] instead of [1, 0, 0, 0, 0, 0, 0, 0].
Was just curious why that was happening.

Tracking the payload builder further, it looks like this is something that the pack_bitstring in utilities.py does:

>>> from pymodbus.utilities import pack_bitstring
>>> pack_bitstring([True] + [False]*7)
b'\x01'

Still not sure why and would appreciate some input!

Asad
@asadali84
It kinda looks like it is treating the 0th element in the array as the LSB and the last element in the array as the MSB
dhoomakethu
@dhoomakethu
Play around with byteorder in BinaryPayloadBuilder .
Asad
@asadali84
The byte order won't affect this. This is the flipping of the bits within the byte.
In other words, byte order will change the above from \x0100 to \x0001 but within the byte why is it stored as [0, 0, 0, 0, 0, 0, 0, 1] and not [1, 0, 0, 0, 0, 0, 0, 0]
Martin Høy
@marhoy

I have a question about using a AsyncModbusSerialClient with an already running event loop. I've successfully run the async_asyncio_client.py example file which works fine for a AsyncModbusTCPClient.

But if I try to do the same with a AsyncModbusSerialClient (providing the loop as a parameter), I get this:
Traceback (most recent call last):
File "async_asyncio_serial_client.py", line 143, in <module>
run_with_already_running_loop()
File "async_asyncio_serial_client.py", line 115, in run_with_already_running_loop
baudrate=9600,
File "/home/pi/pyflexit/.venv/lib/python3.7/site-packages/pymodbus/client/asynchronous/serial.py", line 75, in new
yieldable = factory_class(framer=framer, port=port, **kwargs)
File "/home/pi/pyflexit/.venv/lib/python3.7/site-packages/pymodbus/client/asynchronous/factory/serial.py", line 106, in async_io_factory
loop.run_until_complete(coro)
File "/usr/lib/python3.7/asyncio/base_events.py", line 571, in run_until_complete
self.run_forever()
File "/usr/lib/python3.7/asyncio/base_events.py", line 526, in run_forever
raise RuntimeError('This event loop is already running')
RuntimeError: This event loop is already running

KuDeTa
@KuDeTa
Hello, i'm a total newb to pymodbus, and experimenting with reading oxygen data coming from our hospital system. At the moment the process is manual, and i figured i'd give it a shot. I have a unit sending MODBUS data over Ethernet. I've managed to recieve this data on a pymodbus server and it seems to be receiving appropriately. I'm a bit overwhelmed by the complexity and uncertain as to what comes next. I probably ought to read the spec. In the meantime could someone give me a pointer in how to decode and interrogate what i am receiving at the server. Server Syncronous Client logs:
KuDeTa
@KuDeTa
2020-04-20 18:56:01,176 Thread-50 DEBUG sync :46 Client Connected [192.168.0.240:1292] 2020-04-20 18:56:01,223 Thread-50 DEBUG sync :199 Handling data: 0x0 0x1 0x0 0x0 0x0 0x2b 0xff 0x10 0x0 0x1 0x0 0x12 0x24 0x0 0x4 0x0 0x0 0x0 0x7 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x4 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x5f 0x0 0x0 0x0 0x6 0x0 0x0 2020-04-20 18:56:01,223 Thread-50 DEBUG socket_framer :147 Processing: 0x0 0x1 0x0 0x0 0x0 0x2b 0xff 0x10 0x0 0x1 0x0 0x12 0x24 0x0 0x4 0x0 0x0 0x0 0x7 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x4 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x5f 0x0 0x0 0x0 0x6 0x0 0x0 2020-04-20 18:56:01,224 Thread-50 DEBUG factory :137 Factory Request[WriteMultipleRegistersRequest: 16] 2020-04-20 18:56:01,224 Thread-50 DEBUG context :64 validate: fc-[16] address-2: count-18 2020-04-20 18:56:01,225 Thread-50 DEBUG context :90 setValues[16] 2:18 2020-04-20 18:56:01,225 Thread-50 DEBUG sync :229 send: [WriteMultipleRegisterResponse (1,18)]- b'000100000006ff1000010012' 2020-04-20 18:56:01,275 Thread-50 DEBUG sync :199 Handling data: 2020-04-20 18:56:01,276 Thread-50 DEBUG socket_framer :147 Processing: 2020-04-20 18:56:01,276 Thread-50 DEBUG sync :54 Client Disconnected [192.168.0.240:1292]
dhoomakethu
@dhoomakethu
@KuDeTa Are you trying to read from a real modbus unit and write it to server ? Why do you want to do that ? You can use a client to read the data and process it for your use case.
@marhoy The Asyncio clients are still in beta stage and are prone to errors. Please raise an issue I will take a look when I get some time
nat-kh
@nat-kh
Hello everyone! I want to write or read bits from my Controller. So I set the Controller as a Serialserver (with RS232) using the examples and I tried connecting it with the Client (TCP Client, "127.0.0.1")… I tried different things, before coming to this conclusion and at one Point I didn't have any Errors and it went smoothely. But most of the time I seem to get this error "Connection to (127.0.0.1, 5020) failed: [WinError 10061]"
does anybody have any idea as to what the Problem might be, what can I do to fix this?
Is my Approach to what the Server is and what Clients is wrong in the first place?