Low-Energy Muon (LEM) Experiment  0.5.1
scs400.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "midas.h"
#include "mscb.h"
#include "scs400.h"
Include dependency graph for scs400.c:

Go to the source code of this file.

Data Structures

struct  SCS400_SETTINGS
 Stores all the parameters the device driver needs. More...
 
struct  SCS400_INFO
 This structure contains private variables for the device driver. More...
 

Macros

#define SCS400_INIT_ERROR   -2
 tag: initializing error More...
 
#define SCS400_READ_ERROR   -1
 tag: read error More...
 
#define SCS400_MAX_ERROR   5
 maximum number of error messages More...
 
#define SCS400_DELTA_TIME_ERROR   600
 reset error counter after DELTA_TIME_ERROR seconds More...
 
#define SCS400_DEBUG   FALSE
 debug flag More...
 
#define SCS400_MSCB_DEBUG   FALSE
 MSCB debug flag. More...
 
#define SCS400_NOVARS   57
 number of variables of the thermo element MSCB card More...
 
#define SCS400_TEMP_CHS   8
 number of temperature channels More...
 
#define SCS400_POS_DEMAND   0
 position of demand temperature More...
 
#define SCS400_POS_TEMP   1
 position of measured temperature More...
 
#define SCS400_POS_CPROP   2
 position of gain for PID More...
 
#define SCS400_POS_CINT   3
 position of reset for PID More...
 
#define SCS400_POS_PINT   4
 position of PInt from PID More...
 
#define SCS400_POS_POWER   5
 position of power More...
 
#define SCS400_POS_OFFSET   6
 position of offset More...
 
#define SCS400_POS_PERIOD   7
 position of period More...
 
#define SCS400_SETTINGS_STR   "\Detailed Messages = INT : 0\n\Read Period (sec) = INT : 1\n\MSCB Port = STRING : [32] usb0\n\Group Addr = INT : 1\n\Node Addr = INT : 10\n\Demand Temp Name = STRING[8] : \n\[32] Demand0\n\[32] Demand1\n\[32] Demand2\n\[32] Demand3\n\[32] Demand4\n\[32] Demand5\n\[32] Demand6\n\[32] Demand7\n\Temp Name = STRING[8] : \n\[32] Temp0\n\[32] Temp1\n\[32] Temp2\n\[32] Temp3\n\[32] Temp4\n\[32] Temp5\n\[32] Temp6\n\[32] Temp7\n\Gain P (PID) Name = STRING[8] : \n\[32] CProp0\n\[32] CProp1\n\[32] CProp2\n\[32] CProp3\n\[32] CProp4\n\[32] CProp5\n\[32] CProp6\n\[32] CProp7\n\Rate I (PID) Name = STRING[8] : \n\[32] CInt0\n\[32] CInt1\n\[32] CInt2\n\[32] CInt3\n\[32] CInt4\n\[32] CInt5\n\[32] CInt6\n\[32] CInt7\n\PInt (PID) Name = STRING[8] : \n\[32] PInt0\n\[32] PInt1\n\[32] PInt2\n\[32] PInt3\n\[32] PInt4\n\[32] PInt5\n\[32] PInt6\n\[32] PInt7\n\Power Name = STRING[8] : \n\[32] Pwr0\n\[32] Pwr1\n\[32] Pwr2\n\[32] Pwr3\n\[32] Pwr4\n\[32] Pwr5\n\[32] Pwr6\n\[32] Pwr7\n\Offset Name = STRING[8] : \n\[32] Offset0\n\[32] Offset1\n\[32] Offset2\n\[32] Offset3\n\[32] Offset4\n\[32] Offset5\n\[32] Offset6\n\[32] Offset7\n\Period Name = STRING : [32] Period\n\"
 Initializing string for the struct SCS400_SETTINGS. More...
 

Functions

INT scs400_in_init (HNDLE hKey, void **pinfo, INT channels)
 
INT scs400_out_init (HNDLE hKey, void **pinfo, INT channels)
 
INT scs400_exit (SCS400_INFO *info)
 
INT scs400_set (SCS400_INFO *info, INT channel, float value)
 
INT scs400_get_in_label (SCS400_INFO *info, INT channel, char *name)
 
INT scs400_get_out_label (SCS400_INFO *info, INT channel, char *name)
 
float scs400_mscb_to_float (char *data, int index)
 
INT scs400_get (SCS400_INFO *info, INT channel, float *pvalue)
 
INT scs400_in (INT cmd,...)
 
INT scs400_out (INT cmd,...)
 

Variables

SCS400_INFOinfo
 global info structure, in/out-init routines need the same structure More...
 

Macro Definition Documentation

#define SCS400_DEBUG   FALSE

debug flag

Definition at line 29 of file scs400.c.

#define SCS400_DELTA_TIME_ERROR   600

reset error counter after DELTA_TIME_ERROR seconds

Definition at line 27 of file scs400.c.

Referenced by scs400_get(), and scs400_set().

#define SCS400_INIT_ERROR   -2

tag: initializing error

Definition at line 21 of file scs400.c.

Referenced by scs400_get().

#define SCS400_MAX_ERROR   5

maximum number of error messages

Definition at line 25 of file scs400.c.

Referenced by scs400_set().

#define SCS400_MSCB_DEBUG   FALSE

MSCB debug flag.

Definition at line 31 of file scs400.c.

Referenced by scs400_in_init().

#define SCS400_NOVARS   57

number of variables of the thermo element MSCB card

Definition at line 35 of file scs400.c.

Referenced by scs400_in_init().

#define SCS400_POS_CINT   3

position of reset for PID

Definition at line 45 of file scs400.c.

Referenced by scs400_in_init(), and scs400_set().

#define SCS400_POS_CPROP   2

position of gain for PID

Definition at line 43 of file scs400.c.

Referenced by scs400_in_init(), and scs400_set().

#define SCS400_POS_DEMAND   0

position of demand temperature

Definition at line 39 of file scs400.c.

Referenced by scs400_in_init().

#define SCS400_POS_OFFSET   6

position of offset

Definition at line 51 of file scs400.c.

Referenced by scs400_in_init(), and scs400_set().

#define SCS400_POS_PERIOD   7

position of period

Definition at line 53 of file scs400.c.

Referenced by scs400_set().

#define SCS400_POS_PINT   4

position of PInt from PID

Definition at line 47 of file scs400.c.

Referenced by scs400_get(), and scs400_in_init().

#define SCS400_POS_POWER   5

position of power

Definition at line 49 of file scs400.c.

Referenced by scs400_get(), and scs400_in_init().

#define SCS400_POS_TEMP   1

position of measured temperature

Definition at line 41 of file scs400.c.

Referenced by scs400_get(), and scs400_in_init().

#define SCS400_READ_ERROR   -1

tag: read error

Definition at line 22 of file scs400.c.

