-1

I am trying to write data to DVP28SS2 controller using minimalmodbus in ASCII mode. I have received a response from the controller but it seems wrong. In particular bits, corresponding to slave address and the function code don't match them.

  • The request is: 3A 30 31 31 30 30 30 32 38 30 30 30 31 30 32 30 30 36 34 36 30 0D 0A (:01100028000102006460\r\n)
  • The response is: 3A 30 B1 39 30 30 B2 36 44 8D 0A (:0±900²6D\x8d\n)

The correct response for a request (as an example) should look like this: enter image description here

import minimalmodbus
import serial

D40 = 4096 + 40
instrument = minimalmodbus.Instrument(port = 'COM5',mode = 'ascii', slaveaddress = 1,  debug = True)  # port name, slave address (in decimal)

instrument.serial.baudrate = 9600        # Baud
instrument.serial.bytesize = 7
instrument.serial.parity   = serial.PARITY_EVEN
instrument.serial.stopbits = 1
instrument.serial.timeout  = 0.05         # seconds

## Write  ##
data_to_write = 100
instrument.write_register(registeraddress=D40, value=data_to_write,number_of_decimals=0)  

As a result I have received:

MinimalModbus debug mode. Create serial port COM5
MinimalModbus debug mode. Will write to instrument (expecting 17 bytes back): 3A 30 31 31 30 30 30 32 38 30 30 30 31 30 32 30 30 36 34 36 30 0D 0A (23 bytes)
MinimalModbus debug mode. Clearing serial buffers for port COM5
MinimalModbus debug mode. No sleep required before write. Time since previous read: 45037250.00 ms, minimum silent period: 4.01 ms.
Traceback (most recent call last):
  File "G:\Проекты\Python\Neurolumber_utils\utils\ModbusWriter.py", line 15, in <module>
    instrument.write_register(registeraddress=D40, value=data_to_write,number_of_decimals=0)  # Registernumber, value, number of decimals for storage
  File "C:\Users\Иван Малахов\AppData\Local\Programs\Python\Python39\lib\site-packages\minimalmodbus.py", line 550, in write_register
    self._generic_command(
  File "C:\Users\Иван Малахов\AppData\Local\Programs\Python\Python39\lib\site-packages\minimalmodbus.py", line 1245, in _generic_command
    payload_from_slave = self._perform_command(functioncode, payload_to_slave)
  File "C:\Users\Иван Малахов\AppData\Local\Programs\Python\Python39\lib\site-packages\minimalmodbus.py", line 1329, in _perform_command
    payload_from_slave = _extract_payload(
  File "C:\Users\Иван Малахов\AppData\Local\Programs\Python\Python39\lib\site-packages\minimalmodbus.py", line 1825, in _extract_payload
    raise InvalidResponseError(
minimalmodbus.InvalidResponseError: Did not find footer ('\r\n') as end of ASCII response. The plain response is: ':0±900²6D\x8d\n'
MinimalModbus debug mode. Response from instrument: 3A 30 B1 39 30 30 B2 36 44 8D 0A (11 bytes), roundtrip time: 0.1 ms. Timeout for reading: 50.0 ms.
Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109
  • Hello Ivan. Can you add a link pointing to the documentation for your PLC? What exactly are you trying to do writing to register `40`? Are you sure you are connecting to the right serial port with the right settings? – Marcos G. Dec 04 '22 at 15:41
  • Hello Marcos! Thank you for your comment! Here is the documentation of the the used PLC: https://filecenter.deltaww.com/Products/download/06/060301/Manual/DELTA_IA-PLC_DVP-PLC_PM_EN_20200605.pdf In my code I tried to write any value to any register, just for test I used 100. I am not sure about serial port settings but `instrument.serial.baudrate = 9600 ` is the only value at which I can receive any response from PLC. I varied other parameters and tried different combinations but nothing was changed in the response. – Ivan Malakhov Dec 05 '22 at 08:41
  • 1
    Hello Ivan. Thanks for the manual. Can you include the program you are running on your PLC? It should be something similar to what you have on page 407 of the manual. Your PLC won't be answering to any Modbus queries unless you program it to do so. Based on the error you are getting I think you might be setting it up to work in RTU mode instead of ASCII. – Marcos G. Dec 05 '22 at 10:48
  • Hello @MarcosG. Thank you for the previous advice, i included in the PLC program the code for connection via COM port with rs485 (from the Delta Library of ispSoft) . The image is attached by the link below. https://drive.google.com/file/d/13ZOMWevbMuhSOfvfl6GHLVIOuiO7rOPg/view?usp=sharing When I run the code I have received a response from looks almost like the expected but as if some symbols in hex form of bits were replaced. Request: 3A 30 31 31 30 31 30 32 39 30 30 30 31 30 32 30 33 45 44 43 33 0D 0A Response: 3A 30 B1 B1 30 B1 30 B2 39 30 30 30 B1 42 35 8D 0A – Ivan Malakhov Dec 07 '22 at 17:29
  • At the same time I check the register in which I tried to write a value. It was changed as I have wrote in code with minimalmodbus. @MarcosG. – Ivan Malakhov Dec 07 '22 at 17:34
  • Looks like noise is getting into your wires somehow. Are you using a three-wire connection between your serial port and your PLC? Are you connecting both to the same power supply? What kind of serial port adaptor are you using on your computer? Does it have a GND connection in addition to A/B? – Marcos G. Dec 08 '22 at 08:01
  • I am using an ESPADA adapter which only has 2 pins "A" and "B". The computer and controller power supply are connected to the same outlet. Colleagues told me that the controller that I use has problems with the ASCII standard. When I changed the mode to "RTU" as you suggested, everything worked. Thank you! I should notice that I used register D40 = 4096+40 from the very beginning. – Ivan Malakhov Dec 26 '22 at 08:24

1 Answers1

1

Colleagues told me that the controller that I use has problems with the ASCII standard. When I changed the mode to "RTU", everything worked.