Irai Automgen Runtime User guide

Type
User guide
A
U
Csourc
e
OpenS
o
2008
U
T
O
e
Runtimefo
o
urce
IRAI‐w
w
OM
rAUTOMGE
w
w.irai.
c
M
G
E
N
c
om
E
N
R
U
U
N
T
T
IME

3
The purpose is to propose a free AUTOMGEN runtime which can be used to build AUTOMGEN
compatible targets.The runtime itself is a very small program which is able to run directly
AUTOMGENpivotcodegeneratedwithAUTOMGENINTpostprocessor.TheRUNTIMEisabletorun
100%of the AUTOMGEN
programming,SCADAand WEB SCADA functionalities. AUTOMGEN is able
tocommunicatewiththeRUNTIMEonserialcommunicationportoronTCPIP.
AUTOMGENruntimeiscomposedbysmallcsourcefiles.Thisisalowlevelconcept,soitshouldrun
ontargetswithlowresources.
Filesareclassifiedin
twogroups:
targetspecificgroup(filesmustbemodifiedforeachtargets)
standardgroup(filesshouldbecompiledwithoutmodificationsforanytargets).
Theincludedsamplescanbecompiledwith:
‐VISUALC6.0,.NET2003or.NET2005forWindows32bitssamples,
‐embeddedVisualC++4.0for
WindowsCE,
‐thestandardfilesshouldbecompiledwithanyCcompilers.
StandardFiles
Core.c
Thisisthemainpartoftheruntime;thispartisabletorunAUTOMGENprograms.
Core Com
I/O
(devicespecific)
Target
(devicespecific)
PhysicalI/Os
SerialorTCPIP
link

4
Com.c
This is the high level communicationpart.The low levelis device specific (target_xxx.c).The Com.h
header file contains the communication settings: serial port (number, speed, parity, etc.) or TCPIP
(portnumber).
SpecificFiles
Io.c
ThisisthelinkbetweentheruntimeandthephysicalI/Os.
The functions of this module must be modified for driving the physical I/O available on the device
(seesamplesbelow).
Listoftheio.cfunctions
intinitio(void)
MustinitializethephysicalI/O.Mustreturn0iftheI/Oinitializationis
ok,otherwise<0.
Sample:
int initio(void)
{
if(initializemyio()<0) return -1;
return 0;
}
intuninitio(void)
MustuninitializethephysicalI/O.Mustreturn0ifok,otherwise<0.
intreadi(struct_a7int*a7int)
MustreadphysicalinputsandtransferdataintoAUTOMGENvariables.Mustreturn0ifok,otherwise
<0.
Sample(assumingthatgetifunctionreturns32digitalinputsinadwordandgetaifunctionreturnsa
16bitsanalogvalue
inaword).
int readi(struct _a7int *a7int)
{
unsigned count;
unsigned long digitali;
digitali=geti();
// 32 digital inputs
for(count=0;count<32;count++)
{
setvar(a7int,0,a7int->io_i_pos++,(digitali&(1<<count))?1:0,0xffffffff);

5
}
// 1 analog input
a7int->pM[a7int->io_m_pos++]=getai();
return 0;
}
Notes:
1 setvaris a core function whichmustbe used for Booleanvariables state mod ifications. The
directaccessisnotpermittedforwritingBooleanvariablevalues.
2 io_i_pos,io_o_posandio_m_posmemberscan beusedforaccessingthenextvariables.
intwriteo(struct_a7int*a7int)
Must write physical outputs from the states of
the AUTOMGEN variables. Must return 0 if OK,
otherwise<0.
Sample(assuming puto writes16 digital outputs of 4 differentoutputsmodulesand putaowrites 4
analogvalues).
int writeo(struct _a7int *a7int)
{
unsigned modulecount;
unsigned count;
// 4 x 16 digital outputs
for(modulecount=0;modulecount<4;modulecount++)
{
unsigned short v=0;
for(count=0;count<16;count++)
{
if(a7int->pO[a7int->io_o_pos++]) v|=1<<count;
}
puto(modulecount,v);
}
// 4 analog values (assuming putao need a pointer to 4 16 bits values)
putao(&pM[a7int->io_m_pos]);
a7int->io_m_pos+=4;
return 0;
}
Target_xxx.c
Thisisatargetspecificfile,theprovided filestarget_xxx.cfileshowsomespecificsfiles:

