Applies To:
  • CitectSCADA 5.xx, 6.00

Summary:
I have used the Cicode example given in the help for ComOpen. I have modified this cicode slightly, so that it can read and write data to an ASCII Printer.
When I hard code a String to the buffer, it works fine:

sBuffer = "TEST";


But when I use cicode assignments like:

sBuffer = TagRead("VarTag");


It fails, and I get the a Cicode error 257 (Value is out of range).
I have checked to make sure VarTag has a valid value. What is causing this error and how do I fix it?

 

Solution:
The problem lies ultimately with timing, and also the position of the ComClose function. When you hardcode the sBuffer value in cicode, it is sent out the wire, before the ComClose function is called. But when you use Cicode assignment, it takes a little longer. When the ComClose function is called, the ComWrite function has not completed, and suffers interference. To resolve this problem, it is recommended to insert a SleepMS before the ComClose function is called.

It would actually be better practice to only open the Com port on startup, and close the com port on Shutdown.

Some example Cicode has been uploaded to the toolbox. It is recommended if you are experiencing problems writing your Com function, you take a look at this Cicode example.
 

Keywords:
cicode error 257, ComClose, ComWrite  

Attachments