Implements a protocol handler for the protek 608 multimeters which just allows us to read the display. It reports all elements of the display including the bar graph, it does not provide remote control of the multimeter. The protocol handler broadcasts a warning to all clients if the auto-off function is enabled. sct_rfamp.c This is a protocol handler for the Mirrortron 35V 7A AC Generator (ANSFR-83B). sinqhttpprot.c Copied the PSI script context http protocol handler. sct_orhvpsprot.c Ordela high voltage power supply protocol handler now catches unknown commands. sct_eurotherm_2000.tcl Eurotherm controller for the kowari load frame by Douglas Clowes. sct_lakeshore_3xx.tcl Latest update from Arndt. The two control loops are now independent, settletime and tolerance now work properly. common_instrument_dictionary.tcl Make instrument/status saveable. sct_orhvps_common.tcl Provides voltage ramping and implements the dhv1 command for the Ordela HVPS via the sct_orhpsprot.c protocol handler. hmm_configuration_common_1.tcl Adds new "histmem clockscale" subcommand to get and set the clock scale from the fat_clock_scale FAT parameter. You can now upload the FAT FRAME_BUFFER and FRAME_DUTYCYCLE parameters to the histogram memory. The veto commands are now "histmem veto on" and "histmem veto off". hmm_object.tcl The axis order for the histmem object has been restore to t,y,x sct_positmotor_common.tcl Code has been simplified. nxscripts_common_1.tcl Removed obsolete ::nexus::data function. TOF axis now correctly report time_of_flight instead of "time". plc_common_1.tcl Make PLC info saveable. scan_common_1.tcl SICS-385 The scan command should check the final scan variable value against he soft upper and lower limits, not against the hard limits. Make sure that the scan variable axis is saved. platypus, kowari, quokka hmm_configuration.tcl Use the HOR and VER entries in the new histmem_axes hash to select the horizontal and vertical axes for the histmem. kowari motor_configuration.tcl secondary_slit_configuration.tcl Flatten slits motor structure to match old layout in data files. quokka commands.tcl SICS-380 EApPosYmm -> EApPosY quokka detector.tcl Use new script context controller for Ordela HVPS quokka hmm_configuration.tcl Set detector height to 5.08*192 the same as the width quokka motor_configuration.tcl Code cleanup quokka positmotor_configuration.tcl Use new positmotor code. quokka aperture_configuration.tcl Added attenuation factor column to AttRotLookupTable quokka parameters.tcl SICS-380 Refactor nexus, remove redundant parameters. site_ansto.c Added the following protocols, Httpl, Protek608, aand RFAmp. scriptcontext.c SICS-386 SctActionHandler: set "send" string to NULL when a chain of scripts completes with state=idle. It turns out that if none of the scripts in the "read chain" call [sct send] each time the chain is executed, then SICS will hammer the device with calls to AsconWrite(). This can be avoided if SctActionHandler sets the 'send' string to NULL before "goto finish" in the idle state. This will be safer and still let you have chains with multiple [sct send] and read scripts. asyncprotocol.c Fix platypus memory leak. devser.c SICS-387 Started adding code to pass signals on to script context drivers. ascon.c AsconTask(): Make sure we return to the AsconIdle state when sending a command which expect no response, also only reconnect if there is a Timeout when there has been an error. r2888 | ffr | 2010-04-19 14:04:41 +1000 (Mon, 19 Apr 2010) | 90 lines
523 lines
15 KiB
C
523 lines
15 KiB
C
/*
|
|
* S A F E T Y P L C
|
|
*
|
|
* Douglas Clowes, February 2007
|
|
*
|
|
*/
|
|
|
|
#include <netinet/tcp.h>
|
|
#include <sys/time.h>
|
|
#include <sics.h>
|
|
#include "network.h"
|
|
#include "asyncqueue.h"
|
|
#include "nwatch.h"
|
|
#include "safetyplc.h"
|
|
#include "sicsvar.h"
|
|
|
|
extern int DMC2280MotionControl;
|
|
|
|
#define KEY_ENABLED_BIT (1 << 0)
|
|
#define KEY_DISABLED_BIT (1 << 1)
|
|
#define SEC_OPENED_BIT (1 << 2)
|
|
#define SEC_CLOSED_BIT (1 << 3)
|
|
#define TER_OPENED_BIT (1 << 4)
|
|
#define TER_CLOSED_BIT (1 << 5)
|
|
#define MOTOR_ENABLED_BIT (1 << 6)
|
|
#define MOTOR_DISABLED_BIT (1 << 7)
|
|
#define ACCESS_LOCKED_BIT (1 << 8)
|
|
#define ACCESS_UNLOCKED_BIT (1 << 9)
|
|
#define DC_POWEROK_BIT (1 << 10)
|
|
#define EXIT_INPROGRESS_BIT (1 << 11)
|
|
#define SAFETY_TRIPPED_BIT (1 << 12)
|
|
#define SAFETY_MALFUNCTION_BIT (1 << 13)
|
|
#define TER_OPERATE_BIT (1 << 14)
|
|
#define RELAY_ENABLED_BIT (1 << 15)
|
|
#define INST_READY_BIT (1 << 16)
|
|
#define LAMP_TEST_BIT (1 << 17)
|
|
|
|
#define KEY_BOTH_BITS (KEY_ENABLED_BIT | KEY_DISABLED_BIT)
|
|
#define SEC_BOTH_BITS (SEC_OPENED_BIT | SEC_CLOSED_BIT)
|
|
#define TER_BOTH_BITS (TER_OPENED_BIT | TER_CLOSED_BIT)
|
|
#define MOTOR_BOTH_BITS (MOTOR_ENABLED_BIT | MOTOR_DISABLED_BIT)
|
|
#define ACCESS_BOTH_BITS (ACCESS_LOCKED_BIT | ACCESS_UNLOCKED_BIT)
|
|
|
|
static pAsyncProtocol PLC_Protocol = NULL;
|
|
|
|
int PLC_UserPriv = 0; /* Internal */
|
|
typedef enum {
|
|
Unknown_low, Invalid_high, Enabled, Disabled,
|
|
Opened, Closed, Locked, Unlocked, True, False,}PLC_STATUS;
|
|
|
|
char *plc_states[] = {
|
|
"UNKNOWN_LOW", "INVALID_HIGH", "ENABLED",
|
|
"DISABLED", "OPEN", "CLOSED",
|
|
"LOCKED", "UNLOCKED", "TRUE", "FALSE"};
|
|
|
|
typedef enum {
|
|
Key,Secondary,Tertiary,MotionControl,Access,
|
|
DC,Exit,Trip,Fault,Operate,Relay,Ready,}PLC_PARAM;
|
|
|
|
char *plc_parname[] = {
|
|
"plc_key","plc_secondary","plc_tertiary","plc_motioncontrol",
|
|
"plc_access","plc_dc","plc_exit","plc_trip",
|
|
"plc_fault","plc_operate","plc_relay","plc_ready"};
|
|
|
|
typedef struct __SafetyPLCController SafetyPLCController, *pSafetyPLCController;
|
|
|
|
struct __SafetyPLCController {
|
|
pObjectDescriptor pDes;
|
|
pAsyncUnit unit; /* associated AsyncUnit object */
|
|
int iGetOut;
|
|
int iValue;
|
|
int oldValue;
|
|
pNWTimer nw_tmr; /* periodic timer handle */
|
|
pNWTimer oneshot; /* oneshot timer handle */
|
|
int timeout;
|
|
};
|
|
|
|
static int PLC_GetState(void *pData, char *param, PLC_STATUS *retState);
|
|
|
|
static int PLC_Tx(pAsyncProtocol p, pAsyncTxn myCmd)
|
|
{
|
|
int iRet = 1;
|
|
|
|
if (myCmd) {
|
|
myCmd->txn_status = ATX_ACTIVE;
|
|
iRet = AsyncUnitWrite(myCmd->unit, myCmd->out_buf, myCmd->out_len);
|
|
/* TODO handle errors */
|
|
if (iRet < 0) { /* TODO: EOF */
|
|
iRet = AsyncUnitReconnect(myCmd->unit);
|
|
if (iRet == 0)
|
|
return 0;
|
|
}
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
static int PLC_Rx(pAsyncProtocol p, pAsyncTxn myCmd, int rxchar)
|
|
{
|
|
int iRet = 1;
|
|
|
|
switch (myCmd->txn_state) {
|
|
case 0: /* first character */
|
|
/* normal data */
|
|
myCmd->txn_state = 1;
|
|
/* note fallthrough */
|
|
case 1: /* receiving reply */
|
|
if (myCmd->inp_idx < myCmd->inp_len)
|
|
myCmd->inp_buf[myCmd->inp_idx++] = rxchar;
|
|
if (rxchar == 0x0D)
|
|
myCmd->txn_state = 2;
|
|
break;
|
|
case 2: /* received CR and looking for LF */
|
|
if (myCmd->inp_idx < myCmd->inp_len)
|
|
myCmd->inp_buf[myCmd->inp_idx++] = rxchar;
|
|
if (rxchar == 0x0A) {
|
|
myCmd->txn_state = 99;
|
|
/* end of line */
|
|
}
|
|
else
|
|
myCmd->txn_state = 1;
|
|
break;
|
|
}
|
|
if (myCmd->txn_state == 99) {
|
|
myCmd->inp_buf[myCmd->inp_idx] = '\0';
|
|
iRet = 0;
|
|
myCmd->txn_state = 0;
|
|
myCmd->txn_status = ATX_COMPLETE;
|
|
}
|
|
if (iRet == 0) { /* end of command */
|
|
return AQU_POP_CMD;
|
|
}
|
|
return iRet;
|
|
}
|
|
|
|
static int PLC_Ev(pAsyncProtocol p, pAsyncTxn myCmd, int event)
|
|
{
|
|
if (event == AQU_TIMEOUT) {
|
|
/* TODO: handle command timeout */
|
|
myCmd->txn_status = ATX_TIMEOUT;
|
|
return AQU_POP_CMD;
|
|
}
|
|
return AQU_POP_CMD;
|
|
}
|
|
|
|
static void PLC_Notify(void* context, int event)
|
|
{
|
|
pSafetyPLCController self = (pSafetyPLCController) context;
|
|
|
|
switch (event) {
|
|
case AQU_RECONNECT:
|
|
do {
|
|
mkChannel* sock = AsyncUnitGetSocket(self->unit);
|
|
int flag = 1;
|
|
setsockopt(sock->sockid, /* socket affected */
|
|
IPPROTO_TCP, /* set option at TCP level */
|
|
TCP_NODELAY, /* name of option */
|
|
(char *) &flag, /* the cast is historical cruft */
|
|
sizeof(int)); /* length of option value */
|
|
return;
|
|
} while (0);
|
|
}
|
|
return;
|
|
}
|
|
|
|
/*
|
|
* \brief GetCallback is the callback for the read command.
|
|
*/
|
|
static int GetCallback(pAsyncTxn txn)
|
|
{
|
|
int iRet;
|
|
unsigned int iRead;
|
|
char* resp = txn->inp_buf;
|
|
int resp_len = txn->inp_idx;
|
|
PLC_STATUS plcState;
|
|
pSicsVariable plcVar=NULL;
|
|
|
|
pSafetyPLCController self = (pSafetyPLCController) txn->cntx;
|
|
if (resp_len < 0) {
|
|
DMC2280MotionControl = -1;
|
|
}
|
|
else {
|
|
iRet = sscanf(resp,"READ %x", &iRead);
|
|
if(iRet != 1) { // Not a number, probably an error response
|
|
self->iValue = 0;
|
|
}
|
|
else {
|
|
if ((iRead & LAMP_TEST_BIT) == 0)
|
|
self->iValue = iRead;
|
|
}
|
|
if ((self->iValue & MOTOR_BOTH_BITS) == 0) /* neither */
|
|
DMC2280MotionControl = -1;
|
|
else if ((self->iValue & MOTOR_BOTH_BITS) == MOTOR_BOTH_BITS) /* both */
|
|
DMC2280MotionControl = -1;
|
|
else if ((self->iValue & MOTOR_ENABLED_BIT)) /* enabled */
|
|
DMC2280MotionControl = 1;
|
|
else /* disabled */
|
|
DMC2280MotionControl = 0;
|
|
}
|
|
if (self->oldValue != self->iValue) {
|
|
unsigned int i;
|
|
for (i=0; i < sizeof(plc_parname)/sizeof(plc_parname[0]); i++) {
|
|
plcVar = (pSicsVariable)FindCommandData(pServ->pSics,plc_parname[i],"SicsVariable");
|
|
PLC_GetState(self,plc_parname[i],&plcState);
|
|
VarSetText(plcVar,plc_states[plcState],PLC_UserPriv);
|
|
}
|
|
}
|
|
|
|
self->oldValue = self->iValue;
|
|
self->iGetOut = 0;
|
|
return 0;
|
|
}
|
|
|
|
static int MyTimerCallback(void* context, int mode)
|
|
{
|
|
pSafetyPLCController self = (pSafetyPLCController) context;
|
|
if (self->iGetOut) {
|
|
/* TODO error handling */
|
|
}
|
|
self->iGetOut = 1;
|
|
AsyncUnitSendTxn(self->unit, "READ", 4, GetCallback, self, 132);
|
|
return 1;
|
|
}
|
|
|
|
static int MyOneShotCallback(void* context, int mode)
|
|
{
|
|
pSafetyPLCController self = (pSafetyPLCController) context;
|
|
self->oneshot = 0;
|
|
AsyncUnitSendTxn(self->unit, "WRITE 0", 7, NULL, NULL, 132);
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* \brief PutCallback is the callback for the write command.
|
|
*/
|
|
static int PutCallback(pAsyncTxn txn)
|
|
{
|
|
pSafetyPLCController self = (pSafetyPLCController) txn->cntx;
|
|
if (self->oneshot)
|
|
NetWatchRemoveTimer(self->oneshot);
|
|
NetWatchRegisterTimer(&self->oneshot, 500, MyOneShotCallback, self);
|
|
return 0;
|
|
}
|
|
|
|
static int PLC_GetState(void *pData, char *param, PLC_STATUS *retState)
|
|
{
|
|
pSafetyPLCController self = (pSafetyPLCController) pData;
|
|
if (strcasecmp(param, plc_parname[Key]) == 0) {
|
|
*retState = Unknown_low;
|
|
if ((self->iValue & KEY_BOTH_BITS) == KEY_BOTH_BITS)
|
|
*retState = Invalid_high;
|
|
else if (self->iValue & KEY_ENABLED_BIT)
|
|
*retState = Enabled;
|
|
else if (self->iValue & KEY_DISABLED_BIT)
|
|
*retState = Disabled;
|
|
return OKOK;
|
|
}
|
|
if (strcasecmp(param, plc_parname[Secondary]) == 0) {
|
|
*retState = Unknown_low;
|
|
if ((self->iValue & SEC_BOTH_BITS) == SEC_BOTH_BITS)
|
|
*retState = Invalid_high;
|
|
if (self->iValue & SEC_OPENED_BIT)
|
|
*retState = Opened;
|
|
else if (self->iValue & SEC_CLOSED_BIT)
|
|
*retState = Closed;
|
|
return OKOK;
|
|
}
|
|
if (strcasecmp(param, plc_parname[Tertiary]) == 0) {
|
|
*retState = Unknown_low;
|
|
if ((self->iValue & TER_BOTH_BITS) == TER_BOTH_BITS)
|
|
*retState = Invalid_high;
|
|
if (self->iValue & TER_OPENED_BIT)
|
|
*retState = Opened;
|
|
else if (self->iValue & TER_CLOSED_BIT)
|
|
*retState = Closed;
|
|
return OKOK;
|
|
}
|
|
if (strcasecmp(param, plc_parname[MotionControl]) == 0) {
|
|
*retState = Unknown_low;
|
|
if ((self->iValue & MOTOR_BOTH_BITS) == MOTOR_BOTH_BITS)
|
|
*retState = Invalid_high;
|
|
else if (self->iValue & MOTOR_ENABLED_BIT)
|
|
*retState = Enabled;
|
|
else if (self->iValue & MOTOR_DISABLED_BIT)
|
|
*retState = Disabled;
|
|
return OKOK;
|
|
}
|
|
if (strcasecmp(param, plc_parname[Access]) == 0) {
|
|
*retState = Unknown_low;
|
|
if ((self->iValue & ACCESS_BOTH_BITS) == ACCESS_BOTH_BITS)
|
|
*retState = Invalid_high;
|
|
else if (self->iValue & ACCESS_LOCKED_BIT)
|
|
*retState = Locked;
|
|
else if (self->iValue & ACCESS_UNLOCKED_BIT)
|
|
*retState = Unlocked;
|
|
return OKOK;
|
|
}
|
|
if (strcasecmp(param, plc_parname[DC]) == 0) {
|
|
*retState = False;
|
|
if (self->iValue & DC_POWEROK_BIT)
|
|
*retState = True;
|
|
return OKOK;
|
|
}
|
|
if (strcasecmp(param, plc_parname[Exit]) == 0) {
|
|
*retState = False;
|
|
if (self->iValue & EXIT_INPROGRESS_BIT)
|
|
*retState = True;
|
|
return OKOK;
|
|
}
|
|
if (strcasecmp(param, plc_parname[Trip]) == 0) {
|
|
*retState = False;
|
|
if (self->iValue & SAFETY_TRIPPED_BIT)
|
|
*retState = True;
|
|
return OKOK;
|
|
}
|
|
if (strcasecmp(param, plc_parname[Fault]) == 0) {
|
|
*retState = False;
|
|
if (self->iValue & SAFETY_MALFUNCTION_BIT)
|
|
*retState = True;
|
|
return OKOK;
|
|
}
|
|
if (strcasecmp(param, plc_parname[Operate]) == 0) {
|
|
*retState = False;
|
|
if (self->iValue & TER_OPERATE_BIT)
|
|
*retState = True;
|
|
return OKOK;
|
|
}
|
|
if (strcasecmp(param, plc_parname[Relay]) == 0) {
|
|
*retState = False;
|
|
if (self->iValue & RELAY_ENABLED_BIT)
|
|
*retState = True;
|
|
return OKOK;
|
|
}
|
|
if (strcasecmp(param, plc_parname[Ready]) == 0) {
|
|
*retState = False;
|
|
if (self->iValue & INST_READY_BIT)
|
|
*retState = True;
|
|
return OKOK;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static int PLC_Print(SConnection *pCon, SicsInterp *pSics,
|
|
void *pData, char *name, char *param)
|
|
{
|
|
char line[132];
|
|
PLC_STATUS state;
|
|
|
|
if (PLC_GetState(pData, param, &state) != OKOK) {
|
|
return 0;
|
|
} else {
|
|
snprintf(line, 132, "%s.%s = %s", name, param, plc_states[state]);
|
|
SCWrite(pCon, line, eStatus);
|
|
return OKOK;
|
|
}
|
|
}
|
|
|
|
static int PLC_Action(SConnection *pCon, SicsInterp *pSics,
|
|
void *pData, int argc, char *argv[])
|
|
{
|
|
char line[132];
|
|
pSafetyPLCController self = (pSafetyPLCController) pData;
|
|
if (argc == 1) {
|
|
snprintf(line, 132, "%s.iValue = %06X", argv[0], self->iValue & 0xffffff);
|
|
SCWrite(pCon, line, eStatus);
|
|
return OKOK;
|
|
}
|
|
else if (argc == 2) {
|
|
if (strcasecmp(argv[1], "list") == 0) {
|
|
PLC_Print(pCon, pSics, pData, argv[0], plc_parname[Key]);
|
|
PLC_Print(pCon, pSics, pData, argv[0], plc_parname[Secondary]);
|
|
PLC_Print(pCon, pSics, pData, argv[0], plc_parname[Tertiary]);
|
|
PLC_Print(pCon, pSics, pData, argv[0], plc_parname[MotionControl]);
|
|
PLC_Print(pCon, pSics, pData, argv[0], plc_parname[Access]);
|
|
PLC_Print(pCon, pSics, pData, argv[0], plc_parname[DC]);
|
|
PLC_Print(pCon, pSics, pData, argv[0], plc_parname[Exit]);
|
|
PLC_Print(pCon, pSics, pData, argv[0], plc_parname[Trip]);
|
|
PLC_Print(pCon, pSics, pData, argv[0], plc_parname[Fault]);
|
|
PLC_Print(pCon, pSics, pData, argv[0], plc_parname[Operate]);
|
|
PLC_Print(pCon, pSics, pData, argv[0], plc_parname[Relay]);
|
|
PLC_Print(pCon, pSics, pData, argv[0], plc_parname[Ready]);
|
|
return OKOK;
|
|
}
|
|
if (PLC_Print(pCon, pSics, pData, argv[0], argv[1]))
|
|
return OKOK;
|
|
} else if (argc == 3) {
|
|
if (strcasecmp(argv[1], "hattach") == 0) {
|
|
}
|
|
else if (strcasecmp(argv[1], "shutter") == 0) {
|
|
if (strcasecmp(argv[2], "open") == 0) {
|
|
/* open shutter */
|
|
AsyncUnitSendTxn(self->unit, "WRITE 1", 4, PutCallback, self, 132);
|
|
return OKOK;
|
|
}
|
|
else if (strcasecmp(argv[2], "close") == 0 ||
|
|
strcasecmp(argv[2], "shut") == 0) {
|
|
/* close shutter */
|
|
AsyncUnitSendTxn(self->unit, "WRITE 2", 4, PutCallback, self, 132);
|
|
return OKOK;
|
|
}
|
|
else {
|
|
snprintf(line, 132, "%s %s does not understand %s",
|
|
argv[0], argv[1], argv[2]);
|
|
SCWrite(pCon, line, eError);
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
snprintf(line, 132, "%s does not understand %s", argv[0], argv[1]);
|
|
SCWrite(pCon, line, eError);
|
|
return 0;
|
|
}
|
|
|
|
static pSafetyPLCController PLC_Create(const char* pName)
|
|
{
|
|
pSafetyPLCController self = NULL;
|
|
|
|
self = (pSafetyPLCController) malloc(sizeof(SafetyPLCController));
|
|
if (self == NULL)
|
|
return NULL;
|
|
memset(self, 0, sizeof(SafetyPLCController));
|
|
if (AsyncUnitCreate(pName, &self->unit) == 0) {
|
|
free(self);
|
|
return NULL;
|
|
}
|
|
AsyncUnitSetNotify(self->unit, self, PLC_Notify);
|
|
|
|
self->pDes = CreateDescriptor("SafetyPLC");
|
|
return self;
|
|
}
|
|
|
|
static int PLC_Init(pSafetyPLCController self)
|
|
{
|
|
/* TODO: Init the controller */
|
|
if (self->nw_tmr != NULL)
|
|
NetWatchRemoveTimer(self->nw_tmr);
|
|
NetWatchRegisterTimerPeriodic(&self->nw_tmr,
|
|
1000, 1000,
|
|
MyTimerCallback,
|
|
self);
|
|
self->timeout=120000; /* huge */
|
|
return 1;
|
|
}
|
|
|
|
static void PLC_Kill(void* pData)
|
|
{
|
|
pSafetyPLCController self = (pSafetyPLCController) pData;
|
|
if (self->nw_tmr)
|
|
NetWatchRemoveTimer(self->nw_tmr);
|
|
if (self->pDes) {
|
|
DeleteDescriptor(self->pDes);
|
|
self->pDes = NULL;
|
|
}
|
|
free(self);
|
|
return;
|
|
}
|
|
|
|
void SafetyPLCInitProtocol(SicsInterp *pSics) {
|
|
if (PLC_Protocol == NULL) {
|
|
PLC_Protocol = AsyncProtocolCreate(pSics, "SafetyPLC", NULL, NULL);
|
|
PLC_Protocol->sendCommand = PLC_Tx;
|
|
PLC_Protocol->handleInput = PLC_Rx;
|
|
PLC_Protocol->handleEvent = PLC_Ev;
|
|
PLC_Protocol->prepareTxn = NULL;
|
|
PLC_Protocol->killPrivate = NULL;
|
|
}
|
|
}
|
|
|
|
int SafetyPLCFactory(SConnection *pCon, SicsInterp *pSics,
|
|
void *pData, int argc, char *argv[])
|
|
{
|
|
pSafetyPLCController pNew = NULL;
|
|
int iRet, status;
|
|
unsigned int i;
|
|
char pError[256];
|
|
pSicsVariable plcVar=NULL;
|
|
PLC_STATUS plcState;
|
|
|
|
if(argc < 3)
|
|
{
|
|
SCWrite(pCon,"ERROR: insufficient no of arguments to SafetyPLCFactory",
|
|
eError);
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
create data structure and open port
|
|
*/
|
|
pNew = PLC_Create(argv[2]);
|
|
|
|
if(!pNew)
|
|
{
|
|
SCWrite(pCon,"ERROR: failed to create SafetyPLC in SafetyPLCFactory",eError);
|
|
return 0;
|
|
}
|
|
|
|
status = PLC_Init(pNew);
|
|
if(status != 1)
|
|
{
|
|
sprintf(pError,"ERROR: failed to connect to %s",argv[2]);
|
|
SCWrite(pCon,pError,eError);
|
|
}
|
|
|
|
for (i=0; i < sizeof(plc_parname)/sizeof(plc_parname[0]); i++) {
|
|
plcVar = VarCreate(PLC_UserPriv,veText,plc_parname[i]);
|
|
PLC_GetState(pNew,plc_parname[i],&plcState);
|
|
VarSetText(plcVar,plc_states[plcState],PLC_UserPriv);
|
|
AddCommand(pSics,plc_parname[i],VarWrapper,(KillFunc)VarKill,plcVar);
|
|
}
|
|
/*
|
|
create the command
|
|
*/
|
|
iRet = AddCommand(pSics, argv[1], PLC_Action, PLC_Kill, pNew);
|
|
if(!iRet)
|
|
{
|
|
sprintf(pError,"ERROR: duplicate command %s not created", argv[1]);
|
|
SCWrite(pCon,pError,eError);
|
|
PLC_Kill(pNew);
|
|
return 0;
|
|
}
|
|
SCSendOK(pCon);
|
|
return 1;
|
|
}
|