Programming Cai WebControl PLC

Thank you Lou Apo and CAI !

I have tried the counter, and seems to work. I have changed CS to CM when it suited my aplication better.
A question, can I use RAM1 insted off VAR1 ?
I would like to save the VAR for importent things that I want to see in the GUI.

I think I have to get my hands on the latest HW version :)
(I dont have the latest HW with CTS)

-CAI....any news on the new 32 bit WebControl ?
It would be nice with a data sheet and time of delivery.

/Staffan

Thanks for your question. WebControl32 is still under development. Although most functions are working, we are adding a wifi feature to the WebControl32, so that user can use regular NIC configure the board, then switch to wifi mode to communicate in wifi. We hope in a month or two, we can have limited qty beta boards that funcitoning well.

Like WebControl8, we will continue add funcitons and features to WebControl32 once it is released. WebControl8 will be continuously manufactured and sold and supported.
 
Hi Lou,
A customer who wrote his PLC program for controlling certain things. However, his installation environment is different from one to the other. Instead of changing the PLC code, he rather to have tunnable parameters to set. (big house vs. small house, dark beer or light beer, etc) So we added four 32bit signed INT in the "general" screen. User can enter values there and being used in its PLC logic. If the PLC code is for one time use, it probably does not need to use UROM1..4. (VAR1...8 value is assigned in PLC code, they will not keep previous value after restart.) In the PLC logic, UROM1...4 is read only.

CTS is automatically based on current time minus seconds from 1970 to 2000. The reason for doing that is that all the variables is signed 32 bit INT. If we just use total seconds from 1970, by the time 2038, the firmware will be no good. By minus the seconds since 1/1/2000, the firmwre will be able to continue work through 2068. If you don't use NTP, the clock could drift, unless you use DS2417 real time clock chip attached to 1-wire bus. (DS2417 real time clock support added in firmware 3.2.9). No matter what, CTS is based on your clock setting. If you set the clock to 1970, you will get CTS negative number and increasing toward positive.

CAI Support

Thanks for the info. But, when CAI is booted, what will the clock be? If you look at the program I wrote, it will set ram1 to cs at start up. From there on, it requires that cs ticks off one at a time. If it were to jump forward more than 1 second, or backward any amount, the program would cease to function properly.

So

1) where does the cs value come from when the unit is first booted. It has no battery so I would think the clock would be lost during a power outage. Perhaps there is a capacitor that keeps the clock running for short periods?
2) when the clock checks the ntp server, I assume it could adjust backwards or forwards by more than one second?

Also, could you tell me what cgi command to use to set a variable?

I have tried myaddress/api/setvar.cgi? followed by lots of combos by I can't seem to figure out the syntax. I believe that "setvar" is a real address on the cai since it returns "error" instead of page not found.
 
Thanks for your question.  WebControl32 is still under development. Although most functions are working, we are adding a wifi feature to the WebControl32, so that user can use regular NIC configure the board, then switch to wifi mode to communicate in wifi.   We hope in a month or two, we can have limited qty beta boards that funcitoning well.

Like WebControl8,  we will continue add funcitons and features to WebControl32 once it is released. WebControl8 will be continuously manufactured and sold and supported.
Thank you CAI, it looks very intresting. Without knowing what funktions the WebControl32 have,I would like to see a function that makes it possible to read/write to fictive I/O:s from onecontroller to another. I hope you with my poor english understand what I talk about.I wish you all a Happy New Year !
 
To manually set a VAR value from outside:

http://192.168.1.15/api/setvar.cgi?varid=1&value=23456789

Found here: http://cainetworks.com/products/webcontrol/webcontrol-faq.html
 
Thanks for the info. But, when CAI is booted, what will the clock be? If you look at the program I wrote, it will set ram1 to cs at start up. From there on, it requires that cs ticks off one at a time. If it were to jump forward more than 1 second, or backward any amount, the program would cease to function properly.

So

1) where does the cs value come from when the unit is first booted. It has no battery so I would think the clock would be lost during a power outage. Perhaps there is a capacitor that keeps the clock running for short periods?
2) when the clock checks the ntp server, I assume it could adjust backwards or forwards by more than one second?

Lou,

Very good quesiton! When WebControl boot up, it will first sets its clock to a hard coded time value in 2010, which is the clock you see if the board boot up with no Internet available. Then it will immediately reach to time server for getting current clock. or if local time keep DS2417 chip for currecnt clock. While waiting the clock updated, PLC code could start running already.

If the logic is critically depending on the time sequence, please make sure add some logic to make sure the clock is already updated. For example check if year is 2012, if not, goto a label looping.
 
Lou,
Very good quesiton! When WebControl boot up, it will first sets its clock to a hard coded time value in 2010, which is the clock you see if the board boot up with no Internet available. Then it will immediately reach to time server for getting current clock. or if local time keep DS2417 chip for currecnt clock. While waiting the clock updated, PLC code could start running already.
If the logic is critically depending on the time sequence, please make sure add some logic to make sure the clock is already updated. For example check if year is 2012, if not, goto a label looping.

Would it be possible to see example code from CAI for this check 2012 (or later) function?

Marty in SC
 
Hello,

My first post here. I was the webcontrol user that requested the features present in 03.02.11 and my new board just arrived with them today. Easier to buy a new board with the firmware rather than send out my existing board that is in a production system, of course it will still take a while to swap the board in and out.

The new features work very nicely. I initially requested the CTS because I want to be able to have things happen after a certain time or not happen. For example I want to run a pump to recirculate every X seconds, but if it just ran due to some other need I don't need to run it. I also don't want to run something with a compressor if it was just running within the last X seconds. I did some quick math (might be off) and it looks like the CTS is since 3/22/2000. As far as I'm concerned I don't care how it relates to a fixed time, only counting elapsed time.

