fix missing return from ITC4_Config, change SerialError to getRS232Error, adjust Formatting

r2415 | dcl | 2008-04-14 08:37:57 +1000 (Mon, 14 Apr 2008) | 2 lines
This commit is contained in:
Douglas Clowes
2008-04-14 08:37:57 +10:00
parent 895e52bfe9
commit 519bf308fa

View File

@@ -1,10 +1,10 @@
/*-------------------------------------------------------------------------- /*--------------------------------------------------------------------------
I T C 4 U T I L I T C 4 U T I L
A few utility functions for dealing with a ITC4 temperature controller A few utility functions for dealing with a ITC4 temperature controller
within the SINQ setup: host -- TCP/IP -- MAC --- RS-232. within the SINQ setup: host -- TCP/IP -- MAC --- RS-232.
Mark Koennecke, Juli 1997 Mark Koennecke, Juli 1997
Copyright: Copyright:
@@ -55,7 +55,7 @@
char pCommand[80]; char pCommand[80];
char pReply[132]; char pReply[132];
pITC4 self = NULL; pITC4 self = NULL;
self = (pITC4)malloc(sizeof(ITC4)); self = (pITC4)malloc(sizeof(ITC4));
if(self == NULL) if(self == NULL)
{ {
@@ -68,7 +68,7 @@
self->fDiv = 10.; self->fDiv = 10.;
self->fMult = 10.; self->fMult = 10.;
self->controller = NULL; self->controller = NULL;
self->controller = (prs232)FindCommandData(pServ->pSics,pRS232, self->controller = (prs232)FindCommandData(pServ->pSics,pRS232,
"RS232 Controller"); "RS232 Controller");
if(!self->controller){ if(!self->controller){
@@ -81,7 +81,7 @@
controller do not recognize it. Sighhhhhhh. I had to put it in again controller do not recognize it. Sighhhhhhh. I had to put it in again
in order to check for ITC-503, but I handle the thing by default as in order to check for ITC-503, but I handle the thing by default as
an ITC4 if I do not get a proper response. an ITC4 if I do not get a proper response.
*/ */
self->i503 = 0; self->i503 = 0;
sprintf(pCommand,"V"); sprintf(pCommand,"V");
iRet = transactRS232(self->controller, pCommand,strlen(pCommand), iRet = transactRS232(self->controller, pCommand,strlen(pCommand),
@@ -94,8 +94,8 @@
if(strstr(pReply,"ITC503") != NULL) if(strstr(pReply,"ITC503") != NULL)
{ {
self->i503 = 1; self->i503 = 1;
} }
if(!self->iReadOnly) if(!self->iReadOnly)
{ {
/* switch to remote and unlocked operation pg48 */ /* switch to remote and unlocked operation pg48 */
@@ -103,15 +103,15 @@
iRet = transactRS232(self->controller, pCommand,strlen(pCommand), iRet = transactRS232(self->controller, pCommand,strlen(pCommand),
pReply,79); pReply,79);
if(iRet != 1) if(iRet != 1)
{ {
return iRet; return iRet;
} }
if(pReply[0] == '?') if(pReply[0] == '?')
{ {
strcpy(self->pAns,pReply); strcpy(self->pAns,pReply);
return ITC4__BADCOM; return ITC4__BADCOM;
} }
/* Set heater and gas flow controls to manual pg51 */ /* Set heater and gas flow controls to manual pg51 */
sprintf(pCommand,"A0"); sprintf(pCommand,"A0");
iRet = transactRS232(self->controller, pCommand,strlen(pCommand), iRet = transactRS232(self->controller, pCommand,strlen(pCommand),
@@ -119,13 +119,13 @@
if(iRet != 1) if(iRet != 1)
{ {
return iRet; return iRet;
} }
if(pReply[0] == '?') if(pReply[0] == '?')
{ {
strcpy(self->pAns,pReply); strcpy(self->pAns,pReply);
return ITC4__BADCOM; return ITC4__BADCOM;
} }
/* Set heater sensor pg 52 */ /* Set heater sensor pg 52 */
sprintf(pCommand,"H%1.1d",self->iControl); sprintf(pCommand,"H%1.1d",self->iControl);
iRet = transactRS232(self->controller, pCommand,strlen(pCommand), iRet = transactRS232(self->controller, pCommand,strlen(pCommand),
@@ -133,13 +133,13 @@
if(iRet != 1) if(iRet != 1)
{ {
return ITC4__BADCOM; return ITC4__BADCOM;
} }
if(pReply[0] == '?') if(pReply[0] == '?')
{ {
strcpy(self->pAns,pReply); strcpy(self->pAns,pReply);
return ITC4__BADCOM; return ITC4__BADCOM;
} }
/* Display on control sensor on front panel pg51 */ /* Display on control sensor on front panel pg51 */
sprintf(pCommand,"F%1.1d",self->iControl); sprintf(pCommand,"F%1.1d",self->iControl);
iRet = transactRS232(self->controller, pCommand,strlen(pCommand), iRet = transactRS232(self->controller, pCommand,strlen(pCommand),
@@ -147,7 +147,7 @@
if(iRet != 1) if(iRet != 1)
{ {
return iRet; return iRet;
} }
if(pReply[0] == '?') if(pReply[0] == '?')
{ {
strcpy(self->pAns,pReply); strcpy(self->pAns,pReply);
@@ -161,7 +161,7 @@
if(iRet != 1) if(iRet != 1)
{ {
return iRet; return iRet;
} }
if(pReply[0] == '?') if(pReply[0] == '?')
{ {
strcpy(self->pAns,pReply); strcpy(self->pAns,pReply);
@@ -175,14 +175,14 @@
} }
} }
return 1; return 1;
} }
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
void ITC4_Close(pITC4 *pData) void ITC4_Close(pITC4 *pData)
{ {
} }
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
/* Called by ansto/itc4driv.c:ConfigITC4 */ /* Called by ansto/itc4driv.c:ConfigITC4 */
int ITC4_Config(pITC4 *pData, int iTmo, int iRead, int iControl, int ITC4_Config(pITC4 *pData, int iTmo, int iRead, int iControl,
float fDiv,float fMult) float fDiv,float fMult)
{ {
@@ -191,92 +191,92 @@
char pCommand[10]; char pCommand[10];
pITC4 self; pITC4 self;
self = *pData; self = *pData;
/* 3 input channels see p52 */
/* BUG ALLOWS iControl=4 */
if (iControl < 1 || iControl > 3) {
return 1;
} else {
/* switch to remote and unlocked operation pg48 */
sprintf(pCommand,"C3");
iRet = transactRS232(self->controller, pCommand,strlen(pCommand), pReply,79);
if(iRet != 1)
{
return iRet;
}
if(pReply[0] == '?')
{
strcpy(self->pAns,pReply);
return ITC4__BADCOM;
}
/* Set heater and gas flow controls to manual pg51 */ /* 3 input channels see p52 */
sprintf(pCommand,"A0"); /* BUG ALLOWS iControl=4 */
iRet = transactRS232(self->controller, pCommand,strlen(pCommand), if (iControl < 1 || iControl > 3) {
pReply,79); return 1;
if(iRet != 1) } else {
{ /* switch to remote and unlocked operation pg48 */
return iRet; sprintf(pCommand,"C3");
} iRet = transactRS232(self->controller, pCommand,strlen(pCommand), pReply,79);
if(pReply[0] == '?') if(iRet != 1)
{ {
strcpy(self->pAns,pReply); return iRet;
return ITC4__BADCOM; }
} if(pReply[0] == '?')
{
strcpy(self->pAns,pReply);
return ITC4__BADCOM;
}
/* Set heater sensor pg 52 */ /* Set heater and gas flow controls to manual pg51 */
sprintf(pCommand,"H%1.1d",iControl); sprintf(pCommand,"A0");
iRet = transactRS232(self->controller, pCommand,strlen(pCommand), iRet = transactRS232(self->controller, pCommand,strlen(pCommand),
pReply,79); pReply,79);
if(iRet != 1) if(iRet != 1)
{ {
return ITC4__BADCOM; return iRet;
} else if(pReply[0] == '?') }
{ if(pReply[0] == '?')
strcpy(self->pAns,pReply); {
return ITC4__BADCOM; strcpy(self->pAns,pReply);
} else { return ITC4__BADCOM;
self->iControl = iControl; }
}
/* Display on control sensor on front panel pg51 */ /* Set heater sensor pg 52 */
sprintf(pCommand,"F%1.1d",iControl); sprintf(pCommand,"H%1.1d",iControl);
iRet = transactRS232(self->controller, pCommand,strlen(pCommand), iRet = transactRS232(self->controller, pCommand,strlen(pCommand),
pReply,79); pReply,79);
if(iRet != 1) if(iRet != 1)
{ {
return iRet; return ITC4__BADCOM;
} } else if(pReply[0] == '?')
if(pReply[0] == '?') {
{ strcpy(self->pAns,pReply);
strcpy(self->pAns,pReply); return ITC4__BADCOM;
return ITC4__BADCOM; } else {
} self->iControl = iControl;
}
/* Heater Auto, Gas Manual pg51 */ /* Display on control sensor on front panel pg51 */
sprintf(pCommand,"A1"); sprintf(pCommand,"F%1.1d",iControl);
iRet = transactRS232(self->controller, pCommand,strlen(pCommand), iRet = transactRS232(self->controller, pCommand,strlen(pCommand),
pReply,79); pReply,79);
if(iRet != 1) if(iRet != 1)
{ {
return iRet; return iRet;
} }
if(pReply[0] == '?') if(pReply[0] == '?')
{ {
strcpy(self->pAns,pReply); strcpy(self->pAns,pReply);
return ITC4__BADCOM; return ITC4__BADCOM;
} }
/* reset timeout */
/*iRet = SerialConfig(&self->pData, 10);*/
if(iRet != 1)
{
return iRet;
}
/* Heater Auto, Gas Manual pg51 */
sprintf(pCommand,"A1");
iRet = transactRS232(self->controller, pCommand,strlen(pCommand),
pReply,79);
if(iRet != 1)
{
return iRet;
}
if(pReply[0] == '?')
{
strcpy(self->pAns,pReply);
return ITC4__BADCOM;
}
/* reset timeout */
/*iRet = SerialConfig(&self->pData, 10);*/
if(iRet != 1)
{
return iRet;
}
} return 1;
} }
}
/* --------------------------------------------------------------------------*/ /* --------------------------------------------------------------------------*/
int ITC4_Send(pITC4 *pData, char *pCommand, char *pReply, int iLen) int ITC4_Send(pITC4 *pData, char *pCommand, char *pReply, int iLen)
{ {
@@ -290,7 +290,7 @@
strcat(pCommand,"\r"); strcat(pCommand,"\r");
} */ } */
return transactRS232(self->controller,pCommand,strlen(pCommand),pReply,iLen); return transactRS232(self->controller,pCommand,strlen(pCommand),pReply,iLen);
} }
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
int ITC4_Read(pITC4 *pData, float *fVal) int ITC4_Read(pITC4 *pData, float *fVal)
{ {
@@ -309,7 +309,7 @@
if(iRet != 1) if(iRet != 1)
{ {
return iRet; return iRet;
} }
if(pReply[0] == '?') if(pReply[0] == '?')
{ {
strcpy(self->pAns,pReply); strcpy(self->pAns,pReply);
@@ -322,7 +322,7 @@
strcpy(self->pAns,pReply); strcpy(self->pAns,pReply);
return ITC4__BADCOM; return ITC4__BADCOM;
} }
iRet = sscanf(&pReply[1],"%f",&fRead); iRet = sscanf(&pReply[1],"%f",&fRead);
if(iRet != 1) if(iRet != 1)
{ {
@@ -333,7 +333,7 @@
*fVal = fRead; *fVal = fRead;
} }
else else
{ {
*fVal = fRead/self->fDiv; *fVal = fRead/self->fDiv;
} }
return 1; return 1;
@@ -354,7 +354,7 @@
{ {
return ITC4__READONLY; return ITC4__READONLY;
} }
/* format command */ /* format command */
if(self->i503) if(self->i503)
{ {
@@ -365,20 +365,20 @@
fSet = fVal; fSet = fVal;
iSet = (int)(fSet*self->fMult); iSet = (int)(fSet*self->fMult);
sprintf(pCommand,"T%5.5d",iSet); sprintf(pCommand,"T%5.5d",iSet);
} }
/* try three times: send, read, test, if OK return, else /* try three times: send, read, test, if OK return, else
resend. This must be done because the ITC4 tends to loose resend. This must be done because the ITC4 tends to loose
characters characters
*/ */
for(i = 0; i < 3; i++) for(i = 0; i < 3; i++)
{ {
/* send command */ /* send command */
iRet = transactRS232(self->controller,pCommand,strlen(pCommand),pReply,131); iRet = transactRS232(self->controller,pCommand,strlen(pCommand),pReply,131);
if(iRet != 1) if(iRet != 1)
{ {
return iRet; return iRet;
} }
if(pReply[0] == '?') if(pReply[0] == '?')
{ {
strcpy(self->pAns,pReply); strcpy(self->pAns,pReply);
@@ -404,14 +404,14 @@
else else
{ {
fDelta = fRead - fSet; fDelta = fRead - fSet;
} }
if(fDelta < 0) if(fDelta < 0)
fDelta = -fDelta; fDelta = -fDelta;
if(fDelta < fPrecision) if(fDelta < fPrecision)
{ {
/* Success, go home */ /* Success, go home */
return 1; return 1;
} }
} }
return ITC4__BADSET; return ITC4__BADSET;
} }
@@ -422,7 +422,7 @@
pITC4 self; pITC4 self;
self = *pData; self = *pData;
switch(iCode) switch(iCode)
{ {
case ITC4__BADCOM: case ITC4__BADCOM:
@@ -441,9 +441,9 @@
break; break;
case ITC4__BADSET: case ITC4__BADSET:
strncpy(pError,"ITC4: Failed three times to write new set value to ITC4",iLen); strncpy(pError,"ITC4: Failed three times to write new set value to ITC4",iLen);
break; break;
default: default:
SerialError(iCode, pError,iLen); getRS232Error(iCode, pError,iLen);
break; break;
} }
} }