ledbelly2142 Posted October 22, 2012 Share Posted October 22, 2012 I have a modbus registry value that is the status of 5 relays in bit representation... the bit values indicate the on/off stat of the relays in order (e.g. 1, 2, 3, 4 ,5). The variable value component reads the binary notation and converts it into a number, which I think is normal. So when some of the relays are on, I get a value of "9". How can I display the registry value in bit representation, and how can I make it useable for logging relay run time? I would like to log relay 1 runtime, relay 2 runtime, etc... Thanks Link to comment Share on other sites More sharing options...
AzeoTech Posted October 23, 2012 Share Posted October 23, 2012 Best bet is to create 5 test channels, one for each bit, then in the Modbus channel's event, put something like: private bits = to.bit(myChannel[0]) bitChannel0.addvalue(bits[0][0]) bitChannel1.addvalue(bits[0][1]) etc... Link to comment Share on other sites More sharing options...
ledbelly2142 Posted October 23, 2012 Author Share Posted October 23, 2012 I'm not doing something right. The bits are not accurate and some are -0... Here is what I have in the channel (channel=RelayStatus) event: private bits = to.Bit(RelayStatus[0]) Relay1.addvalue(bits[0][0]) Relay2.addvalue(bits[0][1]) Relay3.addvalue(bits[0][2]) Relay4.addvalue(bits[0][3]) Relay5.addvalue(bits[0][4]) I am think that the second [0] in the Relay.addvalue lines identifies the bit (sequentially) in the registry value. But I also thought that using [0][0] together was identifying a two dimensional array. Thanks Link to comment Share on other sites More sharing options...
ledbelly2142 Posted October 23, 2012 Author Share Posted October 23, 2012 Just reread the documentation, the bit order is from the LSB (least significant bit)... so the first relay (I think) should be Relay1.addvalue(bits[0][7]) Relay1.addvalue(bits[0][6]) but this does not work either. I have some formatting issue, the bit values seem random with -1, -0, 0, and 1. Link to comment Share on other sites More sharing options...
AzeoTech Posted October 23, 2012 Share Posted October 23, 2012 Actually, you want [0][0] because you want the LSB (right most). If you get random values between -1 and 1 it means you forgot to set the Timing of the Test channel to 0. Link to comment Share on other sites More sharing options...
ledbelly2142 Posted October 23, 2012 Author Share Posted October 23, 2012 That is right, my timing in the test channels were wrong. Thank you. So the [0][0] bit is LSB, would have taken me a while to figured that out. Cheers Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.