08-14-2023 07:35 AM
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.
08-14-2023 07:39 AM - edited 08-14-2023 07:45 AM
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.
08-14-2023 09:08 AM
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)
08-15-2023 02:11 AM
He wants to write coils.
08-15-2023 11:09 PM
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?
08-16-2023 02:23 AM
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.
08-16-2023 02:35 AM
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.
08-16-2023 07:15 AM
Try runnning this example , Change CoIls Address to 1 (It starts from 0).,
08-16-2023 09:02 AM
@LVNinja wrote:
Try runnning this example , Change CoIls Address to 1 (It starts from 0).,
??? - you cannot change a coil address, you can only address a coil if defined as coil at a specific address. Which the topic starter already tried and which failed.
08-16-2023 11:13 PM - edited 08-16-2023 11:22 PM
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.