?? dpi515com.cpp
字號(hào):
if(!status)
{
status = viRead (instr, reinterpret_cast<unsigned char *>(strRead), 50, &rtnCount);
rcdBytes = rcdBytes + rtnCount; // number of bytes actually read
if(strncmp(strRead, ":UNIT:PRES", 10)==NULL)
{
ptr = strtok(strRead, " ");
ptr = strtok(NULL, "\r");
strcpy(currentUnit, ptr);
strcpy(strUnit, ptr);
pUnit = GetPressureUnit(ptr);
}
else
status = -1;
}
return status;
}
/******************************************************************************/
/* Function: setCurrentUnit */
/* Author: Alaster Jones */
/* Purpose: set the current unit */
/* Inputs: string pointer unit */
/* Outputs: long status */
/******************************************************************************/
long cDPI515Communications::setCurrentUnit(char * strUnit)
{
char strWrite[100];
long status = 0;
sprintf(strWrite, ":UNIT %s\r\n", strUnit);
wrtCount = strlen(strWrite);
status = viWrite (instr, reinterpret_cast<unsigned char *>(strWrite), wrtCount, &rtnCount);
sndBytes = sndBytes + rtnCount; // number of bytes actually written
return status;
}
/******************************************************************************/
/* Function: setIsolationValve */
/* Author: Alaster Jones */
/* Purpose: set the isolation valve open or closed */
/* Inputs: short open/closed */
/* Outputs: long status */
/******************************************************************************/
long cDPI515Communications::setIsolationValve(short sOpen)
{
char strWrite[100];
long status = 0;
sprintf(strWrite, ":OUTP:ISOL %d\r\n", sOpen);
wrtCount = strlen(strWrite);
status = viWrite (instr, reinterpret_cast<unsigned char *>(strWrite), wrtCount, &rtnCount);
sndBytes = sndBytes + rtnCount; // number of bytes actually written
return status;
}
/******************************************************************************/
/* Function: getPressureOperationsRegister */
/* Author: Alaster Jones */
/* Purpose: read the pressure operations register */
/* Inputs: pointer to operations register value */
/* Outputs: long status */
/******************************************************************************/
long cDPI515Communications::getPressureOperationsRegister(short * pReg)
{
char * ptr;
char strWrite[100];
char strRead[100];
long status = 0;
// flush the buffers before we do a read every time
status = viFlush(instr, VI_WRITE_BUF_DISCARD);
status = viFlush(instr, VI_READ_BUF_DISCARD);
strcpy(strWrite, ":STAT:OPER:PRES?\r\n");
wrtCount = strlen(strWrite);
status = viWrite (instr, reinterpret_cast<unsigned char *>(strWrite), wrtCount, &rtnCount);
sndBytes = sndBytes + rtnCount; // number of bytes actually written
if(!status)
{
status = viRead (instr, reinterpret_cast<unsigned char *>(strRead), 50, &rtnCount);
rcdBytes = rcdBytes + rtnCount; // number of bytes actually read
if(!status && strncmp(strRead, ":STAT:OPER:PRES:EVEN", 20)==NULL)
{
ptr = strtok(strRead, " ");
ptr = strtok(NULL, "\r");
*pReg = atoi(ptr);
}
else
status = -1;
}
return status;
}
/******************************************************************************/
/* Function: onSRQ */
/* Author: Alaster Jones */
/* Purpose: act on the srq event */
/* Inputs: passed the srq value */
/* Outputs: long status */
/******************************************************************************/
long cDPI515Communications::onSRQ(short srqRegister)
{
long status = 0;
short sReg;
if (srqRegister >= 192) // get the pressure operations register
status = getPressureOperationsRegister(&sReg);
if(sReg == 2) // if it's 2 we have a range change complete event so open iso valve
setIsolationValve(1);
return status;
}
/******************************************************************************/
/* Function: getStatusByte */
/* Author: Alaster Jones */
/* Purpose: get the status byte (after an SRQ event) */
/* Inputs: passed the session ID and pointer to SRQ register */
/* Outputs: long status */
/******************************************************************************/
long cDPI515Communications::getStatusByte(ViSession vi, USHORT * srq)
{
// read the status byte
return viReadSTB(vi, srq);
}
/******************************************************************************/
/* Function: gotoLocal */
/* Author: Alaster Jones */
/* Purpose: return the controller to local control */
/* Inputs: none */
/* Outputs: long status */
/******************************************************************************/
long cDPI515Communications::gotoLocal(void)
{
char strWrite[100];
long status = 0;
strcpy(strWrite, ":LOC\r\n");
status = viWrite (instr, reinterpret_cast<unsigned char *>(strWrite), strlen(strWrite), &rtnCount);
sndBytes = sndBytes + rtnCount; // number of bytes actually written
return status;
}
/******************************************************************************/
/* Function: getpressurePercentFS */
/* Author: Alaster Jones */
/* Purpose: return a percent full scale value */
/* Inputs: pressure */
/* Outputs: pressure as percent full scale */
/******************************************************************************/
double cDPI515Communications::getpressurePercentFS(double pressure)
{
// work it out in mbar as current range full scale stored as mbar
float mbarpressureReading;
mbarpressureReading = pressure * pUnit->dConversion;
return (mbarpressureReading/currentRangeFS)*100;
}
/******************************************************************************/
/* Function: getpercentFSPressure */
/* Author: Alaster Jones */
/* Purpose: return a pressure value */
/* Inputs: percent FS */
/* Outputs: percent full scale as a pressure (current units) */
/******************************************************************************/
double cDPI515Communications::getpercentFSPressure(double pcFS)
{
// work it out in mbar as current range full scale stored as mbar
float cuFullScale;
cuFullScale = currentRangeFS * pUnit->dConversion;
return (pcFS*cuFullScale)/100;
}
/******************************************************************************/
/* Function: waitforSRQ */
/* Author: Alaster Jones */
/* Purpose: wait for a serial SRQ to return */
/* Inputs: wait period and pointer to SRQ return value */
/* Outputs: long status */
/******************************************************************************/
long cDPI515Communications::waitforSRQ(short waitPeriod, short * SRQ_event)
{
struct timeb t;
long timenow, timenext;
long status = 0;
char * ptr;
char strRead[100];
*SRQ_event = 0;
ftime(&t);
timenext = t.time + waitPeriod;
do
{
ftime(&t);
timenow = t.time;
//Application->ProcessMessages();
status = viRead (instr, reinterpret_cast<unsigned char *>(strRead), 50, &rtnCount);
rcdBytes = rcdBytes + rtnCount; // number of bytes actually read
if(!status && strncmp(strRead, ":SRQ", 4)==NULL)
{
ptr = strtok(strRead, " ");
ptr = strtok(NULL, "\r");
*SRQ_event = atoi(ptr);
//onSRQ(*SRQ_event);
return status;
}
else
status = -1;
}
while(timenow<timenext);
return status;
}
/******************************************************************************/
/* Function: setVent */
/* Author: Alaster Jones */
/* Purpose: vent the controller */
/* Inputs: short vent start/stop */
/* Outputs: long status */
/******************************************************************************/
long cDPI515Communications::setVent(short On)
{
char strWrite[100];
long status = 0;
sprintf(strWrite, ":SOUR:VENT %d\r\n", On);
status = viWrite (instr, reinterpret_cast<unsigned char *>(strWrite), strlen(strWrite), &rtnCount);
sndBytes = sndBytes + rtnCount; // number of bytes actually written
return status;
}
/******************************************************************************/
/* Function: clearByteCounters */
/* Author: Alaster Jones */
/* Purpose: just clear the basic stuff */
/* Inputs: none */
/* Outputs: none */
/******************************************************************************/
void cDPI515Communications::clearByteCounters(void)
{
sndBytes = 0;
rcdBytes = 0;
trap_SRQ = false;
trap_SRQ_Value = 0;
};
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -