0

I am communicating with an irradiation sensor using minimalmodbus in Python 3.x. I can stablish a communication and read the registers of the sensor. The Baudrate of the sensor is 9600 but I want to change it to 38400.

The datasheet of the sensor says that it can be done by using the function code 0x46 and the subfunction 06.

datasheet

I've found that minimalmodbus only uses function codes 1,2,3,4,5,6,15 and 16, and I haven't found any possibility to use sub function.

Is there any option for me to change the baudrate or should I change minimalmodbus for another library as pyModbus?

Dani
  • 21
  • 6

1 Answers1

0

Looking at the Minimalmodbus documentation, you can "extend" it to handle more function codes by using the _performCommand() function. The documentation says that it will take care of the CRC generation.

Link: https://minimalmodbus.readthedocs.io/en/master/develop.html#extending-minimalmodbus

I did a quick search and it looks like you are using a Tamb485 sensor. Based on that documentation, To set the BAUD rate to 38400 and the parity/stop bits (both are set at the same time) to 8E1 on a device you would do:

_performCommand(0x46, '0x05,0x04,0x02')

0x46 - function code

0x05 - sub function code
0x04 - baud rate 38400
0x02 - parity/stop bits 8E1
Marker
  • 972
  • 6
  • 9
  • I just used _performCommand(70, '\x06\x04\x00') and it worked fine! Thanks – Dani Feb 13 '19 at 14:53
  • Great, I see that I didn't look close enough at that function to see that the address was implied and the function code was a parameter, I'll update my answer. Glad it pointed you in the right direction anyway. – Marker Feb 13 '19 at 15:07