143 lines
4.6 KiB
C
143 lines
4.6 KiB
C
/*---------------------------------------------------------------------------
|
|
N H Q 2 0 0 U T I L
|
|
|
|
A few utility functions for talking to a NHQ 200
|
|
voltage controller via the ANSTO setup:
|
|
TCP/IP===MOXA===RS-232===NHQ200.
|
|
|
|
Mark Koennecke, Juli 1997
|
|
Mark Lesha, January 2006 (based on ITC4 code)
|
|
Douglas Clowes, December 2006 (based on LAKESHORE340 code)
|
|
|
|
----------------------------------------------------------------------------*/
|
|
#ifndef NHQ200_UTIL_H
|
|
#define NHQ200_UTIL_H
|
|
|
|
/*----------------------- ERRORCODES--------------------------------------
|
|
Most functions return a negative error code on failure. Error codes
|
|
defined are those defined for serialsinq plus a few additional ones:
|
|
*/
|
|
|
|
#define NHQ200__BADCOM -501 /* command not recognized */
|
|
#define NHQ200__BADPAR -502 /* bad parameter to command */
|
|
#define NHQ200__BADMALLOC -503 /* error allocating memory */
|
|
#define NHQ200__BADREAD -504 /* error analysing command string on Read */
|
|
#define NHQ200__FAULT -505 /* fault or overload condition exists in NHQ200 */
|
|
#define NHQ200__NONHQ200 -510 /* Controller is not NHQ200 */
|
|
#define NHQ200__BADSET -530 /* failed three times to set voltage */
|
|
#define NHQ200__READONLY -531
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
typedef struct __NHQ200 {
|
|
pAsyncUnit unit;
|
|
int iRead;
|
|
int iControl;
|
|
void *pData;
|
|
char pAns[80]; /* should be enough for NHQ200 errors */
|
|
/* The NHQ200 does not need multipliers or dividers but
|
|
leave them in anyway for back compatibility or future use
|
|
but force the value to 1.0 all the time */
|
|
float fDiv;
|
|
float fMult;
|
|
float fValue;
|
|
int iError;
|
|
int iReadOnly;
|
|
int iState;
|
|
char serial_number[20];
|
|
char software_version[20];
|
|
char voltage_max[20];
|
|
char current_max[20];
|
|
char status_s[20];
|
|
char status_t[20];
|
|
int module_status;
|
|
int vmax_percent;
|
|
int imax_percent;
|
|
int ramp_input;
|
|
char* transReply;
|
|
int transWait;
|
|
int iGetOut;
|
|
struct timeval tv_last;
|
|
} NHQ200;
|
|
|
|
typedef struct __NHQ200 *pNHQ200;
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
int NHQ200_Open(pNHQ200 *pData,char *pHost, int iPort, int iChannel, int iMode);
|
|
/***** creates an NHQ200 datastructure and opens a connection to the NHQ200
|
|
controller. Input Parameters are:
|
|
the hostname
|
|
the port number
|
|
the RS-232 channel number on the Mac.
|
|
iMode: 1 for ReadOnly, 0 for normal mode
|
|
|
|
Return values are 1 for success, a negative error code on
|
|
failure.
|
|
|
|
*/
|
|
|
|
void NHQ200_Close(pNHQ200 *pData);
|
|
/****** close a connection to an NHQ200controller and frees its
|
|
data structure. The only parameter is a pointer to the data
|
|
structure for this controller. This pointer will be invalid after
|
|
this call.
|
|
*/
|
|
|
|
int NHQ200_Config(pNHQ200 *pData, int iTmo, int iRead,
|
|
int iControl, float fDiv, float fMult);
|
|
/***** configure some aspects of a NHQ200 voltage controller.
|
|
The parameter are:
|
|
- a pointer to the data structure for the controller as
|
|
returned by NHQ200_Open
|
|
- a value for the connection timeout
|
|
- the voltage sensor to use for reading the
|
|
voltage.
|
|
- the voltage sensor used by the NHQ200controller
|
|
for regulating the voltage.
|
|
- the divisor needed to calculate the real voltage
|
|
from the sensor.
|
|
The function returns 1 on success, a negative error code on
|
|
failure.
|
|
*/
|
|
|
|
int NHQ200_Send(pNHQ200 *pData, char *pCommand, char *pReply, int iLen);
|
|
/******* send a the command in pCommand to the NHQ200controller.
|
|
A possible reply is returned in the buffer pReply.
|
|
Maximum iLen characters are copied to pReply.
|
|
The first parameter is a pointer to a NHQ200data structure
|
|
as returned by NHQ200_Open.
|
|
|
|
Return values are 1 for success, a negative error code on
|
|
failure.
|
|
*/
|
|
|
|
int NHQ200_Read(pNHQ200 *pData, float *fVal);
|
|
/******* reads the current actual voltage of the sensor
|
|
configured by ConfigNHQ200for reading. The value is returned
|
|
in fVal. The first parameter is a pointer to a NHQ200
|
|
data structure as returned by NHQ200_Open.
|
|
|
|
Return values are 1 for success, a negative error code on
|
|
failure.
|
|
*/
|
|
|
|
int NHQ200_Set(pNHQ200 *pData, float fVal);
|
|
/****** sets a new preset voltage in the NHQ200 voltage
|
|
controller. Parameters are:
|
|
- a pointer to a NHQ200data structure as returned by NHQ200_Open.
|
|
- the new preset value.
|
|
|
|
Return values are 1 for success, a negative error code on
|
|
failure.
|
|
*/
|
|
|
|
void NHQ200_ErrorTxt(pNHQ200 *pData, int iCode, char *pError, int iLen);
|
|
/******* translates one of the negative error NHQ200error codes
|
|
into text. Maximum iLen bytes will be copied to the
|
|
buffer pError;
|
|
*/
|
|
|
|
|
|
#endif /* NHQ200_UTIL_H */
|
|
|
|
|