I am following this guideline to make connection between epics and PLC.
http://metis.ipfn.ist.utl.pt/index.php?title=FUSION_Collaborations/ESTHER/Slow_Control/EPICS_%26_Siemens_PLC_Tutorial
http://oss.aquenos.com/epics/s7nodave/docs/2.1.3/manual.html#recordreference.deviceaddress
Poll Groups
All the input records in the database have a SCAN field. The IOC
application will scan the value of each record at the interval defined
in the SCAN field. For a SCAN field of "0.1 second" of a input record,
the IOC application will query the PLC for that record's value once
every 100 miliseconds.
However, EPICS treats each query independently, so by setting the
SCAN field of every input record in this way, EPICS will query each
value thorugh the local network and wait for the response before moving
on to the next query, resulting in delayed responses.
The s7nodave library allows records to be assinged to polling
groups. All the records in a pollgroup are queried in the same network
packet, greatly reducing response lag.
In order to assign an input record to a poll group using the
s7nodave library, one must set the SCAN field to "I/O Intr", and the INP
field to "@myPLC(PG=[POLLGROUP_NAME]) [PLC_ADDR]". This can be seen in the example below for the PV S7:biI1_5poll.
record(bi, "S7:biI1_5poll")
{
field(SCAN, "I/O Intr")
field(DTYP, "s7nodave")
field(INP, "@myPLC(PG=1s) I1.5")
field(DESC, "S7 PLC I1.5 Binary Input POLLING")
}
Ommiting (PG=[POLLGROUP_NAME]) will assign the PV record to the "default" poll group.
----------------------------------------------
Sequencer Program
The example sequencer program inside this testS7 is a simple
state-machine that monitors the value of a PLC port and sets another
port to high or low accordingly. This program sequencer can be seen in
the [testS7]/tests7App/src/snctests7.stt file:
program snctests7
double v;
short light;
assign v to "S7:biQ1_0";
monitor v;
assign light to "S7:boQ0_7";
ss ss1 {
state init {
when (delay(1)) {
printf("snctests7: Startup delay over\n");
printf("snctests7: Going to low\n");
} state low
}
state low {
when (v >= 0.5) {
printf("snctests7: Changing to high %f\n",v);
light = TRUE;
pvPut(light);
} state high
}
state high {
when (v <= 0.5) {
printf("snctests7: Changing to low %f\n",v);
light = FALSE;
pvPut(light);
} state low
}
}