This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| logicpython:cubloc_api:setmodbus [2026/04/14 04:54] – [Parameters] mfranklin | logicpython:cubloc_api:setmodbus [2026/04/14 05:10] (current) – [Example] mfranklin | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== SetModbus ====== | ====== SetModbus ====== | ||
| - | Configure UART settings and start the LogicPython Modbus RTU slave worker. | + | Configure UART settings and start the LogicPython Modbus RTU slave process. |
| ===== Syntax ===== | ===== Syntax ===== | ||
| Line 26: | Line 26: | ||
| * **channel**: | * **channel**: | ||
| * **baudRate**: | * **baudRate**: | ||
| - | * **protocol**: | + | * **protocol**: |
| * **recvSize**: | * **recvSize**: | ||
| * **sendSize**: | * **sendSize**: | ||
| Line 35: | Line 35: | ||
| * **holdingRegisters**: | * **holdingRegisters**: | ||
| * **memoryLock**: | * **memoryLock**: | ||
| - | * **returnInterval**: | + | * **returnInterval**: |
| + | |||
| + | '' | ||
| + | |||
| + | ^ Field ^ Bits ^ Meaning ^ | ||
| + | | Data bits | 1..0 | 00=5 bits, 01=6 bits, 10=7 bits, 11=8 bits | | ||
| + | | Stop bits | 2 | 0=1 stop bit, 1=2 stop bits | | ||
| + | | Parity | 4..3 | 00=None, 10=Even, 11=Odd (01 is reserved and raises '' | ||
| + | |||
| + | Common '' | ||
| + | |||
| + | ^ protocol ^ Frame format ^ | ||
| + | | 3 | 8N1 | | ||
| + | | 11 | 8E1 | | ||
| + | | 19 | 8O1 | | ||
| + | | 7 | 8N2 | | ||
| ===== Exceptions ===== | ===== Exceptions ===== | ||
| Line 54: | Line 69: | ||
| INPUT_PINS | INPUT_PINS | ||
| ADC_CHANS | ADC_CHANS | ||
| - | |||
| - | coils = bytearray(1) | ||
| - | discrete_inputs = bytearray(1) | ||
| - | input_regs | ||
| - | holding_regs | ||
| - | mem_lock | ||
| for pin in OUTPUT_PINS: | for pin in OUTPUT_PINS: | ||
| Line 67: | Line 76: | ||
| Input(pin) | Input(pin) | ||
| - | SetModbus(0, 9600, 3, 64, 64, 1, coils, discrete_inputs, | + | # Configure and start the Modbus RTU slave process |
| + | UART_CHANNEL = 0 | ||
| + | BAUD_RATE = 115200 | ||
| + | PROTOCOL = 3 # 8N1 | ||
| + | BUFFER_SIZE = 64 | ||
| + | SLAVE_ADDRESS = 1 | ||
| + | |||
| + | coils = bytearray(1) | ||
| + | discrete_inputs = bytearray(1) | ||
| + | input_regs | ||
| + | holding_regs | ||
| + | mem_lock | ||
| + | |||
| + | SetModbus(UART_CHANNEL, | ||
| + | BAUD_RATE, | ||
| + | PROTOCOL, | ||
| + | BUFFER_SIZE, | ||
| + | BUFFER_SIZE, | ||
| + | SLAVE_ADDRESS, | ||
| + | | ||
| while True: | while True: | ||