LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Modbus Write single coil not responding

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.1.pngGenerator modbus.jpg 

0 Kudos
Message 1 of 12
(2,536 Views)

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.

0 Kudos
Message 2 of 12
(2,533 Views)

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)

----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------
0 Kudos
Message 3 of 12
(2,507 Views)

He wants to write coils.

Message 4 of 12
(2,485 Views)

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?

0 Kudos
Message 5 of 12
(2,455 Views)

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.


___________________
Try to take over the world!
0 Kudos
Message 6 of 12
(2,440 Views)

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.

0 Kudos
Message 7 of 12
(2,437 Views)

Try runnning this example , Change CoIls Address to 1 (It starts from 0).,

 

LVNinja_0-1692188035571.png

 

LVNinja_1-1692188075280.png

 

 

0 Kudos
Message 8 of 12
(2,419 Views)

@LVNinja wrote:

Try runnning this example , Change CoIls Address to 1 (It starts from 0).,

 

LVNinja_0-1692188035571.png

 

LVNinja_1-1692188075280.png

 

 


??? - 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.

0 Kudos
Message 9 of 12
(2,411 Views)

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.

Message 10 of 12
(2,390 Views)