Applies To:
  • CitectSCADA 3.4, 4.2, 5.0

Summary:
I have a need to get data from a TCP-enabled computer (UNIX....) and have a simple TCP/IP server on this computer that can serve the information that I want. What is a simple means to get it? 

Solution:
This must be done on an IOServer, and you should define an IODevice that you disable at startup.

You can use the ComRead, ComWrite function to talk to a TCP port. Install service pack D for version 3.4/4.2 or later, OR use version 5.0.  Define:

Boards

Board Name: TCP
Board Type: TCPIP
Address: 0

Ports

Board Name: TCP
Port Name: PORT1
Special Opt: -iaaa.bbb.ccc.ddd -pnn -a -T

where aaa.bbb.ccc.ddd is the IP address of the server
nn is the port number on the server
-T specifies TCP
or you can use -U for UDP

Then use the following Cicode functions:

ComOpen(hPort, "PORT1", 0); // to open the port
ComRead(hPort, Buffer, len, 0); // to read into a buffer of size len
ComWrite(hPort, Buffer, len, 0); // to write from a buffer len characters
ComClose(hPort); // to close the port

For example, to access a persons account information on a UNIX server, use port 79 in the ports form, and then use the following Cicode

STRING Buffer;
FUNCTION
My_finger()

INT len;
STRING TXT = "svend^n";
hPort = ComOpen("PORT1", 0);
IF hPort > 0 THEN

SleepMS(200); // give time for port to finish connect
len = StrLength(TXT);
error = ComWrite(hPort, TXT, len, 0);
len = 127;
error = ComRead(hPort, Buffer, len, 0);
message("read", "#" + Buffer + "#", 0);
ComClose(hPort);

END

END

 

Keywords:
 

Attachments