Cicode Tagwrite Function

I am not a visual basic or Cicode expert and so am looking for someone to help (hold my hand). I have a Scada system running Citect Scada 6.1 service pack B. This system is connected to an OPC server, and two Allen Bradely PLC's. I would like help writing some Cicode that will take values from a tag and write them to another tag automatically anytime the project is running.

Basically I have values coming from the OPC server that I want written to registers in the Allen Bradley PLC.

This seems like simple task, except that I have little to no experience with VB code writing. I have played with the "Tagwrite" function some, but am hoping someone out there might be able to whip me out a quick bit of code to do what I want, and save me the pain!!!

Please help.
 
P

Patrick Beckett

Firstly, do not bother with VB. Citect has its own language which is more tightly integrated - Cicode.

You need two functions and the tags being available in the tag database.
e.g ReadTag is the tag in the OPC Server you want to read.
WriteTag is the tag in the AB you want to update.

The first task is triggered on startup which starts a new task to run the looping function.

FUNCTION
StartUpFunction()

INT hMyTask;

// Start new task which will run forever for transferring data all the time
hMyTask = TaskNew("fnDoThis","",0);

END

The next task runs all the time and transfers the value of the ReadTag to WriteTag.

FUNCTION fnDoThis;

//never stop the loop
While 1 DO
//update the first tag
WriteTag=ReadTag;
//place any other tags here
//go to sleep for a second, to prevent overloading the PC and comms
Sleep(1);
//go back to the start of the loop
END;

//end of function
END

Providing the Startup Function is triggered by Citect when starting (part of the Computer Setup Wizard), then this will read the value of one tag and update the other every second.

I use a derivative of this all the time in my projects.

Regards
Patrick
 
P

Patrick Beckett

Sorry, having looked at my post again, I realise that it would work on version 7 not version 6.10

The fnDoThis should include

<pre>ReRead(1);</pre>

i.e.
<pre>
while 1 do
<b>ReRead(1);</b>
WriteTag=ReadTag;
sleep(1);
end;
</pre>

Sorry about that.

Patrick
 
Patrick, thank you very much for the reply. I already had the tag "read" by virtue of creating the variable tag coming from the OPC server. I used your code for a TagWrite, While (1) DO and sleep for the loop function and it works great.

Thanks very much for helping me along!
 
Top