6
Target_win32_console :forwindows32OSinconsolemode
Target_win32_gui:forwindows32OSguimode
Target_wince:forWindowsCEOS
Listofthetarget_xxx.cfunctions
DWORDtarget_gettimeinms(void)
MustreturnaDWORDwhichisa32bitstimecounterinms.Thestartingvaluedoesnotmatter,the
important is
that the returned value between two calls evolves regarding the number of 1/1000
secondswhichhaveelapsed.
voidtarget_readrtc(unsignedshort*ms,unsignedshort*sec,unsignedshort*min,unsignedshort
*hour,unsignedshort*day,unsignedshort*month,unsignedshort*year)
Mustreturnthecurrentdateandtimeinthe7unsignedshorts.
voidtarget_fatal(void)
Calledwhenafatalerroroccurs,byexampletheexecutionofaninvalidoperationcode.
char*target_id(void)
Mustreturna
16chars string(thele ngthmustbeexactly16chars)whichisthenameofthetarget.
ThisnamewillbedisplayedinAUTOMGENatconnectiontime.
unsignedchartarget_confbyte(void)
Mustreturnaconfigurationbyte.Actuallyonlybit1(value=2)isused.Thisbitmustbesetto0ifthe
integersarecodedwithLSBfirst,otherwisesetthisbitto1.
inttarget_com_open(unsignedport,unsigned speed,unsigned parity,unsigned databits,unsigned
stopbits)
Openaserialportforcommunications.
Portisthenumberoftheport,1=firstport,2=second,etc.
Speedisthebaudrateinbauds,
Parityisoneofthesechars:N(fornone),O(forodd),
E(foreven),
Databits:always8.
Stopbits:1or2.
Thisfunctionmustreturn0forsuccess,<0forerror.
voidtarget_com_send(unsignedchar*buff,unsignedlen)
Thisfunctionmustsendthelencharsofthebuffbufferstotheseriallink.
inttarget_com_getchar(void)
Thisfunctionmustreturnanincomingcharfromtheseriallinkor‐1ifnocharhasbeen
received.

7
voidtarget_com_close(void)
Thisfunctionmustclosetheseriallink.
inttarget_netcom_start(void)
ThisfunctionmustinitializetheTCPIPconnectionandmustreturn0forsuccessor‐1otherwise.
inttarget_netcom_close(void)
ThisfunctionmustclosetheTCPIPconnection.
inttarget_netcom_srvread(unsignedclient,unsignedchar*data,unsignedmaxdata)
This function must return datas read from the specified TCPIP client. Must return the number
of
readbytesincaseofsuccess,otherwise‐1.
inttarget_netcom_srvgetlenin(unsignedclient)
MustreturnthenumberofavailablecharsforthespecifiedTCPIPclientor‐1iferror.
inttarget_netcom_srvgetfirstclient(void)
MustreturnthefirstTCPIPclientconnectedor‐1ifnoclientisconnected.
inttarget_netcom_srvgetnextclient(unsignedcli)
MustreturnthenextTCPIPclient(following
cli)connecte d or‐1ifnomoreclients.
inttarget_netcom_srvopen(int(*netevent)(struct_NE*pne),WORDport)
MustcreateaTCPIPserver.
Netvent:alwaysnull.
Portnumber:portusedforlisteningincomingclientrequests.
Mustreturn0forsuccess,otherwise<0.
inttarget_netcom_srvclose(void)
MuststoptheTCPIPserver.Mustreturn0forsuccess,otherwise<0.
inttarget_netcom_srvsenddata(intclient,BYTE*data,intlen)
Must
sendlenbytestothespecifiedclient.Mustreturn0forsuccess,otherwise<0.
Assistance
StephaneMASSART
Tel+33466549130
  • Page 1 1
  • Page 2 2
  • Page 3 3
  • Page 4 4
  • Page 5 5
  • Page 6 6
  • Page 7 7

Irai Automgen Runtime User guide

Type
User guide

Ask a question and I''ll find the answer in the document

Finding information in a document is now easier with AI