The UROM variables are setable via the general web interface and are readable via the PLC code. This will be really useful for people that want to use this as a thermostat and want to change the temp every once in a while and not rewrite code (and have it survive a restart)

I have been working on perl code to control the board and I am using it explicitly for my uses. My big motivation for doing it was template/variables in the PLC code without having to do multiple steps. If people are interested I will release this code publicly when it is more complete.

The way I program my board now is by editing a text file (call it fermcontroller.plc), then running 'caiwebcontrol plcsetcode fermcontroller.plc'. My script compiles the code and transfers it to the unit, it performs the same error checking the web interface does and will abort if there is an error.

Following is a snippit from my fermcontroller.plc. What I really love about this is the variable subsitution as well as being able to include comments.

$GLYCOLSETVAR = VAR4


$GLYCOLTEMP = T4
$GLYCOLTEMPSTATE = TS4
$GLYCOLRETURNTEMP = T5
$GLYCOLRETURNTEMPSTATE = TS5
$GLYCOLPUMPOP = OP3
$GLYCOLCOOLOP = OP5
$GLYCOLCOOLDIFF = 30 # tenths of degrees differential for glycol cooling

CHKGLYCOL:
SET $SUBPARAM1 EM2 # Set param to EM2 which is "bad sensor" message

# SET $DEBUGVAR1 4 # Set $TEMPVAR1 so we known which sensor is "bad"
CZ $GLYCOLTEMPSTATE ALERT # If temp sensor state is 0 (bad sensor) send alert

BZ $GLYCOLTEMPSTATE CLRGLYCOL # If temp sensor state is 0 (bad sensor) stop controlling

# SET $DEBUGVAR1 5 # Set $TEMPVAR1 so we known which sensor is "bad"
CZ $GLYCOLRETURNTEMPSTATE ALERT # If glycol return sensor is 0 (bad sensor) then alert, but don't stop controlling

TSTEQ $GLYCOLSETVAR $FVDISABLED
GOTO CLRGLYCOL

#TODO When seconds since epoch is available check last time
#compressor was run so we dont run too often

#We never step glycol, but we do use differential to set temp
ADD $GLYCOLSETVAR $GLYCOLCOOLDIFF $TEMPVAR1
TSTGT $GLYCOLTEMP $TEMPVAR1
SET $GLYCOLCOOLOP 1 # Cool on

TSTLE $GLYCOLTEMP $GLYCOLSETVAR
SET $GLYCOLCOOLOP 0 # Cool off

SET $SUBPARAM1 0 # Unset $SUBPARAM1
RET
 
Tried to edit my post, but maybe I can't because I'm new here. I forgot something.

The UROM variables are not visible in the getall.cgi XML, but I have requested this as a feature. Once I move to using this new code I'll have to make two requests in order to retrieve all the data to graph it.
 
Nice work. Writing the code using named variables instead of 1, 2, 3 etc would be a great help. I can't tell you how many times I have been like "what the heck number was I using for that again?".

Of course with CAI having so few variables, I tend to reuse variables as the code flows from top to bottum, but I could always make a compound name or something.

By the way, what are you running there? Chilling a beer line?
 
By the way, what are you running there? Chilling a beer line?

This system is controlling a homemade glycol chiller (modified window shaker cooling propylene glycol) and 2 temperature controlled conical beer fermenters. Each fermenter has a solenoid going to a coil to provide glycol for chilling as well as flexwrap heat tape around each one for heating. These are in my garage so most of the time now it is heating unless I need to crash the temperature down. In the summer I won't be using the heating at all and I'll get to see if my chiller can keep up.

When I started writing the PLC code for this I quickly got frustrated with how much I had to keep looking at my notes, so I decided to go down this path and make it a lot easier. Granted when everything is working perfectly I likely won't ever need to change the code again, but if I need to go back later to figure something out at least I've got comments

This is a ton easier to read:

CHKPUMP:
# TODO Add some time check to cycle the pump every once in a while to recirculate the tank/line
ADD $FV1COOLOP $FV2COOLOP $TEMPVAR1
ADD $TEMPVAR1 $PUMPSWITCH $TEMPVAR1
ADD $TEMPVAR1 $GLYCOLCOOLOP $TEMPVAR1

TSTGT $TEMPVAR1 0 $GLYCOLPUMPOP
NOP
RET

Than this:

CHKPUMP:
ADD OP7 OP6 RAM6
ADD RAM6 IP8 RAM6
ADD RAM6 OP5 RAM6
TSTGT RAM6 0 OP3
NOP
RET
 
Yup, that is a bunch easier. You must do some serious brewing there. I just buy pre-brewed kegs. I have a little mini glycol chiller I built for my line.

And man this forum is working like cropola tonight. It is not letting quick posts work at all and regular posts are slow as a snail.
 
Yup, that is a bunch easier. You must do some serious brewing there. I just buy pre-brewed kegs. I have a little mini glycol chiller I built for my line.

And man this forum is working like cropola tonight. It is not letting quick posts work at all and regular posts are slow as a snail.

I don't get to brew as much as I used to. Sometimes building the tools/toys is as much fun as using them.

BTW If anyone has a PLC firmware other than 03.02.09 or 03.02.11, I'd love to get a copy of everything on the webinterface so my module can support older firmwares. I'm mainly interested in the javascript code, but a recursive get on everything from the web interface will help out (zip or tar it up and send it to me). If the Opcodes, IOIdentifiers have changed it will be incompatible unless explicitly coded to support it.
 
Back
Top