Low-Energy Muon (LEM) Experiment
0.5.2
|
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <math.h>
#include "midas.h"
#include "steppermotor.h"
#include "ets_logout.h"
#include "lemSCWatchdog.h"
Go to the source code of this file.
Data Structures | |
struct | SM_INTERNAL |
stores internal information More... | |
struct | SM_INDIVIDUAL |
structure to store information on individual steppermotor More... | |
struct | SM_SETTINGS |
stores internal informations within the DD. More... | |
struct | SM_INFO |
Macros | |
#define | SM_ETS_LOGOUT_SLEEP 10000 |
sleep time (us) between the telnet commands of the ets_logout More... | |
#define | SM_TIME_OUT 2000 |
time out in msecs for read (rs232) More... | |
#define | SM_TIME_BETWEEN_SETS 10 |
minimum time between settings of steppermotor to allow odb updates More... | |
#define | SM_ACCURACY 1.0 |
condition for alarm on manual changes More... | |
#define | SM_RECONNECTION_TIMEOUT 5 |
timeout in (sec) between logout terminal server an reconnection trial More... | |
#define | SM_MAX_READBACK_FAILURE 5 |
maximum number of readback failures before a reconnect will take place More... | |
#define | SM_MAX_RECONNECTION_FAILURE 5 |
maximum number of reconnections before bailing off More... | |
#define | SM_MAX_ERROR 3 |
maximum number of error messages More... | |
#define | SM_DELTA_TIME_ERROR 3600 |
reset error counter after SM_DELTA_TIME_ERROR seconds More... | |
#define | SM_MAX_TRY 10 |
maximum number of communication attempts More... | |
#define | SM_WAIT 500 |
time (ms) to wait between commands More... | |
#define | SM_INIT_ERROR -2 |
initialize error tag More... | |
#define | SM_READ_ERROR -1 |
read error tag More... | |
#define | SM_DEBUG 0 |
debug tag, if set to TRUE, additional messages will be displayed at execution time More... | |
#define | SM_K2700_CH 20 |
#define | SM_K2700_SIG_CH 4 |
#define | SM_K2700_POT_CH 2 |
#define | SM_SCS900_CH 32 |
#define | SM_SCS900_SIG_CH 4 |
#define | SM_SCS900_POT_CH 2 |
#define | SM_SCS2001M_CH 44 |
#define | SM_SCS2001M_SIG_CH 14 |
#define | SM_SCS2001M_POT_CH 15 |
#define | SM_INTERNAL_STR "\ODB Offset = INT : 12\n\Detailed Messages = INT : 0\n\ETS_IN_USE = INT : 1\n\SCW_IN_USE = INT : 0\n\No Connection = INT : 1\n\Reconnection Timeout = INT : 10\n\Read Timeout = INT : 5\n" |
initializing string for SM_INTERNAL More... | |
Functions | |
INT | sm_send_rcv (SM_INFO *info, char *cmd, char *str) |
INT | sm_send (SM_INFO *info, char *cmd) |
void | sm_no_connection (SM_INFO *info, INT value) |
float | sm_read_potmeter (SM_INFO *info) |
int | check_serialnumber_and_maxima (SM_INFO *info) |
float | sm_read_position (SM_INFO *info) |
float | sm_read_velocity (SM_INFO *info) |
INT | sm_in_init (HNDLE hKey, void **pinfo, INT channels, INT(*bd)(INT cmd,...)) |
INT | sm_out_init (HNDLE hKey, void **pinfo, INT channels, INT(*bd)(INT cmd,...)) |
INT | sm_set (SM_INFO *info, float setpoint) |
INT | sm_get (SM_INFO *info, float *pvalue) |
INT | sm_out_get_default_name (SM_INFO *info, INT channel, char *name) |
INT | sm_in_get_default_name (SM_INFO *info, INT channel, char *name) |
INT | sm_switch (SM_INFO *info, float floatmodus) |
INT | sm_exit (SM_INFO *info) |
INT | SM_in (INT cmd,...) |
INT | SM_out (INT cmd,...) |
Variables | |
SM_INFO * | info |
global info structure, in/out-init routines need the same structure More... | |
#define SM_ACCURACY 1.0 |
condition for alarm on manual changes
Definition at line 35 of file steppermotor.c.
Referenced by sm_in_init(), sm_set(), and sm_switch().
#define SM_DEBUG 0 |
debug tag, if set to TRUE, additional messages will be displayed at execution time
Definition at line 55 of file steppermotor.c.
Referenced by sm_get(), sm_in_init(), sm_read_potmeter(), and sm_switch().
#define SM_DELTA_TIME_ERROR 3600 |
reset error counter after SM_DELTA_TIME_ERROR seconds
Definition at line 48 of file steppermotor.c.
#define SM_ETS_LOGOUT_SLEEP 10000 |
sleep time (us) between the telnet commands of the ets_logout
Definition at line 31 of file steppermotor.c.
#define SM_INIT_ERROR -2 |
initialize error tag
Definition at line 51 of file steppermotor.c.
#define SM_INTERNAL_STR "\ODB Offset = INT : 12\n\Detailed Messages = INT : 0\n\ETS_IN_USE = INT : 1\n\SCW_IN_USE = INT : 0\n\No Connection = INT : 1\n\Reconnection Timeout = INT : 10\n\Read Timeout = INT : 5\n" |
initializing string for SM_INTERNAL
Definition at line 79 of file steppermotor.c.
Referenced by sm_in_init().
#define SM_K2700_CH 20 |
Definition at line 57 of file steppermotor.c.
Referenced by sm_in_init().
#define SM_K2700_POT_CH 2 |
Definition at line 59 of file steppermotor.c.
Referenced by sm_in_init(), and sm_read_potmeter().
#define SM_K2700_SIG_CH 4 |
Definition at line 58 of file steppermotor.c.
Referenced by sm_in_init().
#define SM_MAX_ERROR 3 |
maximum number of error messages
Definition at line 47 of file steppermotor.c.
#define SM_MAX_READBACK_FAILURE 5 |
maximum number of readback failures before a reconnect will take place
Definition at line 42 of file steppermotor.c.
#define SM_MAX_RECONNECTION_FAILURE 5 |
maximum number of reconnections before bailing off
Definition at line 44 of file steppermotor.c.
Referenced by sm_set().
#define SM_MAX_TRY 10 |
maximum number of communication attempts
Definition at line 49 of file steppermotor.c.
Referenced by sm_send_rcv().
#define SM_READ_ERROR -1 |
read error tag
Definition at line 52 of file steppermotor.c.
#define SM_RECONNECTION_TIMEOUT 5 |
timeout in (sec) between logout terminal server an reconnection trial
Definition at line 40 of file steppermotor.c.
Referenced by sm_set().
#define SM_SCS2001M_CH 44 |
Definition at line 63 of file steppermotor.c.
Referenced by sm_in_init().
#define SM_SCS2001M_POT_CH 15 |
Definition at line 65 of file steppermotor.c.
Referenced by sm_in_init(), and sm_read_potmeter().
#define SM_SCS2001M_SIG_CH 14 |
Definition at line 64 of file steppermotor.c.
Referenced by sm_in_init().
#define SM_SCS900_CH 32 |
Definition at line 60 of file steppermotor.c.
Referenced by sm_in_init().
#define SM_SCS900_POT_CH 2 |
Definition at line 62 of file steppermotor.c.
Referenced by sm_in_init(), and sm_read_potmeter().
#define SM_SCS900_SIG_CH 4 |
Definition at line 61 of file steppermotor.c.
Referenced by sm_in_init().
#define SM_TIME_BETWEEN_SETS 10 |
minimum time between settings of steppermotor to allow odb updates
Definition at line 34 of file steppermotor.c.
Referenced by sm_set().
#define SM_TIME_OUT 2000 |
time out in msecs for read (rs232)
Definition at line 33 of file steppermotor.c.
Referenced by sm_send_rcv().
#define SM_WAIT 500 |
time (ms) to wait between commands
Definition at line 50 of file steppermotor.c.
Referenced by sm_send_rcv().
int check_serialnumber_and_maxima | ( | SM_INFO * | info | ) |
Checking serial number, checks the serial number of the steppermotordriver
Returns:
-999 : bus not connected
1 : length of serial number not correct
j+10 : character j of serialnumber not correct
Definition at line 256 of file steppermotor.c.
References SM_INFO::bd_connected, SM_SETTINGS::individual, SM_INDIVIDUAL::mhc, SM_INFO::sm_in_use, sm_send(), sm_send_rcv(), and SM_INFO::sm_settings.
Referenced by sm_in_init(), and sm_switch().
INT sm_exit | ( | SM_INFO * | info | ) |
terminates the bus driver and free's the memory allocated for the info structure SM_INFO.
Return: FE_SUCCESS
info | is a pointer to the DD specific info structure |
Definition at line 1170 of file steppermotor.c.
References SM_INFO::bd, SM_INFO::bd_connected, SM_INFO::bd_info, and SM_INFO::data.
Referenced by SM_in().
INT sm_get | ( | SM_INFO * | info, |
float * | pvalue | ||
) |
Obtains the opening in percent if sm is in_use,
otherwise -300.0 if the steppermotor is not in use
or opening minus 1000.0 if the opening is out of range (<-10 or >120)
Return: FE_SUCCESS
info | is a pointer to the DD specific info structure |
pvalue | a pointer to where the results will be stored |
Definition at line 884 of file steppermotor.c.
References SM_DEBUG, SM_INFO::sm_in_use, sm_read_potmeter(), and SM_INFO::startup_error.
Referenced by SM_in().
INT SM_in | ( | INT | cmd, |
... | |||
) |
steppermotor device driver (DD). It is handling the communication between the steppermotor and midas.
steppermotor_in is the part, which handles the communication steppermotor->MIDAS
RS232: 9600 baud, 8 data bits, 1 stop bit, no parity bit, no hardware protocol, no software protocol, termination: \ r\n (CR LF)
Device Driver info structure entries are organized as:
sm_settings |__ closed_potmeter_reading
Definition at line 1186 of file steppermotor.c.
References hKey, info, sm_exit(), sm_get(), sm_in_get_default_name(), and sm_in_init().
INT sm_in_get_default_name | ( | SM_INFO * | info, |
INT | channel, | ||
char * | name | ||
) |
at startup, after initialization of the DD, this routine allows to write default names of the in-channels into the ODB.
Return: FE_SUCCESS
info | is a pointer to the DD specific info structure |
channel | of the name to be set |
name | pointer to the ODB name |
Definition at line 973 of file steppermotor.c.
References SM_INFO::sm_in_name.
Referenced by SM_in().
INT sm_in_init | ( | HNDLE | hKey, |
void ** | pinfo, | ||
INT | channels, | ||
INT(*)(INT cmd,...) | bd | ||
) |
Initializes the SM device driver, i.e. generates all the necessary structures in the ODB if necessary, initializes the bus driver.
Return:
hKey | is the device driver handle given from the class driver |
pinfo | is needed to store the internal info structure |
channels | is the number of channels of the device (from the class driver) |
bd | is a pointer to the 0bus driver |
Definition at line 362 of file steppermotor.c.
References SM_INFO::bd, SM_INFO::bd_connected, SM_INFO::bd_info, check_serialnumber_and_maxima(), SM_INFO::data, SM_INTERNAL::detailed_msg, SM_INFO::first_bd_error, SM_INFO::FromAutoPress, hDB, SM_INFO::hDB, hKey, SM_INFO::hkey, SM_INFO::hkey_no_connection, SM_SETTINGS::individual, info, SM_SETTINGS::intern, SM_INFO::last_reconnect, SM_INFO::last_set_time, SM_INFO::modus, SM_INTERNAL::odb_offset, SM_INFO::position, SM_SETTINGS::read_back_device, SM_INFO::setpoint, SM_INDIVIDUAL::signature, SM_INFO::signature, SM_ACCURACY, SM_DEBUG, SM_INFO::sm_in_name, SM_INFO::sm_in_use, SM_INTERNAL_STR, SM_K2700_CH, SM_K2700_POT_CH, SM_K2700_SIG_CH, SM_INFO::sm_modus_name, sm_no_connection(), SM_INFO::sm_out_name, sm_read_position(), sm_read_potmeter(), sm_read_velocity(), SM_SCS2001M_CH, SM_SCS2001M_POT_CH, SM_SCS2001M_SIG_CH, SM_SCS900_CH, SM_SCS900_POT_CH, SM_SCS900_SIG_CH, SM_INFO::sm_settings, SM_INFO::startup_error, SM_INFO::velocity, and SM_INFO::voltage.
Referenced by SM_in().
void sm_no_connection | ( | SM_INFO * | info, |
INT | value | ||
) |
Set's the no connection flag.
info | is a pointer to the DD specific info structure. |
value | equal 1 if the connection is available, otherwise 0. |
Definition at line 236 of file steppermotor.c.
References SM_INFO::bd_connected, SM_INFO::hDB, and SM_INFO::hkey_no_connection.
Referenced by sm_in_init(), sm_send_rcv(), and sm_switch().
INT SM_out | ( | INT | cmd, |
... | |||
) |
steppermotor device driver (DD). It is handling the communication between the steppermotor and midas.
steppermotor_out is the part, which handles the communication steppermotor<-MIDAS
Definition at line 1236 of file steppermotor.c.
References hKey, info, sm_out_get_default_name(), sm_out_init(), sm_set(), and sm_switch().
INT sm_out_get_default_name | ( | SM_INFO * | info, |
INT | channel, | ||
char * | name | ||
) |
at startup, after initialization of the DD, this routine allows to write default names of the out-channels into the ODB.
Return: FE_SUCCESS
info | is a pointer to the DD specific info structure |
channel | of the name to be set |
name | pointer to the ODB name |
Definition at line 951 of file steppermotor.c.
References SM_INFO::sm_modus_name, and SM_INFO::sm_out_name.
Referenced by SM_out().
INT sm_out_init | ( | HNDLE | hKey, |
void ** | pinfo, | ||
INT | channels, | ||
INT(*)(INT cmd,...) | bd | ||
) |
Initializes the SM device0 driver.
Return:
hKey | is the device driver handle given from the class driver |
pinfo | is needed to store the internal info structure |
channels | is the number of channels of the device (from the class driver) |
bd | is a pointer to the bus driver |
Definition at line 673 of file steppermotor.c.
Referenced by SM_out().
float sm_read_position | ( | SM_INFO * | info | ) |
Reads postion from the motor-driver (PRINT POS)
Returns position (float)
Definition at line 295 of file steppermotor.c.
References SM_INFO::bd_connected, SM_INTERNAL::detailed_msg, SM_SETTINGS::intern, sm_send_rcv(), and SM_INFO::sm_settings.
Referenced by sm_in_init(), sm_set(), and sm_switch().
float sm_read_potmeter | ( | SM_INFO * | info | ) |
Reads the voltage from the potentiometer using the read back devise.
It use info->settings.pcurve and info->settings.closed_voltage to translate the voltage into a opening in degrees
Returns opening of the needlevalve in degrees
Definition at line 918 of file steppermotor.c.
References SM_INFO::data, SM_SETTINGS::individual, SM_INDIVIDUAL::pcurve, SM_SETTINGS::read_back_device, SM_DEBUG, SM_INFO::sm_in_use, SM_K2700_POT_CH, SM_SCS2001M_POT_CH, SM_SCS900_POT_CH, SM_INFO::sm_settings, and SM_INFO::voltage.
Referenced by sm_get(), sm_in_init(), sm_set(), and sm_switch().
float sm_read_velocity | ( | SM_INFO * | info | ) |
Reads maximum velocity from the motor-driver PRINT VM
Returns maximum velocity in degrees per second (float)
Definition at line 326 of file steppermotor.c.
References SM_INFO::bd_connected, SM_INTERNAL::detailed_msg, SM_SETTINGS::intern, sm_send_rcv(), and SM_INFO::sm_settings.
Referenced by sm_in_init(), and sm_switch().
INT sm_send | ( | SM_INFO * | info, |
char * | cmd | ||
) |
send/recieve routine. loops SM_MAX_TRY times if there would be a communication problem.
Return: FE_SUCCESS
cmd | command string |
Definition at line 211 of file steppermotor.c.
References SM_INFO::bd_connected, SM_INTERNAL::detailed_msg, SM_SETTINGS::intern, and SM_INFO::sm_settings.
Referenced by check_serialnumber_and_maxima(), and sm_set().
INT sm_send_rcv | ( | SM_INFO * | info, |
char * | cmd, | ||
char * | str | ||
) |
send/recieve routine. loops SM_MAX_TRY times if there would be a communication problem.
Return: number of read bytes
cmd | command string |
str | reply string |
Definition at line 162 of file steppermotor.c.
References SM_INFO::bd_connected, SM_INTERNAL::detailed_msg, SM_SETTINGS::intern, SM_MAX_TRY, sm_no_connection(), SM_INFO::sm_settings, SM_TIME_OUT, and SM_WAIT.
Referenced by check_serialnumber_and_maxima(), sm_read_position(), and sm_read_velocity().
INT sm_set | ( | SM_INFO * | info, |
float | setpoint | ||
) |
Sends absolute set command to the steppermotor
Return: FE_SUCCESS
info | is a pointer to the DD specific info structure |
setpoint | is the requested opening in percent |
Definition at line 691 of file steppermotor.c.
References SM_INFO::bd, SM_INFO::bd_connected, SM_INFO::bd_info, SM_INTERNAL::detailed_msg, SM_INFO::first_bd_error, SM_INFO::hkey, SM_SETTINGS::individual, SM_SETTINGS::intern, SM_INFO::last_reconnect, SM_INFO::last_set_time, SM_INDIVIDUAL::mac_close, SM_INDIVIDUAL::mac_open, SM_INFO::modus, SM_INDIVIDUAL::mrc_close, SM_INDIVIDUAL::mrc_open, SM_INFO::position, SM_INFO::reconnection_failures, SM_INFO::scw, SM_INTERNAL::scw_in_use, SM_INFO::setpoint, SM_ACCURACY, SM_INFO::sm_in_use, SM_MAX_RECONNECTION_FAILURE, sm_read_position(), sm_read_potmeter(), SM_RECONNECTION_TIMEOUT, sm_send(), SM_INFO::sm_settings, SM_TIME_BETWEEN_SETS, SM_INFO::startup_error, SM_INDIVIDUAL::valve_range, and SM_INFO::velocity.
Referenced by SM_out().
INT sm_switch | ( | SM_INFO * | info, |
float | floatmodus | ||
) |
Switches the steppermotor program between read_only (0), read_write(1) and automatic(2)
In the read_only case it tries to free the bus.
Return: FE_SUCCESS
info | is a pointer to the DD specific info structure |
floatmodus | is the new value for the info->modus |
Definition at line 987 of file steppermotor.c.
References SM_INFO::bd, SM_INFO::bd_connected, SM_INFO::bd_info, check_serialnumber_and_maxima(), SM_INTERNAL::detailed_msg, SM_INFO::FromAutoPress, SM_INFO::hDB, SM_INFO::hkey, SM_SETTINGS::intern, SM_INFO::modus, SM_INTERNAL::odb_offset, SM_INFO::position, SM_INFO::setpoint, SM_ACCURACY, SM_DEBUG, SM_INFO::sm_in_use, sm_no_connection(), sm_read_position(), sm_read_potmeter(), sm_read_velocity(), SM_INFO::sm_settings, SM_INFO::startup_error, and SM_INFO::velocity.
Referenced by SM_out().
SM_INFO* info |
global info structure, in/out-init routines need the same structure
Definition at line 152 of file steppermotor.c.