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:51] – [Example] mfranklin | logicpython:cubloc_api:setmodbus [2026/04/14 05:10] (current) – [Example] mfranklin | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== SetModbus ====== | ====== SetModbus ====== | ||
| - | Start the LogicPython Modbus RTU slave worker using a pre-opened UART '' | + | Configure UART settings and start the LogicPython Modbus RTU slave process. |
| - | + | ||
| - | ===== Syntax ===== | + | |
| - | + | ||
| - | <code python> | + | |
| - | from cubloc import SetModbus | + | |
| - | + | ||
| - | SetModbus(channel: | + | |
| - | baudRate: int, | + | |
| - | protocol: int, | + | |
| - | recvSize: int, | + | |
| - | sendSize: int, | + | |
| - | slaveAddress: | + | |
| - | coils: object, | + | |
| - | discreteInputs: | + | |
| - | inputRegisters: | + | |
| - | holdingRegisters: | + | |
| - | memoryLock: object, | + | |
| - | returnInterval: | + | |
| - | </ | + | |
| - | + | ||
| - | ===== Parameters ===== | + | |
| - | + | ||
| - | * **channel**: | + | |
| - | * **slaveAddress**: | + | |
| - | * **coils**: Writable bit-packed coil buffer (8 '' | + | |
| - | * **discreteInputs**: | + | |
| - | * **inputRegisters**: | + | |
| - | * **holdingRegisters**: | + | |
| - | * **memoryLock**: | + | |
| - | * **returnInterval**: | + | |
| - | + | ||
| - | ===== Exceptions ===== | + | |
| - | + | ||
| - | * [[https:// | + | |
| - | * [[https:// | + | |
| - | * [[https:// | + | |
| - | + | ||
| - | ====== SetModbus ====== | + | |
| - | + | ||
| - | Configure UART settings and start the LogicPython Modbus RTU slave worker. | + | |
| ===== Syntax ===== | ===== Syntax ===== | ||
| Line 66: | Line 26: | ||
| * **channel**: | * **channel**: | ||
| * **baudRate**: | * **baudRate**: | ||
| - | * **protocol**: | + | * **protocol**: |
| - | * **recvSize**: | + | * **recvSize**: |
| - | * **sendSize**: | + | * **sendSize**: |
| * **slaveAddress**: | * **slaveAddress**: | ||
| * **coils**: Writable bit-packed coil buffer (8 '' | * **coils**: Writable bit-packed coil buffer (8 '' | ||
| Line 75: | 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 94: | Line 69: | ||
| INPUT_PINS | INPUT_PINS | ||
| ADC_CHANS | ADC_CHANS | ||
| + | |||
| + | for pin in OUTPUT_PINS: | ||
| + | Output(pin) | ||
| + | Low(pin) | ||
| + | for pin in INPUT_PINS: | ||
| + | Input(pin) | ||
| + | |||
| + | # 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) | coils = bytearray(1) | ||
| Line 101: | Line 89: | ||
| mem_lock | mem_lock | ||
| - | for pin in OUTPUT_PINS: | + | SetModbus(UART_CHANNEL, |
| - | | + | |
| - | | + | |
| - | for pin in INPUT_PINS: | + | |
| - | | + | |
| - | + | | |
| - | SetModbus(0, | + | |
| while True: | while True: | ||