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

Go to the source code of this file.

Data Structures

struct  BH_IN_SETTINGS
 
struct  BH_OUT_SETTINGS
 
struct  BH_INFO
 

Macros

#define BH_TIME_OUT   2000
 timeout in (ms) for the communication between pc and bronkhorst More...
 
#define BH_RECONNECTION_TIMEOUT   5
 timeout in (sec) between logout terminal server an reconnection trial More...
 
#define BH_MAX_READBACK_FAILURE   5
 maximum number of readback failures before a reconnect will take place More...
 
#define BH_MAX_RECONNECTION_FAILURE   5
 maximum number of reconnections before bailing off More...
 
#define BH_MAX_ERROR   10
 maximum number of error messages More...
 
#define BH_DELTA_TIME_ERROR   3600
 reset error counter after BH_DELTA_TIME_ERROR seconds More...
 
#define BH_WAIT   500
 time (ms) to BH_WAIT between commands More...
 
#define BH_CMD_ERROR   -3
 unvalid command error More...
 
#define BH_INIT_ERROR   -2
 initialize error tag More...
 
#define BH_READ_ERROR   -1
 read error tag More...
 
#define BH_ETS_LOGOUT_SLEEP   10000
 sleep time (us) between the telnet commands of the ets_logout More...
 
#define BH_SUCCESS   1
 
#define BH_IN_SETTINGS_STR   "\Detailed Messages = INT : 0\n\ETS_IN_USE = INT : 1\n\SCW_IN_USE = INT : 0\n\Input = STRING[2]:\n\[32] BH Flow measured\n\[32] BH ValvePos Get\n\"
 initializing string for the BH_IN_SETTINGS structure. More...
 
#define BH_OUT_SETTINGS_STR   "\Output = STRING[2] :\n\[32] BH Flow setpoint\n\[32] BH ValvePos Set\n\"
 initializing string for the BH_OUT_SETTINGS structure. More...
 
#define BH_SCW_STR   "\Proc Name = STRING : [32]\n\PID = INT : -1\n\Log Name = STRING : [64]\n\DD Name = STRING : [32] bronkhorst\n\Last Updated = DWORD : 0\n\Timeout = DWORD : 180\n\"
 defines the slowcontrol default watchdog info structure More...
 

Functions

int bh_success (char *str, char *error_msg)
 
void hex2ascii (char *str, int len, char *result)
 
int bh_decode_number (char *rply, int decode_tag, char *err_msg, float *result)
 
int bh_decode_string (char *rply, char *err_msg, char *result)
 
INT bh_get_send_rcv (BH_INFO *info, INT cmd, char *result)
 
INT bh_set_send_rcv (BH_INFO *info, INT cmd, float value)
 
INT bh_get_cmd (char *str, int *decode_tag)
 
INT bh_in_init (HNDLE hKey, void **pinfo, INT channels, INT(*bd)(INT cmd,...))
 
INT bh_out_init (HNDLE hKey, void **pinfo, INT channels, INT(*bd)(INT cmd,...))
 
INT bh_exit (BH_INFO *info)
 
INT bh_set (BH_INFO *info, INT channel, float value)
 
INT bh_get (BH_INFO *info, INT channel, float *pvalue)
 
INT bh_in_get_label (BH_INFO *info, INT channel, char *name)
 
INT bh_out_get_label (BH_INFO *info, INT channel, char *name)
 
INT bh_flow_in (INT cmd,...)
 
INT bh_flow_out (INT cmd,...)
 

Variables

BH_INFOinfo
 global info structure since port (rs232 or terminal server) can only be initialized once. More...
 

Macro Definition Documentation

#define BH_CMD_ERROR   -3

unvalid command error

Definition at line 49 of file bronkhorst.c.

Referenced by bh_get().

#define BH_DELTA_TIME_ERROR   3600

reset error counter after BH_DELTA_TIME_ERROR seconds

Definition at line 45 of file bronkhorst.c.

Referenced by bh_get().

#define BH_ETS_LOGOUT_SLEEP   10000

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

Definition at line 54 of file bronkhorst.c.

Referenced by bh_get().

#define BH_IN_SETTINGS_STR   "\Detailed Messages = INT : 0\n\ETS_IN_USE = INT : 1\n\SCW_IN_USE = INT : 0\n\Input = STRING[2]:\n\[32] BH Flow measured\n\[32] BH ValvePos Get\n\"

initializing string for the BH_IN_SETTINGS structure.

Definition at line 159 of file bronkhorst.c.

Referenced by bh_in_init().

#define BH_INIT_ERROR   -2

initialize error tag

Definition at line 50 of file bronkhorst.c.

Referenced by bh_get().

#define BH_MAX_ERROR   10

maximum number of error messages

Definition at line 44 of file bronkhorst.c.

Referenced by bh_get(), bh_get_send_rcv(), bh_set(), and bh_set_send_rcv().

#define BH_MAX_READBACK_FAILURE   5

