Main Page   Compound List   File List   Compound Members   File Members  

TecPlc.c File Reference

This module implements a class driver for channels located in a Modicon PLC. More...


Compounds

struct  TEC_INFO
 This structure is the basic parameter definition for the device to be handled. More...


Defines

#define DRIVER(_i)   ((INT (*)(INT cmd, ...))(pTecInfo->driver[_i]))
#define abs(a)   (((a) < 0) ? -(a) : (a))

Functions

void * GetChannelRecord (INT type, HNDLE hDB, HNDLE key)
 Allocates memory for the channel type and reads the record from the ODB and merges it into the allocated memory depending on the type of the channel.

INT GetReadRegister (void *channel)
 Gets the PLC register to read for the type of the channel.

INT GetWriteRegister (void *channel)
 Gets the PLC register to write for the type of the channel.

INT ParseReadData (void *channel, INT value)
 Takes read value and decomposes into ODB key values.

INT UpdateChannel (HNDLE hDB, TEC_INFO *pTecInfo, INT channel)
 Compare the channel and mirror info to see if anything changed.

INT SetControlDemand (EQUIPMENT *pequipment, HNDLE hDB, TEC_INFO *pTecInfo, INT channel)
 Attaches the hotlink callback functions to the specified channel.

void CommandDemand (HNDLE hDB, HNDLE hKey, void *info)
 Hotlink callback function for turning on controlled channel.

INT CommandClear (void *param)
 Task spawned to clear the passed address in the PLC after one second.

void free_mem (TEC_INFO *pTecInfo)
 This function will free all allocated memory for the device at the end of its lifetime.

void tec_read (EQUIPMENT *pequipment, int channel)
 This routine collects data from all the signal sources and writes them to the ODB if they have changed.

INT tec_init (EQUIPMENT *pequipment)
 This routine is used to initialize the instance of the equipment.

INT tec_exit (EQUIPMENT *pequipment)
 Exit function that closes all device driver conections.

INT tec_idle (EQUIPMENT *pequipment)
 The idle task routine.

INT cd_tec_read (char *pevent, INT off)
 Generates bank data for the logger.

INT cd_tec (INT cmd, EQUIPMENT *pequipment)
 This is the class driver command interface, called by the front end code on startup, shutdowen and periodically by idle task.

void SetpointDemand (HNDLE hDB, HNDLE hKey, void *info)
 Hotlink callback function for turning on controlled channel.


Detailed Description

This module implements a class driver for channels located in a Modicon PLC.

The interface to controllable channels is based on the ISAC Controls PLC interface specification, which uses a Command and Status word for each device. These registers are located in the 4x area of the PLC.

There are also simple value channels which give data from analog inputs, These registers are located in the 4x area of the PLC.

To manage the channels, a data structure is defined that can handle all aspects of each channel type. The ODB entries contain a Type field to identify each channel.

Author:
David Morris - TRIUMF

Define Documentation

#define abs      (((a) < 0) ? -(a) : (a))
 

#define DRIVER _i       ((INT (*)(INT cmd, ...))(pTecInfo->driver[_i]))
 


Function Documentation

INT cd_tec INT    cmd,
EQUIPMENT *    pequipment
 

This is the class driver command interface, called by the front end code on startup, shutdowen and periodically by idle task.

Parameters:
cmd  the command to execute in the class driver
pequipment  a pointer the the EQUIPMENT structure used by the front end
Returns:
the result of the requested command or FE_ERR_DRIVER if the request is invalid

INT cd_tec_read char *    pevent,
INT    off
 

Generates bank data for the logger.

Not implemented at present

INT CommandClear void *    param [static]
 

Task spawned to clear the passed address in the PLC after one second.

Parameters:
param  a VX_TASK_SPAWN structure defining the PLC and address.
  • arg1 contains the pointer to the TEC_INFO structure
  • arg2 contains the channel number
  • arg3 contains the handle of the database
  • arg4 contains the handle of the key

void CommandDemand HNDLE    hDB,
HNDLE    hKey,
void *    info
 

Hotlink callback function for turning on controlled channel.

Parameters:
hDB  a handle to the database
hKey  the handle of the modified key
info  the EQUIPMENT pointer for the front end

void free_mem TEC_INFO   pTecInfo [static]
 

This function will free all allocated memory for the device at the end of its lifetime.

Parameters:
pTecInfo  pointer to the structure

void * GetChannelRecord INT    type,
HNDLE    hDB,
HNDLE    hKey
[static]
 

Allocates memory for the channel type and reads the record from the ODB and merges it into the allocated memory depending on the type of the channel.

Parameters:
type  the type of the new channel structure
hDB  a handle to the database
hKey  the handle of the modified key

INT GetReadRegister void *    channel [static]
 

Gets the PLC register to read for the type of the channel.

Parameters:
channel  a pointer to the channel data structure

INT GetWriteRegister void *    channel [static]
 

Gets the PLC register to write for the type of the channel.

Parameters:
channel  a pointer to the channel data structure

INT ParseReadData void *    channel,
INT    value
[static]
 

Takes read value and decomposes into ODB key values.

The CONTROL type of channel has several status bits in the passed value.

Parameters:
channel  a pointer to the channel entry in the data structure
value  the value to be decomposed

INT SetControlDemand EQUIPMENT *    pequipment,
HNDLE    hDB,
TEC_INFO   pTecInfo,
INT    channel
[static]
 

Attaches the hotlink callback functions to the specified channel.

The type of the channel and the associated callbacks are determined.

Parameters:
pequipment  an EQUIPMENT pointer for the front end
hDB  the handle to the database
pTecInfo  the internal data structure for the front end
channel  the target channel for the hotlinks

void SetpointDemand HNDLE    hDB,
HNDLE    hKey,
void *    info
 

Hotlink callback function for turning on controlled channel.

Parameters:
hDB  a handle to the database
hKey  the handle of the modified key
info  the EQUIPMENT pointer for the front end

INT tec_exit EQUIPMENT *    pequipment
 

Exit function that closes all device driver conections.

Parameters:
pequipment  the EQUIPMENT pointer for the class driver
Returns:
always returns FE_SUCCESS

INT tec_idle EQUIPMENT *    pequipment
 

The idle task routine.

All channels are read from the PLC.

Parameters:
pequipment  a pointer the the EQUIPMENT structure used by the front end
Returns:
always returns FE_SUCCESS

INT tec_init EQUIPMENT *    pequipment
 

This routine is used to initialize the instance of the equipment.

The connection to the ODB is established, space is allocated to store all the parameters for the devices in the equipment. Values are initialized. The device driver is initialized, and a first collection of data is made.

Parameters:
pequipment  the EQUIPMENT pointer for the class driver
Returns:
always returns FE_SUCCESS

void tec_read EQUIPMENT *    pequipment,
int    channel
 

This routine collects data from all the signal sources and writes them to the ODB if they have changed.

Parameters:
pequipment  the EQUIPMENT pointer for the class driver
channel  the channel of interest. If the channel value is -1 all channels are read.

INT UpdateChannel HNDLE    hDB,
TEC_INFO   pTecInfo,
INT    channel
[static]
 

Compare the channel and mirror info to see if anything changed.

If there is a change, send the updated info to the ODB.

Parameters:
hDB  a handle to the database
pTecInfo  a pointer to the internal data structure
channel  the channel of interest


Generated on Mon Apr 19 15:27:44 2004 for Twist TEC DAQ System by doxygen1.2.18