#define SCS400_SETTINGS_STR   "\Detailed Messages = INT : 0\n\Read Period (sec) = INT : 1\n\MSCB Port = STRING : [32] usb0\n\Group Addr = INT : 1\n\Node Addr = INT : 10\n\Demand Temp Name = STRING[8] : \n\[32] Demand0\n\[32] Demand1\n\[32] Demand2\n\[32] Demand3\n\[32] Demand4\n\[32] Demand5\n\[32] Demand6\n\[32] Demand7\n\Temp Name = STRING[8] : \n\[32] Temp0\n\[32] Temp1\n\[32] Temp2\n\[32] Temp3\n\[32] Temp4\n\[32] Temp5\n\[32] Temp6\n\[32] Temp7\n\Gain P (PID) Name = STRING[8] : \n\[32] CProp0\n\[32] CProp1\n\[32] CProp2\n\[32] CProp3\n\[32] CProp4\n\[32] CProp5\n\[32] CProp6\n\[32] CProp7\n\Rate I (PID) Name = STRING[8] : \n\[32] CInt0\n\[32] CInt1\n\[32] CInt2\n\[32] CInt3\n\[32] CInt4\n\[32] CInt5\n\[32] CInt6\n\[32] CInt7\n\PInt (PID) Name = STRING[8] : \n\[32] PInt0\n\[32] PInt1\n\[32] PInt2\n\[32] PInt3\n\[32] PInt4\n\[32] PInt5\n\[32] PInt6\n\[32] PInt7\n\Power Name = STRING[8] : \n\[32] Pwr0\n\[32] Pwr1\n\[32] Pwr2\n\[32] Pwr3\n\[32] Pwr4\n\[32] Pwr5\n\[32] Pwr6\n\[32] Pwr7\n\Offset Name = STRING[8] : \n\[32] Offset0\n\[32] Offset1\n\[32] Offset2\n\[32] Offset3\n\[32] Offset4\n\[32] Offset5\n\[32] Offset6\n\[32] Offset7\n\Period Name = STRING : [32] Period\n\"

Initializing string for the struct SCS400_SETTINGS.

Definition at line 74 of file scs400.c.

Referenced by scs400_in_init().

#define SCS400_TEMP_CHS   8

number of temperature channels

Definition at line 37 of file scs400.c.

Referenced by scs400_get(), scs400_get_in_label(), scs400_get_out_label(), scs400_in_init(), and scs400_set().

Function Documentation

INT scs400_exit ( SCS400_INFO info)

terminates the MSCB and free's the memory allocated for the DD info structure.

Return: FE_SUCCESS

Parameters
infois a pointer to the DD specific info structure

Definition at line 346 of file scs400.c.

References SCS400_INFO::fd.

Referenced by scs400_in().

INT scs400_get ( SCS400_INFO info,
INT  channel,
float *  pvalue 
)

Reads a temperature value back from the scs400

Return: FE_SUCCESS

Parameters
infois a pointer to the DD specific info structure
channelto be read back
pvaluepointer to the ODB value

Definition at line 510 of file scs400.c.

References SCS400_INFO::errcount, SCS400_INFO::fd, SCS400_INFO::input_buffer, SCS400_INFO::lasterrtime, SCS400_SETTINGS::node_addr, SCS400_INFO::present_value, SCS400_INFO::previous_value, SCS400_SETTINGS::read_timeout, SCS400_INFO::read_timer, SCS400_DELTA_TIME_ERROR, SCS400_INIT_ERROR, scs400_mscb_to_float(), SCS400_POS_PINT, SCS400_POS_POWER, SCS400_POS_TEMP, SCS400_TEMP_CHS, SCS400_INFO::settings, and SCS400_INFO::startup_error.

Referenced by scs400_in().

INT scs400_get_in_label ( SCS400_INFO info,
INT  channel,
char *  name 
)

at startup, after initialization of the DD, this routine allows to write default names into the ODB.

Return: FE_SUCCESS

Parameters
infois a pointer to the DD specific info structure
channelof the name to be set
namepointer to the ODB name

Definition at line 440 of file scs400.c.

References SCS400_SETTINGS::pint, SCS400_SETTINGS::power, SCS400_TEMP_CHS, SCS400_INFO::settings, and SCS400_SETTINGS::temp.

Referenced by scs400_in().

INT scs400_get_out_label ( SCS400_INFO info,
INT  channel,
char *  name 
)

at startup, after initialization of the DD, this routine allows to write default names into the ODB.

Return: FE_SUCCESS

Parameters
infois a pointer to the DD specific info structure
channelof the name to be set
namepointer to the ODB name

Definition at line 463 of file scs400.c.

References SCS400_SETTINGS::demand, SCS400_SETTINGS::gain, SCS400_SETTINGS::offset, SCS400_SETTINGS::period, SCS400_SETTINGS::rate, SCS400_TEMP_CHS, and SCS400_INFO::settings.

Referenced by scs400_out().

INT scs400_in ( INT  cmd,
  ... 
)

MIDAS device driver for the MSCB thermo element card (input channels).

Definition at line 604 of file scs400.c.

References hKey, info, scs400_exit(), scs400_get(), scs400_get_in_label(), and scs400_in_init().

INT scs400_in_init ( HNDLE  hKey,
void **  pinfo,
INT  channels 
)

Initializes the thermo element MSCB device driver, i.e. generates all the necessary structures in the ODB if necessary, and initializes the MSCB. Furthermore it makes some consitency checks to verify that the addressed module is indeed a thermo element MSCB card.

Return:

  • FE_SUCCESS if everything went smooth
  • FE_ERR_ODB otherwise
Parameters
hKeyis the device driver handle given from the class driver
pinfois needed to store the internal info structure
channelsis the number of channels of the device (from the class driver)

Definition at line 183 of file scs400.c.

References SCS400_INFO::cint_width, SCS400_INFO::cprop_width, SCS400_INFO::demand_width, SCS400_INFO::errcount, SCS400_INFO::fd, hDB, info, SCS400_INFO::lasterrtime, SCS400_SETTINGS::node_addr, SCS400_INFO::offset_width, SCS400_INFO::pint_width, SCS400_SETTINGS::port, SCS400_INFO::pwr_width, SCS400_INFO::read_timer, SCS400_MSCB_DEBUG, SCS400_NOVARS, SCS400_POS_CINT, SCS400_POS_CPROP, SCS400_POS_DEMAND, SCS400_POS_OFFSET, SCS400_POS_PINT, SCS400_POS_POWER, SCS400_POS_TEMP, SCS400_SETTINGS_STR, SCS400_TEMP_CHS, SCS400_INFO::settings, SCS400_INFO::startup_error, and SCS400_INFO::temp_width.

Referenced by scs400_in().

float scs400_mscb_to_float ( char *  data,
int  index 
)
Parameters
data
index

Definition at line 486 of file scs400.c.

Referenced by scs400_get().

INT scs400_out ( INT  cmd,
  ... 
)

MIDAS device driver for the MSCB thermo element card (output channels).

Definition at line 655 of file scs400.c.

References hKey, info, scs400_get_out_label(), scs400_out_init(), and scs400_set().

INT scs400_out_init ( HNDLE  hKey,
void **  pinfo,
INT  channels 
)

Passes the info pointer to the class driver, all the rest is done in the scs400_in_init routine.

Return:

  • FE_SUCCESS if everything went smooth
  • FE_ERR_ODB otherwise
Parameters
hKeyis the device driver handle given from the class driver
pinfois needed to store the internal info structure
channelsis the number of channels of the device (from the class driver)

Definition at line 327 of file scs400.c.

References hDB, and info.

Referenced by scs400_out().

INT scs400_set ( SCS400_INFO info,
INT  channel,
float  value 
)

sets the power or offset values of the thermo element MSCB card.

Return: FE_SUCCESS

Parameters
infois a pointer to the DD specific info structure
channelto be set
valueto be set

Definition at line 365 of file scs400.c.

References SCS400_SETTINGS::detailed_msg, SCS400_INFO::errcount, SCS400_INFO::fd, SCS400_INFO::lasterrtime, SCS400_SETTINGS::node_addr, SCS400_INFO::pwr_width, SCS400_DELTA_TIME_ERROR, SCS400_MAX_ERROR, SCS400_POS_CINT, SCS400_POS_CPROP, SCS400_POS_OFFSET, SCS400_POS_PERIOD, SCS400_TEMP_CHS, SCS400_INFO::settings, and SCS400_INFO::startup_error.

Referenced by scs400_out().

Variable Documentation

SCS400_INFO* info

global info structure, in/out-init routines need the same structure

global info structure, in/out-init routines need the same structure

Definition at line 166 of file scs400.c.