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

Go to the source code of this file.

Data Structures

struct  DANFYSIK_SETTINGS
 Stores all the parameters the device driver needs. More...
 
struct  DANFYSIK_INFO
 

Macros

#define DANFYSIK_INIT_ERROR   -2
 tag: initializing error More...
 
#define DANFYSIK_READ_ERROR   -1
 tag: read error More...
 
#define DANFYSIK_TIME_OUT   2000
 timeout in (ms) for the communication between pc and danfysik More...
 
#define DANFYSIK_RECONNECTION_TIMEOUT   10
 timeout in (sec) for before trying to reconnect again (after a communication breakdown) More...
 
#define DANFYSIK_IN_CH   5
 number of input channels More...
 
#define DANFYSIK_OUT_CH   4
 number of output channels More...
 
#define DANFYSIK_ETS_LOGOUT_SLEEP   10000
 sleep time (us) between the telnet commands of the ets_logout More...
 
#define DANFYSIK_MAX_READBACK_FAILURE   5
 maximum number of readback failures before a reconnect will take place More...
 
#define DANFYSIK_MAX_EMPTY_READBACK_ERR   10
 maximum number of empty readback errors More...
 
#define DELTA_TIME_ERROR   3600
 reset error counter after DELTA_TIME_ERROR seconds More...
 
#define DANFYSIK_STATUS_OFF   0x800000
 
#define DANFYSIK_STATUS_LOCAL   0x400000
 
#define DANFYSIK_INTERLOCK_EXT_4   0x200000
 
#define DANFYSIK_SPARE_1   0x100000
 
#define DANFYSIK_SPARE_2   0x080000
 
#define DANFYSIK_SPARE_3   0x040000
 
#define DANFYSIK_PERCENTAGE   0x020000
 
#define DANFYSIK_INTERLOCK_EXT_1   0x010000
 
#define DANFYSIK_STATUS_STANDBY   0x008000
 
#define DANFYSIK_INTERLOCK_SUM   0x004000
 
#define DANFYSIK_INTERLOCK_DC_OVER_CURRENT   0x002000
 
#define DANFYSIK_INTERLOCK_OVER_VOLTAGE_PROTECTION   0x001000
 
#define DANFYSIK_STATUS_ON   0x000800
 
#define DANFYSIK_INTERLOCK_EXT_2   0x000400
 
#define DANFYSIK_INTERLOCK_MAINS_FAILURE   0x000200
 
#define DANFYSIK_STATUS_CURRENT_LIMIT   0x000100
 
#define DANFYSIK_INTERLOCK_EARTH_LEAKAGE_FAILURE   0x000080
 
#define DANFYSIK_INTERLOCK_CONVERTER_OVER_VOLTAGE   0x000040
 
#define DANFYSIK_INTERLOCK_MPS_OVERTEMPERATURE   0x000020
 
#define DANFYSIK_SPARE_4   0x000010
 
#define DANFYSIK_SPARE_5   0x000008
 
#define DANFYSIK_INTERLOCK_EXT_3   0x000004
 
#define DANFYSIK_STATUS_MPS_NOT_READY   0x000002
 
#define DANFYSIK_INTERLOCK_MPS_FAN_FAULT   0x000001
 
#define DANFYSIK_SETTINGS_STR   "\Detailed Messages = INT : 0\n\ETS_IN_USE = INT : 1\n\Input Names = STRING[5] : \n\[32] Remote (read back)\n\[32] Current Set Value (A) (readback)\n\[32] Output Voltage (V)\n\[32] Output Current (A)\n\[32] Status\n\Output Names = STRING[4] : \n\[32] Remote\n\[32] State (0 off, 1 on, 2 reset)\n\[32] Set Current (A)\n\[32] Current Limit (A)\n\Max. Current = FLOAT : 20.f\n\Max. Voltage = FLOAT : 75.f\n\Next Read Attempt (ms) = DWORD : 75\n\"
 Initializing string for the struct DANFYSIK_SETTINGS. More...
 

Functions

void danfysik_strip_rubbish (char *str_in, char *str_clean)
 
INT danfysik_error_read (int channel, char *str)
 
void danfysik_decode_status (DANFYSIK_INFO *info, char *str)
 
INT danfysik_in_init (HNDLE hKey, void **pinfo, INT channels, INT(*bd)(INT cmd,...))
 
INT danfysik_out_init (HNDLE hKey, void **pinfo, INT channels, INT(*bd)(INT cmd,...))
 
INT danfysik_exit (DANFYSIK_INFO *info)
 
INT danfysik_set (DANFYSIK_INFO *info, INT channel, float value)
 
INT danfysik_in_get_label (DANFYSIK_INFO *info, INT channel, char *name)
 
INT danfysik_out_get_label (DANFYSIK_INFO *info, INT channel, char *name)
 
INT danfysik_get (DANFYSIK_INFO *info, INT channel, float *pvalue)
 
INT danfysik_in (INT cmd,...)
 
INT danfysik_out (INT cmd,...)
 

Variables

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

Macro Definition Documentation

#define DANFYSIK_ETS_LOGOUT_SLEEP   10000

sleep time (us) between the telnet commands of the ets_logout

Definition at line 38 of file danfysik.c.

Referenced by danfysik_get().

#define DANFYSIK_IN_CH   5

number of input channels

Definition at line 33 of file danfysik.c.

#define DANFYSIK_INIT_ERROR   -2

tag: initializing error

Definition at line 24 of file danfysik.c.

Referenced by danfysik_get().

#define DANFYSIK_INTERLOCK_CONVERTER_OVER_VOLTAGE   0x000040

Definition at line 66 of file danfysik.c.

Referenced by danfysik_decode_status().

#define DANFYSIK_INTERLOCK_DC_OVER_CURRENT   0x002000

Definition at line 59 of file danfysik.c.

Referenced by danfysik_decode_status().

#define DANFYSIK_INTERLOCK_EARTH_LEAKAGE_FAILURE   0x000080

Definition at line 65 of file danfysik.c.

Referenced by danfysik_decode_status().

#define DANFYSIK_INTERLOCK_EXT_1   0x010000

Definition at line 56 of file danfysik.c.

Referenced by danfysik_decode_status().

#define DANFYSIK_INTERLOCK_EXT_2   0x000400

Definition at line 62 of file danfysik.c.

Referenced by danfysik_decode_status().

#define DANFYSIK_INTERLOCK_EXT_3   0x000004

Definition at line 70 of file danfysik.c.

Referenced by danfysik_decode_status().

#define DANFYSIK_INTERLOCK_EXT_4   0x200000

Definition at line 51 of file danfysik.c.

Referenced by danfysik_decode_status().

#define DANFYSIK_INTERLOCK_MAINS_FAILURE   0x000200

Definition at line 63 of file danfysik.c.

Referenced by danfysik_decode_status().

#define DANFYSIK_INTERLOCK_MPS_FAN_FAULT   0x000001

Definition at line 72 of file danfysik.c.

Referenced by danfysik_decode_status().

#define DANFYSIK_INTERLOCK_MPS_OVERTEMPERATURE   0x000020

Definition at line 67 of file danfysik.c.

Referenced by danfysik_decode_status().

#define DANFYSIK_INTERLOCK_OVER_VOLTAGE_PROTECTION   0x001000

Definition at line 60 of file danfysik.c.

Referenced by danfysik_decode_status().

#define DANFYSIK_INTERLOCK_SUM   0x004000

Definition at line 58 of file danfysik.c.

#define DANFYSIK_MAX_EMPTY_READBACK_ERR   10

maximum number of empty readback errors

Definition at line 44 of file danfysik.c.

Referenced by danfysik_get().

#define DANFYSIK_MAX_READBACK_FAILURE   5

maximum number of readback failures before a reconnect will take place

Definition at line 42 of file danfysik.c.

Referenced by danfysik_get().

#define DANFYSIK_OUT_CH   4

number of output channels

Definition at line 35 of file danfysik.c.

#define DANFYSIK_PERCENTAGE   0x020000

Definition at line 55 of file danfysik.c.

Referenced by danfysik_decode_status().

#define DANFYSIK_READ_ERROR   -1

tag: read error

Definition at line 26 of file danfysik.c.

Referenced by danfysik_get().

#define DANFYSIK_RECONNECTION_TIMEOUT   10

timeout in (sec) for before trying to reconnect again (after a communication breakdown)

Definition at line 30 of file danfysik.c.

Referenced by danfysik_get().

#define DANFYSIK_SETTINGS_STR   "\Detailed Messages = INT : 0\n\ETS_IN_USE = INT : 1\n\Input Names = STRING[5] : \n\[32] Remote (read back)\n\[32] Current Set Value (A) (readback)\n\[32] Output Voltage (V)\n\[32] Output Current (A)\n\[32] Status\n\Output Names = STRING[4] : \n\[32] Remote\n\[32] State (0 off, 1 on, 2 reset)\n\[32] Set Current (A)\n\[32] Current Limit (A)\n\Max. Current = FLOAT : 20.f\n\Max. Voltage = FLOAT : 75.f\n\Next Read Attempt (ms) = DWORD : 75\n\"

Initializing string for the struct DANFYSIK_SETTINGS.

Definition at line 86 of file danfysik.c.

Referenced by danfysik_in_init().

#define DANFYSIK_SPARE_1   0x100000

Definition at line 52 of file danfysik.c.

#define DANFYSIK_SPARE_2   0x080000

Definition at line 53 of file danfysik.c.

#define DANFYSIK_SPARE_3   0x040000

Definition at line 54 of file danfysik.c.

#define DANFYSIK_SPARE_4   0x000010

Definition at line 68 of file danfysik.c.

#define DANFYSIK_SPARE_5   0x000008

Definition at line 69 of file danfysik.c.

#define DANFYSIK_STATUS_CURRENT_LIMIT   0x000100

Definition at line 64 of file danfysik.c.

Referenced by danfysik_decode_status().

#define DANFYSIK_STATUS_LOCAL   0x400000

Definition at line 50 of file danfysik.c.

Referenced by danfysik_decode_status().

#define DANFYSIK_STATUS_MPS_NOT_READY   0x000002

Definition at line 71 of file danfysik.c.

Referenced by danfysik_decode_status().

#define DANFYSIK_STATUS_OFF   0x800000

Definition at line 49 of file danfysik.c.

Referenced by danfysik_decode_status().

#define DANFYSIK_STATUS_ON   0x000800

Definition at line 61 of file danfysik.c.

Referenced by danfysik_decode_status().

#define DANFYSIK_STATUS_STANDBY   0x008000

Definition at line 57 of file danfysik.c.

Referenced by danfysik_decode_status().

#define DANFYSIK_TIME_OUT   2000

timeout in (ms) for the communication between pc and danfysik

Definition at line 28 of file danfysik.c.

Referenced by danfysik_get(), and danfysik_in_init().

#define DELTA_TIME_ERROR   3600

reset error counter after DELTA_TIME_ERROR seconds

Definition at line 46 of file danfysik.c.

Referenced by danfysik_get().

Function Documentation

INT danfysik_error_read ( int  channel,
char *  str 
)

Checks if there was any error message response form a danfysik request.

Return:

  • 1 (true) if an error occured
  • 0 (false) otherwise
Parameters
channel
strresponse string from the danfysik power supply.

Definition at line 164 of file danfysik.c.

References DANFYSIK_INFO::danfysik_settings, DANFYSIK_SETTINGS::detailed_msg, DANFYSIK_INFO::empty_readback_error, and DANFYSIK_INFO::errcount.

Referenced by danfysik_get().

INT danfysik_exit ( DANFYSIK_INFO info)

quits the bus driver and free's the memory allocated for the info structure

DANFYSIK_INFO

.

Return: FE_SUCCESS

Parameters
infois a pointer to the DD specific info structure

Definition at line 471 of file danfysik.c.

References DANFYSIK_INFO::bd, and DANFYSIK_INFO::bd_info.

Referenced by danfysik_in().

INT danfysik_in ( INT  cmd,
  ... 
)

danfysik power supply device driver (DD) input part. It is handling the communication between the danfysik power supply and midas. The danfysik is used as a current source for electromagnets in our $\mathrm{LE-\mu SR}$ setup.

Definition at line 804 of file danfysik.c.

References danfysik_exit(), danfysik_get(), danfysik_in_get_label(), danfysik_in_init(), hKey, and info.

INT danfysik_in_get_label ( DANFYSIK_INFO info,
INT  channel,
char *  name 
)

