?? dpi515com.cpp
字號:
trap_SRQ = true;
ptr = strtok(strRead, " ");
ptr = strtok(NULL, "\r");
trap_SRQ_Value = atol(ptr);
status = -1;
}
else
status = -1;
}
return status;
}
/******************************************************************************/
/* Function: setControllerOnOff */
/* Author: Alaster Jones */
/* Purpose: switch the controller on/off */
/* Inputs: bool on/off */
/* Outputs: long status */
/******************************************************************************/
long cDPI515Communications::setControllerOnOff(short On)
{
char strWrite[100];
long status = 0;
// query pressure
sprintf(strWrite,":OUTP %d\r\n", On);
wrtCount = strlen(strWrite);
status = viWrite (instr, reinterpret_cast<unsigned char *>(strWrite), wrtCount, &rtnCount);
sndBytes = sndBytes + rtnCount; // number of bytes actually written
return status;
}
/******************************************************************************/
/* Function: getControllerOnOff */
/* Author: Alaster Jones */
/* Purpose: get whether the controller is on or off */
/* Inputs: ptr to bool state on/off */
/* Outputs: long status */
/******************************************************************************/
long cDPI515Communications::getControllerOnOff(short * pOn)
{
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);
// query pressure
strcpy(strWrite,":OUTP?\r\n");
wrtCount = strlen(strWrite);
status = viWrite (instr, reinterpret_cast<unsigned char *>(strWrite), wrtCount, &rtnCount);
sndBytes = sndBytes + rtnCount; // number of bytes actually written
// read pressure request
if (!status) // no r/w error
{
status = viRead (instr, reinterpret_cast<unsigned char *>(strRead), 50, &rtnCount);
rcdBytes = rcdBytes + rtnCount; // number of bytes actually read
}
if(!status) // no r/w error
{
if(strncmp(strRead, ":OUTP", 5)==NULL)
{
// correct string returned
ptr = strtok(strRead, " ");
ptr = strtok(NULL, "\r");
*pOn = atoi(ptr);
}
else if(strncmp(strRead, ":SRQ", 4)==NULL)
{
// trap an SRQ here
trap_SRQ = true;
ptr = strtok(strRead, " ");
ptr = strtok(NULL, "\r");
trap_SRQ_Value = atol(ptr);
status = -1;
}
else
status = -1;
}
return status;
}
/******************************************************************************/
/* Function: getInstrumentRanges */
/* Author: Alaster Jones */
/* Purpose: get all the ranges from the instrument */
/* Inputs: */
/* Outputs: long status */
/******************************************************************************/
long cDPI515Communications::getInstrumentRanges(void)
{
char * ptr;
char strWrite[100];
char strRead[200];
long status = 0;
numRanges = 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);
// get the available ranges and the current range
strcpy(strWrite, ":INST:CAT?\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), 200, &rtnCount);
rcdBytes = rcdBytes + rtnCount; // number of bytes actually read
if(ptr = strtok(strRead, "\""))
{
while(!status && (ptr = strtok(NULL, "\"")))
{
// get the range strings
if(strstr(ptr, "bar"))
{
strcpy(instrumentRanges[numRanges++], ptr);
}
}
}
}
return status;
}
/******************************************************************************/
/* Function: getCurrentRange */
/* Author: Alaster Jones */
/* Purpose: gets the current range from the instrument */
/* Inputs: string pointer range */
/* Outputs: long status */
/******************************************************************************/
long cDPI515Communications::getCurrentRange(char * strRange)
{
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);
// need to convert bar to units to get the %FS values later
strcpy(strWrite, ":SOUR:RANG?\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 && (ptr = strtok(strRead, "\"")))
{
ptr = strtok(NULL, "\"");
currentRangeFS = atof(ptr) * 1000;
strcpy(currentRange,ptr);
strcpy(strRange,ptr);
}
else
status = -1;
}
return status;
}
/******************************************************************************/
/* Function: setCurrentRange */
/* Author: Alaster Jones */
/* Purpose: set the current range */
/* Inputs: string pointer range */
/* Outputs: long status */
/******************************************************************************/
long cDPI515Communications::setCurrentRange(char * strRange)
{
char strWrite[100];
long status = 0;
sprintf(strWrite, ":SOUR:RANG\"%s\"\r\n", strRange);
wrtCount = strlen(strWrite);
status = viWrite (instr, reinterpret_cast<unsigned char *>(strWrite), wrtCount, &rtnCount);
sndBytes = sndBytes + rtnCount; // number of bytes actually written
return status;
}
/******************************************************************************/
/* Function: getInstrumentUnits */
/* Author: Alaster Jones */
/* Purpose: get all the units from the instrument */
/* Inputs: read all the units from the instrument */
/* Outputs: long status */
/******************************************************************************/
long cDPI515Communications::getInstrumentUnits(void)
{
char * ptr;
char strWrite[100];
char strRead[100];
long status = 0;
numUnits = 0;
// get the available units
for(short sCount=1; sCount<=MAXUNITS; sCount++)
{
// flush the buffers before we do a read every time
status = viFlush(instr, VI_WRITE_BUF_DISCARD);
status = viFlush(instr, VI_READ_BUF_DISCARD);
sprintf(strWrite, ":INST:UNIT%d?\r\n", sCount);
wrtCount = strlen(strWrite);
status = viWrite (instr, reinterpret_cast<unsigned char *>(strWrite), wrtCount, &rtnCount);
sndBytes = sndBytes + rtnCount; // number of bytes actually written
memset(&strRead,0,100);
if(!status)
{
status = viRead (instr, reinterpret_cast<unsigned char *>(strRead), 20, &rtnCount);
rcdBytes = rcdBytes + rtnCount; // number of bytes actually read
if(strncmp(strRead, ":INST:UNIT", 10)==NULL)
{
ptr = strtok(strRead, " ");
ptr = strtok(NULL, "\r");
strcpy(instrumentUnits[sCount-1], ptr);
numUnits++;
}
else
status = -1;
}
}
return status;
}
/******************************************************************************/
/* Function: getCurrentUnit */
/* Author: Alaster Jones */
/* Purpose: gets the current unit */
/* Inputs: string pointer unit */
/* Outputs: long status */
/******************************************************************************/
long cDPI515Communications::getCurrentUnit(char * strUnit)
{
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, ":UNIT?\r\n");
status = viWrite (instr, reinterpret_cast<unsigned char *>(strWrite), wrtCount, &rtnCount);
sndBytes = sndBytes + rtnCount; // number of bytes actually written
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -