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.
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)
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:
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.
Colleagues told me that the controller that I use has problems with the ASCII standard. When I changed the mode to "RTU", everything worked.