pythoncontrollermodbusmodbus-tcpminimalmodbus

python minimalmodbus protocol implementation for SMC LEC 6: write to multiple coils


minimalmodbus does not provide a way to set multiple coils at once. I cannot find a workaround.

objective:

The modbus protocol description in the datasheet of the SMC LEC 6 controller, see link. I try to follow the directions from the example starting at page 7 by sending the listed modbus commands using the pyton library minimalmodbus.

I want to send the command 01 0F 00 10 00 08 01 02 BE 97 but do not find a way to do this with minimalmodbus. There is not implementation of function code 15 (OF).

What I tried to do:

I reasoned as follows:

I thought this could work by setting these positions all separately:

logging.debug('write step')
step_address = int('0010', 16)

bin_2 = [0] * 8
bin_2[6] = 1

for pos, val in zip(list(range(8)), bin_2):
    contr.write_bit(step_address + pos, val)
time.sleep(WAIT_TIME)
contr.write_bit(flags['DRIVE'], 1); time.sleep(WAIT_TIME * 5)

The actuator does not move though...

Thanks, Jan


Solution

  • I was able to send the command in question by going a bit deeper in the minimal modbus class and sending the raw payload to the device:

    00 10 00 08 01 02

    contr._performCommand(15, '\x00\x10\x00\x08\01\02')
    contr.write_bit(flags['DRIVE'], 1)
    time.sleep(WAIT_TIME * 3)
    contr.write_bit(flags['DRIVE'], 0)