Setting two seperate bits with one data point...
-
Hey Guys, I'm trying to work out how to set two bits in a solar regulator to switch an output via MODBUS over IP using only one data point, or setting two data points simultaneously.
Here is an excerpt from the solar regulator manufacturer.Register 4165 can be used to enable and disable both AUX1 and AUX2. It is split in half, the lower 8-bits control AUX1 the upper 8 bits control AUX2. Setting bits 6&7 will effect AUX 1 and bits 14&15 will control AUX 2. Setting these bits to 00 (decimal 0) will set the AUX OUTPUT LOW (0v) Setting these bits to 01 (decimal 1) will enable the AUX port function (PV ON HIGH, WASTE NOT, etc). Setting these bits to 10 (decimal 2) will set the AUX output HIGH (12v). Setting these bits to 11 (decimal 3) is undefined and has no guaranteed functionality (it could do anything including turning into a blowfish).
What I need to do is have a clickable button on my graphical view which when clicked, changes the LED to Green Flashing and sets bit 6&7 to 10 to switch ON
Then to switch off, I need to have the button go red solid and set bits 6&7 to 00, then 1 second later, set to 01 OFF -
I am only a Mango beginner, but I think you could:
- Set up a modbus-tcp binary datapoint to set bit 6 of register 4165, and another one to set bit 7
- Set up a meta data source and add a binary datapoint to it called 'Aux'
- Set up a scripting data source and add your two modbus points and the meta datapoint to its context
- Have the script examine the meta datapoint and set your two points accordingly
I have never used the scripting data source myself, maybe you can update the script itself without having to create the meta datapoint.
I never worked out how to make a clickable button/toggle in graphical views, but check this thread:
http://forum.infiniteautomation.com/forum/posts/list/97.pageI think all this would be simpler to do in DGLux, as you could create the button and set data actions for it. There is a DGLux mobile app which makes bringing this up this on your phone/tablet very convenient.
-
I'm not sure you want to set the bits individually, but I am somewhat of a modbus beginner. I would think you would want to find the right data type (probably 4 or 2 byte integer) and set it using bitshift's and or's. Something like
if( turn_on ) control.set( 1 << 6 ); //0b01000000 else control.set( 1 << 5 ); //0b00100000
To set more bits, use a bitwise 'or' ( | ) wherever your logic is being done (actionscript in DGLux, a scripting data source, or perhaps in the view itself), i.e. control.set(1 << 6 | 1 << 5);
I agree with Jeremy that this would probably be easier to work out in DGLux than with a graphical view, and I appreciate his answering!
-
Thanks guys I'll see if I can get that to work.
Cheers
Dan