Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

I have a Program written in VC++ using NI App Wizard, I want to use VISA ActiveX control to communicate over Serial interface, Is there any sample program, which shows init, Read, Write routines?

I want to reset comport?
I want to write to comport?
I want terminated read?
0 Kudos
Message 1 of 4
(3,802 Views)
Anil:

You may be getting 2 products confused. For C++, you use the ComponentWorks++ tools for Microsoft Visual C++. For Visual Basic, you use the ComponentWorks ActiveX controls.

A simple C++ VISA serial program follows. In additon to the port settings, it changes the termchar to carriage return '\r' and the timeout to 5 seconds:

CNiVisaSession io ("ASRL1::INSTR");
io.SetAttribute (VisaSerialBaudRate,115200);
io.SetAttribute (VisaSerialDataBits,7);
io.SetAttribute (VisaTerminationChar,0x0D);
io.SetAttribute (VisaTimeout,5000);
io.Write ("*IDN?\n");
CString buf;
io.Read (buf, 1024);
cout << "Identity: " << buf << endl;

Dan Mondrik
Senior Software Engineer, NI-VISA
National Instruments
0 Kudos
Message 2 of 4
(3,802 Views)
Measurement Studio for Visual C++ contains classes that communicate directly with the VISA library. You therefore do not need to use the VISA ActiveX control. You should instead use CNiVisaSession and its related classes.

The attached zip file contains a sample project that demonstrates using CNiVisaSession over serial.

I hope this is helpful.

David Rohacek
National Instruments
0 Kudos
Message 3 of 4
(3,802 Views)
As far as examples go, do you have a CNiVisaSession example that includes asynchronous communication. I'm having trouble getting the callback handler working.

class SerialDlg : public CDialog
{
...
CNiVisaSession *m_Session;
ViStatus AsynchEventHandler(CNIVisaEvent& event);
}


BOOL SerialDlg::OnInitDialog()
{
...
m_Session = new CNiSession((NiString)"ASRL1::INSTR", VI_NULL, (uInt32)1000);
m_Session->InstallEventHandler(VisaEventIoComplete,AsynchEventHandler,userData);
...
}

I've had limited success in doing this. So far, I can only get it working if the callback is a c declared, I'm hoping to have the callback a class member function as shown above. I've spent quite a bit of time trying the OnVisaEventHandler macro without any luck.

Tha
nks,
Lyle
0 Kudos
Message 4 of 4
(3,802 Views)