Fixed general bugs.

r2139 | mle | 2007-08-23 15:08:52 +1000 (Thu, 23 Aug 2007) | 2 lines
This commit is contained in:
Mark Lesha
2007-08-23 15:08:52 +10:00
committed by Douglas Clowes
parent a85720686b
commit e76c3922f0
3 changed files with 107 additions and 60 deletions

View File

@@ -66,7 +66,7 @@
do
{
sprintf(pCommand,"BUSY?");
usleep(50000); // Required to meet Lakeshore340 spec.
usleep(100000); // Required to meet Lakeshore340 spec.
if ((iRet=transactRS232(self->controller,pCommand,strlen(pCommand),pReply,79))<=0)
{
printf("Comms error!\n");
@@ -102,7 +102,7 @@
else
sprintf(pCommand,"%s %s",command,configonlyparameters);
printf("Issuing command: '%s'...\n",pCommand);
usleep(50000); // Required to meet Lakeshore340 spec.
usleep(100000); // Required to meet Lakeshore340 spec.
if ((iRet=writeRS232(self->controller,pCommand,strlen(pCommand)))!=1)
return iRet;
/* Issue the query corresponding to the command, */
@@ -112,7 +112,7 @@
else
sprintf(pCommand,"%s?",command);
printf("Issuing query: '%s'...\n",pCommand);
usleep(50000); // Required to meet Lakeshore340 spec.
usleep(100000); // Required to meet Lakeshore340 spec.
if ((iRet=transactRS232(self->controller,pCommand,strlen(pCommand),pReply,79))<=0)
{
printf("transactRS232 error! Code=%d.\n",iRet);
@@ -180,7 +180,7 @@
/* Reset the controller to power-on state. */
sprintf(pCommand,"*RST");
usleep(50000); // Required to meet Lakeshore340 spec.
usleep(100000); // Required to meet Lakeshore340 spec.
if ((iRet=writeRS232(self->controller, pCommand,strlen(pCommand)))!=1)
return iRet;
@@ -188,7 +188,7 @@
/* just in case we want to use the internal status flags later on. */
/* Actually, we do *RST above, probably this isn't necessary. */
sprintf(pCommand,"*CLS");
usleep(50000); // Required to meet Lakeshore340 spec.
usleep(100000); // Required to meet Lakeshore340 spec.
if ((iRet=writeRS232(self->controller, pCommand,strlen(pCommand)))!=1)
return iRet;
@@ -199,7 +199,7 @@
/* Check the POST status, it should be 0 and not 1. */
sprintf(pCommand,"*TST?");
usleep(50000); // Required to meet Lakeshore340 spec.
usleep(100000); // Required to meet Lakeshore340 spec.
if ((iRet=transactRS232(self->controller,pCommand,strlen(pCommand),pReply,79))<=0)
return iRet;
if (strcmp(pReply,"0")!=0)
@@ -220,7 +220,7 @@
/* There's also the *REV command to check the firmware revision, but */
/* that would be going too far ;) */
sprintf(pCommand,"*IDN?",command);
usleep(50000); // Required to meet Lakeshore340 spec.
usleep(100000); // Required to meet Lakeshore340 spec.
if ((iRet=transactRS232(self->controller,pCommand,strlen(pCommand),pReply,79))<=0)
return iRet;
if (strncmp(pReply,"LSCI,MODEL340",13)!=0)
@@ -239,7 +239,7 @@
/* Clear any alarms. */
sprintf(pCommand,"ALMRST");
usleep(50000); // Required to meet Lakeshore340 spec.
usleep(100000); // Required to meet Lakeshore340 spec.
if ((iRet=writeRS232(self->controller, pCommand,strlen(pCommand)))!=1)
return iRet;
@@ -359,13 +359,13 @@
&&(pCommand[i+1]==' '||pCommand[i+1]=='\0')); // any '? ' pattern or trailing '?' will do.
if (!isquery) // LAKESHORE340 does not send any response.
{
usleep(50000); // Required to meet Lakeshore340 spec.
usleep(100000); // Required to meet Lakeshore340 spec.
iRet=writeRS232(self->controller,pCommand,commandlen);
*pReply='\0';
}
else // LAKESHORE340 will send a response.
{
usleep(50000); // Required to meet Lakeshore340 spec.
usleep(100000); // Required to meet Lakeshore340 spec.
iRet=transactRS232(self->controller,pCommand,commandlen,pReply,iLen);
}
@@ -407,7 +407,7 @@
return LAKESHORE340__BADPAR; // But shouldn't happen
}
usleep(50000); // Required to meet Lakeshore340 spec.
usleep(100000); // Required to meet Lakeshore340 spec.
if ((iRet=transactRS232(self->controller,pCommand,strlen(pCommand),pReply,79))<=0)
return iRet;
@@ -448,11 +448,11 @@
for(i = 0; i < 3; i++)
{
/* send SETP command, we don't get any response so use writeRS232 */
usleep(50000); // Required to meet Lakeshore340 spec.
usleep(100000); // Required to meet Lakeshore340 spec.
if ((iRet=writeRS232(self->controller,pCommand,strlen(pCommand)))!=1)
return iRet;
/* read the set value again using the SETP? command */
usleep(50000); // Required to meet Lakeshore340 spec.
usleep(100000); // Required to meet Lakeshore340 spec.
if ((iRet=transactRS232(self->controller,pCommandRead,strlen(pCommandRead),pReply,131))<=0)
return iRet;
printf("SETP: Response %d characters: '%s'\n",iRet,pReply);

View File

@@ -47,29 +47,51 @@
#include <modriv.h>
#include <rs232controller.h>
#include "lh45util.h"
#include <serialsinq.h>
/* -------------------------------------------------------------------------*/
// Because the Julabo LH45 may return non-printing characters such as DC1 and DC3
// at the beginning of its responses, we provide a functin to strip them off.
char *ReplyStart(char *pReply)
{
while(*pReply<0x20&&*pReply!='\0') // chuck out any and all control characters, CR, LF etc.
pReply++;
return pReply;
}
int LH45_Check_Status(pLH45 self) /* Can be called to check for correct operation of the LH45 */
{
int iRet;
char pCommand[20];
char pReply[132];
char pReply[132],*pReplyStart;
/* Check the status. It should read '03 REMOTE START' or possibly '03 REMOTE START,DEGASING'. */
/* If there is any LH45 overload or other fault condition it will be detected here. */
// printf("Checking LH45 status...");fflush(stdout);
sprintf(pCommand,"status");
printf("Getting STATUS \n");fflush(stdout);
sprintf(pCommand,"STATUS");
iRet = transactRS232(self->controller, pCommand,strlen(pCommand),
pReply,79);
pReplyStart=ReplyStart(pReply);
usleep(500000);
/home/mrt/workspace
if(iRet <= 0)
{
//transactRS232(self->controller,"\nDEBUG: RS232 transaction bad.\n",28,pReply,79);
//transactRS232(self->co/home/mrt/workspacentroller,"\nDEBUG: RS232 transaction bad.\n",28,pReply,79);
return iRet;
}
if (strncmp(pReply,"03 REMOTE START",15)!=0)
printf("Status is: '%s'\n",pReplyStart);fflush(stdout);
int i;
for(i=0;i<strlen(pReply);i++)
printf("0x%02x ",((unsigned char *)pReply)[i]);
printf("\n");
if (strncmp(pReplyStart,"03 REMOTE START",15)!=0)
{
//transactRS232(self->controller,"\nDEBUG: RS232 response bad\n",27,pReply,79);
//transactRS232(self->controller,pReply,strlen(pReply),pReply,79);
strcpy(self->pAns,pReply);
strcpy(self->pAns,pReplyStart);
return LH45__FAULT;
}
//transactRS232(self->controller,"\nDEBUG: Status reply is good!\n",30,pReply,79);
@@ -86,13 +108,14 @@
//setRS232Debug(self->controller,1);
//printf("***RS232 debug mode enabled for LH45***\n");fflush(stdout);
/* switch to remote operation */
/* switch to remote operation - although don't want it to initialise */
/* NOTE: The Julabo does not provide any response for 'out' commands,
so we just use writeRS232 not transactRS232 for these */
//printf("Issuing out_mode_05 1 command...");fflush(stdout);
sprintf(pCommand,"out_mode_05 1");
//printf("Issuing out_mode_05 0 command...");fflush(stdout);
sprintf(pCommand,"OUT_MODE_05 0");
iRet = writeRS232(self->controller, pCommand,strlen(pCommand));
//printf("Response: '%s'\n",pReply);fflush(stdout);
usleep(500000);
printf("OUT_MODE_05 1 is completed \n");fflush(stdout);
if(iRet != 1)
{
return iRet;
@@ -110,8 +133,10 @@
/* Set heater sensor */
/* For the LH45 there is a choice of internal or external sensor control,
set internal when iControl==1 and external when iControl==2 */
sprintf(pCommand,"out_mode_04 %1.1d",self->iControl - 1);
sprintf(pCommand,"OUT_MODE_04 %d",self->iControl - 1);
iRet = writeRS232(self->controller, pCommand,strlen(pCommand));
usleep(500000);
printf("OUT_MODE_04 Response is completed \n");fflush(stdout);
if(iRet != 1)
{
return LH45__BADCOM;
@@ -167,6 +192,7 @@
if(!self->iReadOnly)
return LH45_Setup(self, self->iControl);
return 1;
}
/*--------------------------------------------------------------------------*/
void LH45_Close(pLH45 *pData)
@@ -182,8 +208,9 @@
/* switch off remote operation */
/* Not sure if this is really necessary but do it just in case */
sprintf(pCommand,"out_mode_05 0");
sprintf(pCommand,"OUT_MODE_05 0");
iRet = writeRS232(self->controller, pCommand,strlen(pCommand));
usleep(500000);
/* Don't bother checking the status but record any error reply */
/* if(pReply[0] == '-') // Probably an error response
strcpy(self->pAns,pReply); */
@@ -207,6 +234,7 @@
pLH45 self;
self = *pData;
char *pReplyStart;
/* make sure, that there is a \r at the end of the command */
/* if(strchr(pCommand,(int)'\r') == NULL)
@@ -218,13 +246,22 @@
/* Because the Julabo LH45 only provides a response for the 'version', 'status'
and 'in' commands and not for the 'out' commands, just perform a write
for those and not a full transaction. */
if (strncmp(pCommand,"out",3)==0) // 'out' command; LH45 does not send any response.
if (strncasecmp(pCommand,"OUT",3)==0) // 'OUT' command; LH45 does not send any response.
{
iRet=writeRS232(self->controller,pCommand,strlen(pCommand));
usleep(500000);
*pReply='\0';
}
else
{
iRet=transactRS232(self->controller,pCommand,strlen(pCommand),pReply,iLen);
pReplyStart=ReplyStart(pReply);
// In this case we need to actually shift the buffer content since it is passed in from outside
char *ptoReply=pReply;
do {
*ptoReply++=*pReplyStart;
} while(*pReplyStart++);
}
if(iRet <= 0)
return iRet;
@@ -235,7 +272,7 @@
/*--------------------------------------------------------------------------*/
int LH45_Read(pLH45 *pData, float *fVal)
{
char pCommand[20], pReply[132];
char pCommand[20], pReply[132], *pReplyStart;
int iRet;
float fRead = -9999999.;
pLH45 self;
@@ -247,13 +284,13 @@
switch(self->iRead)
{
case 1:
sprintf(pCommand,"in_pv_00");
sprintf(pCommand,"IN_PV_00");
break;
case 2:
sprintf(pCommand,"in_pv_02");
sprintf(pCommand,"IN_PV_02");
break;
case 3:
sprintf(pCommand,"in_pv_03");
sprintf(pCommand,"IN_PV_03");
break;
default:
return LH45__BADPAR; // But shouldn't happen
@@ -261,24 +298,25 @@
iRet = transactRS232(self->controller, pCommand,strlen(pCommand),
pReply,79);
pReplyStart=ReplyStart(pReply);
usleep(500000);
if(iRet <= 0)
{
return iRet;
}
if(pReply[0] == '-'&&strlen(pReply)>7) // Not a number (-XXX.X\r), probably an error response
}
//sprintf(self->pAns,"The read value is '%s'\n and the command is: '%s' \n",pReply,pCommand);
//return LH45__FAULT;
if(pReplyStart == '-'&&strlen(pReplyStart)>7) // Not a number (-XXX.X\r), probably an error response
{
strcpy(self->pAns,pReply);
strcpy(self->pAns,pReplyStart);
return LH45__BADCOM;
}
iRet = sscanf(pReply,"%f",&fRead);
if(iRet != 1)
{
return LH45__BADREAD;
}
*fVal = fRead;
iRet = sscanf(pReplyStart,"%f",&fRead);
if (iRet == 1)
*fVal = fRead;
/* Check the LH45 operating status after the read, and return */
iRet=LH45_Check_Status(self);
@@ -287,7 +325,7 @@
/* -------------------------------------------------------------------------*/
int LH45_Set(pLH45 *pData, float fVal)
{
char pCommand[20], pCommandRead[20], pReply[132];
char pCommand[20], pCommandRead[20], pReply[132], *pReplyStart;;
int iRet, i;
const float fPrecision = 0.1;
float fDelta, fRead;
@@ -300,14 +338,15 @@
return LH45__READONLY;
}
sprintf(pCommand,"out_sp_00 %1.1f",fVal);
sprintf(pCommandRead,"in_sp_00"); // To read back and check the set value
sprintf(pCommand,"OUT_SP_00 %1.1f",fVal);
sprintf(pCommandRead,"IN_SP_00"); // To read back and check the set value
/* try three times: send, read, test, if OK return, else resend. */
for(i = 0; i < 3; i++)
{
/* send command, since it's an 'out' we don't get any response, so use writeRS232 */
iRet = writeRS232(self->controller,pCommand,strlen(pCommand));
usleep(500000);
//writeRS232(self->controller,pReply,strlen(pReply)); // MJL DEBUG
if(iRet != 1)
{
@@ -318,20 +357,23 @@
strcpy(self->pAns,pReply);
return LH45__BADCOM;
} */
/* read the set value again using the 'in' command */
iRet = transactRS232(self->controller,pCommandRead,strlen(pCommandRead),pReply,131);
pReplyStart=ReplyStart(pReply);
usleep(500000);
//writeRS232(self->controller,pReply,strlen(pReply)); // MJL DEBUG
if(iRet <= 0)
{
return iRet;
}
if(pReply[0] == '-'&&strlen(pReply)>7) // Not a number (-XXX.X\r), probably an error response
if(pReplyStart == '-'&&strlen(pReplyStart)>7) // Not a number (-XXX.X\r), probably an error response
{
strcpy(self->pAns,pReply);
strcpy(self->pAns,pReplyStart);
return LH45__BADCOM;
}
/* Convert the value read back. */
iRet=sscanf(pReply,"%f",&fRead);
iRet=sscanf(pReplyStart,"%f",&fRead);
if(iRet != 1)
{
return LH45__BADREAD;
@@ -342,11 +384,17 @@
fDelta = -fDelta;
if(fDelta < fPrecision)
{
/* Success, but check the LH45 operating status afterwards, and return */
/* Don't bother to repeat the write if we get an error here as it would indicate
a fault or overload in the LH45, not a comms problem */
iRet=LH45_Check_Status(self);
return iRet;
sprintf(pCommand,"OUT_MODE_05 1");
iRet = writeRS232(self->controller, pCommand,strlen(pCommand));
usleep(500000);
if(iRet == 1)
{
/* Success, but check the LH45 operating status afterwards, and return */
/* Don't bother to repeat the write if we get an error here as it would indicate
a fault or overload in the LH45, not a comms problem */
iRet=LH45_Check_Status(self);
return iRet;
}
}
}
return LH45__BADSET;