maximum number of readback failures before a reconnect will take place

Definition at line 39 of file bronkhorst.c.

Referenced by bh_get().

#define BH_MAX_RECONNECTION_FAILURE   5

maximum number of reconnections before bailing off

Definition at line 41 of file bronkhorst.c.

Referenced by bh_get().

#define BH_OUT_SETTINGS_STR   "\Output = STRING[2] :\n\[32] BH Flow setpoint\n\[32] BH ValvePos Set\n\"

initializing string for the BH_OUT_SETTINGS structure.

Definition at line 169 of file bronkhorst.c.

Referenced by bh_out_init().

#define BH_READ_ERROR   -1

read error tag

Definition at line 51 of file bronkhorst.c.

Referenced by bh_get().

#define BH_RECONNECTION_TIMEOUT   5

timeout in (sec) between logout terminal server an reconnection trial

Definition at line 37 of file bronkhorst.c.

Referenced by bh_get().

#define BH_SCW_STR   "\Proc Name = STRING : [32]\n\PID = INT : -1\n\Log Name = STRING : [64]\n\DD Name = STRING : [32] bronkhorst\n\Last Updated = DWORD : 0\n\Timeout = DWORD : 180\n\"

defines the slowcontrol default watchdog info structure

Definition at line 176 of file bronkhorst.c.

Referenced by bh_in_init().

#define BH_SUCCESS   1

bronkhorst <-> midas tags. def's starting with BH_ aren't documented here. For a detailed description of them see the bronkhorst manual 'RS232 INTERFACE with FLOW-BUS protocol' Doc. no.: 9.17.027 D

Definition at line 64 of file bronkhorst.c.

Referenced by bh_decode_number(), bh_decode_string(), bh_get(), bh_get_send_rcv(), bh_in_init(), bh_set(), bh_set_send_rcv(), and bh_success().

#define BH_TIME_OUT   2000

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

Definition at line 34 of file bronkhorst.c.

Referenced by bh_get_send_rcv(), and bh_set_send_rcv().

#define BH_WAIT   500

time (ms) to BH_WAIT between commands

Definition at line 47 of file bronkhorst.c.

Function Documentation

int bh_decode_number ( char *  rply,
int  decode_tag,
char *  err_msg,
float *  result 
)

if the return message of the flowcontroller is a number, this routine is used to decode the return string into a number.

Return:

  • BH_SUCCESS if everthing went fine
  • BH_DECODE_ERR otherwise
Parameters
rplyreturn string from flowcontroller
decode_tagBH_CHAR, BH_INTEGER, BH_FLOAT
err_msgerror message if something went wrong
resultdecoded value

Definition at line 418 of file bronkhorst.c.

References BH_SUCCESS.

Referenced by bh_get().

int bh_decode_string ( char *  rply,
char *  err_msg,
char *  result 
)

if the return message of the flowcontroller is a string, this routine is used to decode the return string.

Return:

  • BH_SUCCESS if everthing went fine
  • BH_DECODE_ERR otherwise
Parameters
rplyreturn string from flowcontroller
err_msgerror message if something went wrong
resultdecoded message

Definition at line 472 of file bronkhorst.c.

References BH_SUCCESS, and hex2ascii().

Referenced by bh_in_init().

INT bh_exit ( BH_INFO info)

terminates the bus driver and free's the memory allocated for the info structure BH_INFO.

Return: FE_SUCCESS

Parameters
infois a pointer to the DD specific info structure

Definition at line 864 of file bronkhorst.c.

References BH_INFO::bd, BH_INFO::bd_info, BH_INFO::bh_in_settings, BH_INFO::scw, BH_IN_SETTINGS::scw_in_use, and BH_INFO::startup_error.

Referenced by bh_flow_in().

INT bh_flow_in ( INT  cmd,
  ... 
)

bronkhorst device driver (DD) for reading. It is handling the communication between the bronkhorst mass flow meter and midas.

Definition at line 1088 of file bronkhorst.c.

References bh_exit(), bh_get(), bh_in_get_label(), bh_in_init(), hKey, and info.

INT bh_flow_out ( INT  cmd,
  ... 
)

bronkhorst device driver (DD) for setting values. It is handling the communication between the bronkhorst mass flow meter and midas.

Definition at line 1141 of file bronkhorst.c.

References bh_out_get_label(), bh_out_init(), bh_set(), hKey, and info.

INT bh_get_cmd ( char *  str,
int *  decode_tag 
)

routine which filters the channel name and generates the command tag

Return: command tag

Parameters
strchannel name
decode_tagdecode tag needed for the decode routines bh_set_send_rcv, bh_get_send_rcv

Definition at line 663 of file bronkhorst.c.

Referenced by bh_get(), and bh_set().

INT bh_get_send_rcv ( BH_INFO info,
INT  cmd,
char *  result 
)

routine which is used to read back values from the flowcontroller.

