You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

Reply
 
Thread Tools Display Modes
Old November 15th, 2021, 04:46 PM   #1
tmithun
Member
India

tmithun is offline
 
Join Date: Nov 2021
Location: Bangalore, India
Posts: 5
Exclamation CICODE Inter process communication, TCP/IP sockets.

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-hel...t/ComOpen.html) docs, after setting up a TCP board (config screenshot below) as per suggestions here.


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.
Attached Images
File Type: png Screenshot 2021-11-16 020439.png (11.4 KB, 4 views)
Attached Files
File Type: txt sockets.txt (1.9 KB, 5 views)
  Reply With Quote
Old November 16th, 2021, 06:49 AM   #2
andrewf
Member
Australia

andrewf is offline
 
Join Date: Mar 2008
Location: NSW
Posts: 82
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.
  Reply With Quote
Old November 17th, 2021, 06:57 AM   #3
tmithun
Member
India

tmithun is offline
 
Join Date: Nov 2021
Location: Bangalore, India
Posts: 5
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:


Current Port record:


PFA the current cicode.

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


Any idea what I'm doing wrong?

Thank you so much in advance!!
Attached Files
File Type: txt trailCitect.txt (1.1 KB, 6 views)
  Reply With Quote
Old November 17th, 2021, 10:24 PM   #4
andrewf
Member
Australia

andrewf is offline
 
Join Date: Mar 2008
Location: NSW
Posts: 82
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-hel...e_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.
  Reply With Quote
Old November 23rd, 2021, 11:29 AM   #5
tmithun
Member
India

tmithun is offline
 
Join Date: Nov 2021
Location: Bangalore, India
Posts: 5
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.

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?
  Reply With Quote
Old November 25th, 2021, 02:29 AM   #6
andrewf
Member
Australia

andrewf is offline
 
Join Date: Mar 2008
Location: NSW
Posts: 82
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.
  Reply With Quote
Old November 25th, 2021, 07:59 AM   #7
tmithun
Member
India

tmithun is offline
 
Join Date: Nov 2021
Location: Bangalore, India
Posts: 5
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.
  Reply With Quote
Old November 26th, 2021, 02:32 AM   #8
andrewf
Member
Australia

andrewf is offline
 
Join Date: Mar 2008
Location: NSW
Posts: 82
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.
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
S71200 TCP/IP communication with scanner card hema LIVE PLC Questions And Answers 1 December 21st, 2020 12:07 AM
problem in modbus tcp/ip communication dardary LIVE PLC Questions And Answers 0 November 8th, 2006 08:12 AM
S7-400 Communication over TCP/IP namboothiripad.mbs LIVE PLC Questions And Answers 2 October 7th, 2006 06:20 AM
Program Structure DDV LIVE PLC Questions And Answers 78 September 18th, 2006 07:16 AM
Simulator, Simulation, Shadow Code Terry Woods LIVE PLC Questions And Answers 1 January 2nd, 2005 03:40 PM


All times are GMT -4. The time now is 06:54 PM.


.