CICODE Inter process communication, TCP/IP sockets.

tmithun

Member
Join Date
Nov 2021
Location
Bangalore, India
Posts
5
Hi, all :)),

I'm very new to CitectSCADA and Cicode programming, however have good programming experience in most major programming languages (Java, py, js, etc); so please excuse my ignorance 🤞🏻.

What I'm trying to do is send a string message to another application running on the same machine, hopefully through sockets.

I have a java application running on my Windows 10 that listens on a particular port for TCP/IP socket communication. I am running the Cicode script running on my local CitectSCADA V7.20 very similar to the ComOpen (https://johnwiltshire.com/citect-help/Subsystems/CicodeReferenceCitectHTML/Content/ComOpen.html) docs, after setting up a TCP board (config screenshot below) as per suggestions here.
Screenshot-2021-11-16-020439.png


I am getting error 257 on the line ComWrite (have attached script file), and have tried to see if any variables are out of range but am unable to figure out what I'm doing wrong.

1. Any clues as to what I'm doing wrong?
2. Is it possible to communicate with another process this way in Cicode?
3. Is there a better way for communicating with the server? I was thinking of synchronized file access as a last-ditch attempt.

Thank you so so much in advance for any help, I am stuck on this for a requirement for quite some time!

If you need any additional info, please let me know.

Screenshot 2021-11-16 020439.png
 

Attachments

  • sockets.txt
    1.9 KB · Views: 10
This is probably not the best method to communicate with another application but you still should be able to get it to work.

There are multiple ways depending on what you are trying to achieve, you can write data to a dbf, csv, xlsx, rtf, SQL etc or look at the CtAPI interface for 2 way communications.

To get the ComOpen and write to work you need to assign a port to a board, with the board that you have attached a screenshot remove '699' from the I/O port field and remove '127.0.0.1' from the special opt field and click on replace. Leave the '0' in Address.

Now create a port (will find it in the same menu as boards) and add these details.
Code:
Port name: MyAppPort (call it some meaningful name)
BoardName: tcpb (TCPIP board that you created)
PortNumber: 1 (Needs to be a unique number for that board)
Special Opt: -i127.0.0.1 -p699  (IP address and port number)

In your Cicode for ComOpen you need to use the port name
Code:
String sPort = "MyAppPort"
hPort = ComOpen(sPort, 0);

And then use this handle for all your following com functions. in your Cicode you are not passing the ComOpen handle (hPort) to the ComWrite() function, SerialWrite(sPort) should be SerialWrite(hPort)

It looks like you are experimenting with Cicode, I would simplify it with a single function until you have a basic working code.

Good luck.
 
Thank you so much Andrew for taking the time out to help me, such a godsend!

You're right, I'm very new and experimenting with Cicode. I'm on a mission to ascertain the feasibility for a project.

It would be of immense help if you point me towards any CtApi documentation or examples for how to run code written in C. (source)

I followed the steps and here's my
Current TCP board record:
TCPIP-Board.png


Current Port record:
Port.png


PFA the current cicode.

When I run the function, I am still getting this error.
error.png


Any idea what I'm doing wrong?

Thank you so much in advance!!
 
The port and board forms look OK now.

If you are running in multi-process mode the com functions need to be called from the I/O process.

multi-process is the default mode. Easiest way to confirm is to open the Citect runtime manager, located in the bottom right hand corner in the system try. If your runtime manager looks like the picture in the below link with the separate 5 processes then you are running in multi-process mode. If only the one process is shown and under the ‘Type’ it has ‘mixed’ then you are running in single process mode.
https://johnwiltshire.com/citect-help/Content/Runtime_Manager.html

If you are running in multi-process mode easiest way to call function from the IO process for testing purposes is to run it from the kernel. In a production environment you would either call it from the process using an event or start up code or in the cicode function by using MsgRPC().

To access cicode from the kernel window you need to add a kernel user, if it doesn’t already exist. Add a new user with the username of kernel and password whatever you want.

To open the kernel for the IO process, open the runtime manager as above and select the process that has type as ‘IO Server’ so that it is highlighted then right click and select ‘Kernel’ from the menu that appears.

You should get a Main kernel window and you should be able to type. Type ‘cicode’ and press enter and it will ask you for the kernel password, if successful a new cicode window will appear.
From this cicode window you can enter your command, this will run the function from the IO process.

Code:
0:> TestCitectVBA()

A couple of tips on fault finding, how you have used the message() function through your cicode you can use tracemsg() and the result will show in the general kernel window. You can also use ErrLog() which will show in kernel window as well as logging to the kernel.dat, only use ErrLog() when essential otherwise it will spam your logs if used everywhere.
 
Hi Andrew,

Sorry for the late reply!! Thank you so much for the reply!!

The Citect runtime manager has only 1 process, with type client.
Citect-Runtime-Manager.png

I am currently calling the 'StartSerial' function from a button click on the GUI, will that be a problem?


I changed all the Message() calls with TraceMsg() and it has made life much easier.
The ErrLog() call logs the errors to a log file in "Documents and Settings" on my machine. However, this folder seems to have some access problems and I'm unable to even list the files in it (dir). Is there a way to change the error log location?

I am still getting the error code 257 on ComWrite(), with no idea what it means (guessing index out of bounds error) and how to fix it :( .
Will running the cicode from an IO process help?
 
Is this just a test project running on a single PC with no physical IO or is this a running system in production?

I think its a simple case of server config and network address but want to be sure of what environment you are testing in first.
 
Yup, you're right, it's a test project running on a single PC with no physical IO.

I'm very new to coding with Cicode and am finding the knowledge base to be somewhat not friendly for beginners like me to understand.
 
Yes it's not easy without some guidance to get started.
At the moment you are running as a client which needs to connect to a server, with no server to connect to then nothing is really going to happen. We need to set your project up as a server.

When Citect is installed there is an Example project, this is meant for beginners to have a look and modify to test. It has all the basics setup and some examples of a few different things so you can run the project to see what it does then look at the project to see how it is achieved. It runs as a server by default.

You can move everything you have created over into the test project and then all the servers are already setup. When you are working with a Citect project you need to make sure you have that project highlighted in Citect Explorer Project List and also run the computer setup wizard as described below.

If you want to get your existing project working then do the following.
Go to the project editor select servers-->Network addresses. For name put localhost (this can be anything it is just a named reference) for address use 127.0.0.1 then click add.

servers-->I/O Servers you should have one named IOServerTrial looking at your previous screenshots. Leave as that name and for Network Addresses select localhost and click replace. This ties the IO server to the IP address of localhost.
You need to do this for Alarm, Report and Trend servers as well which are located in the same menu.

Compile project (File-->Compile)

Run Computer Setup Wizard (Citect Explorer, Tools--> Computer setup Wizard), the wizard basically modifies the Citect.ini file with the basic settings needed.
The first step of the wizard will have the project name, make sure that’s the project you’re working on. The next screen will have the computer role, if the machine IP matches the IP address of the IO Server then you should have the top option of server and control client. If you only have the option of control client and view client then there is an issue and you need to go back and check Network Addresses and Server configuration.
Next screen should be Network setup, select stand alone.
then just click all the way through.

Then run the project and open up the runtime manager and hopefully you should see as I described in my 2nd post and follow those instructions to run your function from the IO Server kernel.
 

Similar Topics

Hi All, Can anyone advise me on how to determine the AN of a genie instance I writing to. I have created a genie to display a valve and some text...
Replies
0
Views
81
I am trying to display a variable within a cicode function onto a graphics page. This function queries a SQL database. I can get the value onto a...
Replies
3
Views
229
Hi guys, its my first time progamming cicode and I need to do popups alarms, there are several digital alarms and in their rising edge transition...
Replies
0
Views
479
Hi all :) , I'm very new to CitectSCADA and Cicode programming, however have good programming experience in most major programming languages...
Replies
0
Views
1,241
Hello, it's been a little over a year now that I've been learning citect scada alone in version 7.2, I know how to make pages, synoptics, create...
Replies
4
Views
7,040
Back
Top Bottom