Hello,
I am trying to integrate a microwave generator for remote operation. The device support Modbus RTU over RS232 port. I have been able to perform many operations using my code except "write to coil". I am not sure how to set address for this Function code. The device manual (image attached) specifies the Modbus address as 2, but I don't know how to set bit address. Also attached is the screenshot of Modbus scanner Chipkin if it helps.
Single bits or coils must have a unique address, so this is supposed to be addressed as 1 byte, means WSR (write single register) in terms of ModBus.
Read Coil Registers and do a bit operation.
Modbus will return a data of U16 ( Use Number to Boolean array and index the value of 6th Element)
So what should be its address? If I write a register at address '2', will it not write to all the 8 bits whereas I want to turn only bit 6 at address 2 as HIGH?
What makes you think this is a coil? The manual (at least from that image) is not clear about what you actually need to do (for instance, it says that this is at address 2 and then it says that start mode is also at address 2). You might want to check if the manual has more details.
My guess would be that this is not a coil, but rather a holding register, and that you are expected to set its value using the bits. This is not certain (registers are 16 bits, as mentioned, and the manual only shows 8 bits), but would make more sense.
There is a Modbus command for toggling single bits in registers (command 22), but this is not implemented in many APIs. As mentioned, you can read the value of the register, use bitwise operations to modify a single bit (see the attached VI and play with different operations) and then write it back.
Like I already wrote, it's mostly likely a normal holding register of 16 bit length where 8 bits are used to perform actions. Those cannot be addressed as coils, so the method would be to read the register first, change the bit(s) you want and then write back.
Performing "Write single register" actually worked. Considering it as 8-bit register, I have written 64 (01000000 in binary) and it turned the generator ON.
For other future readers, I had tried "Write single coil", "write multiple coils" with numerous address setting like '2', '2.6', '8' (2 as base address, 6 as offset) and so on. But none of them worked in my case. It helps if the manual clearly specify the addressing mode (coil or register).
Thanks everyone for contribution.