Instructions

Table Of Contents
Chapter 3 Programming Examples RIGOL
RSA5000 Programming Guide 3-7
}
bool CDemoForRSADlg::InstrWriteEx(CString strAddr, CString strContent) //Write operation with
exception handling
{
ViStatus status;
ViUInt32 retCount;
char * SendBuf = NULL;
bool bWriteOK = true;
// Change the address's data style from CString to char*
SendBuf = strContent.GetBuffer(strContent.GetLength());
strcpy(SendBuf,strContent);
strContent.ReleaseBuffer();
do
{
//Write command to the instrument
status = viWrite(m_SessInstr, (unsigned char *)SendBuf, strlen(SendBuf), &retCount);
//If an error occurs, perform error handling
if (status < 0)
{
//If the time exceeds the limit value, resend the command after a delay of 1s
if (VI_ERROR_TMO == status)
{
Sleep(1000);
status = viWrite(m_SessInstr, (unsigned char *)SendBuf, strlen(SendBuf),
&retCount);
}
else
{
//If another error occurs, reopen the connection after the connection is closed and
resend the command
status = CloseVisaDevice();
Sleep(1000);
status = OpenVisaDevice(m_strInstrAddr);
if (status == 0)
{
status = viWrite(m_SessInstr, (unsigned char *)SendBuf, strlen(SendBuf),
&retCount);
}
}
}
} while (status < 0);
return bWriteOK;
}
bool CDemoForRSADlg::InstrReadEx(CString strAddr, CString *pstrResult) //Read operation with
exception handling
{
ViStatus status;
ViUInt32 retCount;
char * SendAddr = NULL;
unsigned char RecBuf[MAX_REC_SIZE];