Modbus Multi Coils Write


kanber

Recommended Posts

Hi,

I have one device that need to sent multi coil write function( 0F hex, 15 ascii code),

I can sent the date with monitor to write "\x01\x0F\x01\x40\x00\x08\x01\x03\xBE\x8A" and it is working.

Is there any option to do wtih channels?

I tried also Device.mydevice.write("\x01\x0F\x01\x40\x00\x08\x01\x03\xBE\x8A"). but not work also,

I also attached fan.jpg file which is showing Coil W/R table.

I need to read also this channels

Link to comment
Share on other sites

A force coil channel allows you to set or clear a single coil bit. It does not allow you to set more than one bit per query. If you want to set an entire word worth of bits you have to use the forceCoil() function from a sequence. DAQFactory treats coils and input status as individual bits. For 99.9% of applications, this is what customers want, and is most convenient. For cases where you really need to set multiple bits at once, there is the forceCoil() function. Note that for reading input or coil status, you can use channels and DAQFactory will automatically block the channels. It just won't block for outputs when using output channels.

Link to comment
Share on other sites

Hello,

thanks for answer. but I tried with forcecoil function like below

switch

case(butonno == 1)

device.VRVMod.ForceCoil(1,168,{1,0,0,0,0,0,0,0})

case(butonno == 2)

device.VRVMod.ForceCoil(1,168,{0,1,0,0,0,0,0,0})

case(butonno == 3)

device.VRVMod.ForceCoil(1,168,{1,1,0,0,0,0,0,0})

case(butonno == 4)

device.VRVMod.ForceCoil(1,168,{0,0,1,0,0,0,0,0})

case(butonno == 5)

device.VRVMod.ForceCoil(1,168,{1,0,1,0,0,0,0,0})

case(butonno == 6)

device.VRVMod.ForceCoil(1,168,{0,1,1,0,0,0,0,0})

case(butonno == 7)

device.VRVMod.ForceCoil(1,168,{1,1,1,0,0,0,0,0})

endcase

but there is check sum problem I think. I didnt try with device yet. I dont know it will work or not?

Tx: \x01\x0F\x00\xA8\x00\x08\x01\x01^\x8D //ıt should be 5E8D Can it be In char? why it is not showing in hex?

Tx: \x01\x0F\x00\xA8\x00\x08\x01\x02\x1E\x8C //OK

Tx: \x01\x0F\x00\xA8\x00\x08\x01\x03\xDFL //ıt should be DF4C Can it be In char? why it is not showing in hex?

Tx: \x01\x0F\x00\xA8\x00\x08\x01\x04\x9E\x8E //OK

Tx: \x01\x0F\x00\xA8\x00\x08\x01\x05_N //ıt should be 5F4E Can it be In char? why it is not showing in hex?

Tx: \x01\x0F\x00\xA8\x00\x08\x01\x06\x1FO //ıt should be 1F4F Can it be In char? why it is not showing in hex?

Tx: \x01\x0F\x00\xA8\x00\x08\x01\x07\xDE\x8F //OK

Link to comment
Share on other sites

By default the DAQFactory monitor shows any byte between 32 and 127 as its ASCII equivilent. That's why 5E is showing up as ^, and 4C as L, etc. There is an option in the monitor that forces all characters to display in their numeric form (hex or decimal depending on a different setting).

Link to comment
Share on other sites

Achhhh -- I was looking at the array and thinking "MSB on the left, LSB on the right" like when you display a binary number. D'oh!

I didn't think of subsetting the To.Bit() return column-wise on the fly instead of using Transpose(). Cool!

Link to comment
Share on other sites

Now, (To.Bit(buttono))[][0,7] will still return the bits as a 2D array; {{1,1,1,0,0,0,0,0}} rather than {1,1,1,0,0,0,0,0}

Will that work OK in the Modbus call? If so, that will simplify some things for me. For some reason I thought the data array had to be 1D.

Link to comment
Share on other sites

Interesting perspective! I would have said, since it's in the second dimension, it's by definition a 2D array, even though all the values fall in one column.

Good to know about the Modbus call, though. I think there's been a number of times I demoted something to 1D to stick in a Modbus call just because I assumed I had to. This should save a step in that scenario.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.