at startup, after initialization of the DD, this routine allows to write default names of the input channels 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 584 of file danfysik.c.

References DANFYSIK_INFO::danfysik_settings, and DANFYSIK_SETTINGS::in_names.

Referenced by danfysik_in().

INT danfysik_in_init ( HNDLE  hKey,
void **  pinfo,
INT  channels,
INT(*)(INT cmd,...)  bd 
)

Initializes the danfysik device driver, i.e. generates all the necessary structures in the ODB if necessary, initializes the bus driver and the danfysik.

Return:

  • FE_SUCCESS if OK
  • FE_ERR_ODB in case of a severe error
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)
bdis a pointer to the bus driver

Definition at line 337 of file danfysik.c.

References DANFYSIK_INFO::bd, DANFYSIK_INFO::bd_connected, DANFYSIK_INFO::bd_info, danfysik_decode_status(), DANFYSIK_INFO::danfysik_remote, DANFYSIK_INFO::danfysik_settings, DANFYSIK_SETTINGS_STR, DANFYSIK_INFO::danfysik_status, danfysik_strip_rubbish(), DANFYSIK_TIME_OUT, DANFYSIK_SETTINGS::detailed_msg, DANFYSIK_INFO::empty_readback_error, DANFYSIK_INFO::errcount, DANFYSIK_INFO::first_bd_error, hDB, DANFYSIK_INFO::hDB, hKey, DANFYSIK_INFO::hkey, info, DANFYSIK_INFO::last_reconnect, DANFYSIK_INFO::lasterrtime, DANFYSIK_INFO::num_channels, DANFYSIK_INFO::readback_failure, DANFYSIK_INFO::reconnection_failures, DANFYSIK_INFO::soft_current_limit, DANFYSIK_INFO::startup_error, and DANFYSIK_INFO::time_to_read.

Referenced by danfysik_in().

INT danfysik_out ( INT  cmd,
  ... 
)

danfysik power supply device driver (DD) output part. It is handling the communication between the danfysik power supply and midas. The danfysik is used as a current source for electromagnets in our $\mathrm{LE-\mu SR}$ setup.

Definition at line 855 of file danfysik.c.

References danfysik_out_get_label(), danfysik_out_init(), danfysik_set(), hKey, and info.

INT danfysik_out_get_label ( DANFYSIK_INFO info,
INT  channel,
char *  name 
)

at startup, after initialization of the DD, this routine allows to write default names of the output channels 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 601 of file danfysik.c.

References DANFYSIK_INFO::danfysik_settings, and DANFYSIK_SETTINGS::out_names.

Referenced by danfysik_out().

INT danfysik_out_init ( HNDLE  hKey,
void **  pinfo,
INT  channels,
INT(*)(INT cmd,...)  bd 
)

Initializes the danfysik device driver, i.e. generates all the necessary structures in the ODB if necessary, initializes the bus driver and the danfysik.

Return: FE_SUCCESS

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)
bdis a pointer to the bus driver

Definition at line 455 of file danfysik.c.

References info.

Referenced by danfysik_out().

INT danfysik_set ( DANFYSIK_INFO info,
INT  channel,
float  value 
)

sends a new value to the danfysik power supply

Return: FE_SUCCESS

Parameters
infois a pointer to the DD specific info structure
channelfor which channel is this command
valueto be set.

Definition at line 490 of file danfysik.c.

References DANFYSIK_INFO::bd_connected, DANFYSIK_INFO::danfysik_remote, DANFYSIK_INFO::danfysik_settings, danfysik_strip_rubbish(), DANFYSIK_SETTINGS::detailed_msg, DANFYSIK_INFO::first_bd_error, DANFYSIK_INFO::soft_current_limit, and DANFYSIK_INFO::startup_error.

Referenced by danfysik_out().

void danfysik_strip_rubbish ( char *  str_in,
char *  str_clean 
)

The readback string from the danfysik power supply is sometimes starting with some rubbish characters > ascii 127. This routine is simply filtering them out.

Parameters
str_in
str_clean

Definition at line 141 of file danfysik.c.

Referenced by danfysik_get(), danfysik_in_init(), and danfysik_set().

Variable Documentation

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 130 of file danfysik.c.