Hello,
System: Measurement Studio 6.0
We want to use Serial with VISA in asynchrone mode (with handler if possible). We have made a small program (based on CDialog) to test it, but every time we call CNiVisaSession::Read(,,jobID) (jobID for asynchrone mode!), it returns VisaSuccessIoSync, why? (what conditions are missing; event queue in place of handler; or serial VISA cannot be asynchrone at all?)
In fact, we want that CNiVisaSession::Read() returns immediately and uses asynchrone mode (actually, it blocks).
We use the following code (in class CMyClass):
Header:
class CMyClass: public CDialog
{
....
ViByte m_nSerialBuffer[255];
CNiVisaJobId m_nSerialJobId;
CNiVisaSession m_nSerialSession;
void InitNIVisaSerial();
ViStatus OnNIVisaEvent(CNiVisaEvent& nEvent);
};
Body:
CMyClass():m_nSerialSession("ASRL1::INSTR", VisaExclusiveLock){}
...
void CMyClass::InitNIVisaSerial()// called from OnInitDialog
{
// initialize serial
m_nSerialSession.SetAttribute(VisaSerialBaudRate, (uInt32)9600);
m_nSerialSession.SetAttribute(VisaSerialParity, VisaParityNone);
m_nSerialSession.SetAttribute(VisaSerialDataBits, (uInt16)8);
m_nSerialSession.SetAttribute(VisaSerialStopBits, VisaStopOne);
m_nSerialSession.SetAttribute(VisaSerialFlowControl, VisaFlowNone);
m_nSerialSession.SetAttribute(VisaTimeout, (uInt16)5000); //time out of 5 secs
try {
// we want the 0x0D character termination
m_nSerialSession.SetAttribute(VisaSerialEndIn, VisaEndTermChar);
m_nSerialSession.SetAttribute(VisaTerminationChar, (uInt8)0x0D);
// OnNIVisaEvent is called on completion,ok
CNiVisaEventHandlerId nID;
m_nSerialSession.InstallEventHandler(VisaEventIoComplete, *this,
OnVisaEventHandler(CMyClass, OnNIVisaEvent),
nID);
m_nSerialSession.EnableEvent(VisaEventIoComplete, VisaHandler);
}
catch (CNiVisaException* e)
{
e->ReportError();
e->Delete ();
}
}
.....
// called from Read button
void CMyClass::OnReadBtn()
{
// here we send asynchrone read, but every time
// the command complete in synchrone mode, for which raison?
ViStatus nStatus = m_nSerialSession.Read(m_nSerialBuffer, 255, m_nSerialJobId);
if(nStatus == VisaSuccessIoSync) // go always in this condtion after timeout
AfxMessageBox("Reading synchrone");
}
Thanks a lot,
Alain