Return:

  • BH_SUCCESS if everthing went fine
  • BH_COMM_ERR otherwise
    Parameters
    infoinfo structure used by BD_PUTS and BD_GETS macros
    cmdcommand tag telling which value to read back from the flowcontroller.
    resultreturn string from the flowcontroller.

Definition at line 505 of file bronkhorst.c.

References BH_INFO::bh_in_settings, BH_MAX_ERROR, BH_SUCCESS, bh_success(), BH_TIME_OUT, BH_IN_SETTINGS::detailed_msg, and BH_INFO::errorcount.

Referenced by bh_get(), and bh_in_init().

INT bh_in_get_label ( BH_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

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

Definition at line 1066 of file bronkhorst.c.

References BH_INFO::bh_in_settings, and BH_IN_SETTINGS::name.

Referenced by bh_flow_in().

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

Initializes the bronkhorst device driver, i.e. generates all the necessary structures in the ODB if necessary, initializes the bus driver and the bronkhorst mass flow meter.

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

Definition at line 700 of file bronkhorst.c.

References BH_INFO::bd, BH_INFO::bd_connected, BH_INFO::bd_info, bh_decode_string(), bh_get_send_rcv(), BH_INFO::bh_in_settings, BH_IN_SETTINGS_STR, BH_SCW_STR, BH_SUCCESS, BH_INFO::errorcount, BH_INFO::first_bd_error, hDB, hKey, BH_INFO::hkey, info, BH_INFO::last_reconnect, BH_INFO::lasterrtime, BH_IN_SETTINGS::name, BH_INFO::num_channels_in, BH_INFO::readback_failure, BH_INFO::reconnection_failures, BH_INFO::scw, BH_IN_SETTINGS::scw_in_use, BH_INFO::startup_error, and BH_INFO::startup_tag.

Referenced by bh_flow_in().

INT bh_out_get_label ( BH_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

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

Definition at line 1081 of file bronkhorst.c.

References BH_INFO::bh_out_settings, and BH_OUT_SETTINGS::name.

Referenced by bh_flow_out().

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

Initializes the bronkhorst device driver, i.e. generates all the necessary structures in the ODB if necessary, no initialization of the bus driver etc. is done, since this is part of BH_in_init.

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

Definition at line 824 of file bronkhorst.c.

References BH_INFO::bh_out_settings, BH_OUT_SETTINGS_STR, hDB, info, BH_INFO::num_channels_out, and BH_INFO::startup_error.

Referenced by bh_flow_out().

INT bh_set ( BH_INFO info,
INT  channel,
float  value 
)

set a value of the bronkhorst mass flow meter.

Return: FE_SUCCESS

Parameters
infois a pointer to the DD specific info structure.
channelis the channel number
valueto be set

Definition at line 887 of file bronkhorst.c.

References BH_INFO::bd_connected, bh_get_cmd(), BH_INFO::bh_in_settings, BH_MAX_ERROR, BH_INFO::bh_out_settings, bh_set_send_rcv(), BH_SUCCESS, BH_IN_SETTINGS::detailed_msg, BH_INFO::errorcount, BH_INFO::first_bd_error, BH_OUT_SETTINGS::name, BH_INFO::startup_error, and BH_INFO::startup_tag.

Referenced by bh_flow_out().

INT bh_set_send_rcv ( BH_INFO info,
INT  cmd,
float  value 
)

routine which is used to set values of the flowcontroller.

Return:

  • BH_SUCCESS if everthing went fine
  • BH_COMM_ERR if there was a communication problem
  • BH_CMD_UNKNOWN if the command is unkown
    Parameters
    infoinfo structure used by BD_PUTS and BD_GETS macros
    cmdcommand tag telling which value to read back from the flowcontroller.
    valuevalue to be set

Definition at line 593 of file bronkhorst.c.

References BH_INFO::bh_in_settings, BH_MAX_ERROR, BH_SUCCESS, bh_success(), BH_TIME_OUT, BH_IN_SETTINGS::detailed_msg, and BH_INFO::errorcount.

Referenced by bh_set().

int bh_success ( char *  str,
char *  error_msg 
)

decodes for any error messages coming from the bronkhorst flow meter.

return error tag:

  • BH_SUCCESS = no error
  • BH_STATUS_ERR = bronkhost status error
Parameters
strreturn string from the flowmeter
error_msgerror message return string (if error), otherwise empty string.

Definition at line 223 of file bronkhorst.c.

References BH_SUCCESS.

Referenced by bh_get_send_rcv(), and bh_set_send_rcv().

void hex2ascii ( char *  str,
int  len,
char *  result 
)

converts a hex string into a readable ascii string.

Parameters
strhex input string
lenlength of 'str'
resultconverted ascii string

Definition at line 390 of file bronkhorst.c.

Referenced by bh_decode_string().

Variable Documentation

BH_INFO* info

global info structure since port (rs232 or terminal server) can only be initialized once.

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

Definition at line 209 of file bronkhorst.c.