/*--------------------------------------------------------------------------- W E S T 4 1 0 0 A few utility functions for talking to a Lakeshore 340 temperature controller via the SINQ setup: TCP/IP--MAC--RS-232-- WEST4100. Mark Koennecke, Juli 1997 Mark Lesha, January 2006 (based on ITC4 code) Paul Barron, January 2008 (Note: This is based on the old LAKESHORE340 code and not the new LS340 code written by Rodney Davies Feb 08) ----------------------------------------------------------------------------*/ #ifndef SINQWEST4100 #define SINQWEST4100 /*----------------------- ERRORCODES-------------------------------------- Most functions return a negative error code on failure. Error codes defined are those defined for serialsinq plus a few additional ones: */ #define WEST4100__BADCOM -501 /* command not recognized */ #define WEST4100__BADPAR -502 /* bad parameter to command */ #define WEST4100__BADMALLOC -503 /* error allocating memory */ #define WEST4100__BADREAD -504 /* error analysing command string on Read */ #define WEST4100__FAULT -505 /* fault or overload condition exists in WEST4100 */ #define WEST4100__NOWEST4100 -510 /* Controller is not WEST4100 */ #define WEST4100__BADSET -530 /* failed three times to set temperature */ #define WEST4100__READONLY -531 /*------------------------------------------------------------------------*/ typedef struct __WEST4100 { int iAdr; int iTransact; void *pData; char pAns[80]; prs232 controller; } WEST4100; typedef struct __WEST4100 *pWEST4100; /*-----------------------------------------------------------------------*/ int WEST4100_Open(pWEST4100 *pData,char *pHost, int iAddress, int iTransaction); /***** creates an WEST4100 datastructure and opens a connection to the WEST4100 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 WEST4100_Close(pWEST4100 *pData); /****** close a connection to an WEST4100controller 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 WEST4100_Config(pWEST4100 *pData, int iTmo, int iRead, int iControl); /***** configure some aspects of a WEST4100temperature controller. The parameter are: - a pointer to the data structure for the controller as returned by WEST4100_Open - a value for the connection timeout - the temperature sensor to use for reading the temperature. - the temperature sensor used by the WEST4100controller for regulating the temperature. - the divisor needed to calculate the real temperature from the sensor. The function returns 1 on success, a negative error code on failure. */ int WEST4100_Send(pWEST4100 *pData, char *pCommand, char *pReply, int iLen); /******* send a the command in pCommand to the WEST4100controller. A possible reply is returned in the buffer pReply. Maximum iLen characters are copied to pReply. The first parameter is a pointer to a WEST4100data structure as returned by WEST4100_Open. Return values are 1 for success, a negative error code on failure. */ int WEST4100_Read(pWEST4100 *pData, float *fVal); /******* reads the current actual temperature of the sensor configured by ConfigWEST4100for reading. The value is returned in fVal. The first parameter is a pointer to a WEST4100 data structure as returned by WEST4100_Open. Return values are 1 for success, a negative error code on failure. */ int WEST4100_Set(pWEST4100 *pData, float fVal); /****** sets a new preset temperature in the WEST4100temperature controller. Parameters are: - a pointer to a WEST4100data structure as returned by WEST4100_Open. - the new preset value. Return values are 1 for success, a negative error code on failure.pEVInterface */ void WEST4100_ErrorTxt(pWEST4100 *pData, int iCode, char *pError, int iLen); /******* translates one of the negative error WEST4100error codes into text. Maximum iLen bytes will be copied to the buffer pError; */ int WEST4100_Query(pWEST4100 *pData, int parAddress, int *parValue); int WEST4100_Write(pWEST4100 *pData, int parAddress, int parValue); int int2hexstring(int fVal, unsigned char *hexstring); void displayHexString(unsigned char *hexstring); #endif