Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Need help with simple VS2005 C++ code

I'm not sure if I am doing something wrong, or if the Switch Front Panel isn't expected to reflect the results of my code.  I have a virtual 1163 cart setup in MAX.  I start the Switch Soft Front Panel and can see the state of the channels. I have auto refresh turned on.

My C++ code has a task generated by the .mxb file.  The channel is configured this way: 

void CDAQmxTask::Configure()
{
    
   CNiDAQmxDOChannel ch = DOChannels.CreateChannel("SC1Mod6/port0/line2", "DigitalOut", DAQmxOneChannelForEachLine);
    ch.InvertLines = false;

}

 

For simplicity sake, I create a gobal instance  of this class at the top of the dlg class file:

 

CDAQmxTask task;

I have a single button that when pressed should turn on channel 2 

void CFVT_TestAppDlg::OnBnClickedButton1()
{
    task.Stop();
    CNiDAQmxDigitalSingleChannelWriter* writer = new CNiDAQmxDigitalSingleChannelWriter(task.Stream);
    writer->WriteSingleSampleSingleLine(TRUE, TRUE);
    delete writer;
   
}
 

Should I expect to see teh results of this code in either the Schematic or Relays tab of SwitchSoft FP?

 

0 Kudos
Message 1 of 2
(6,507 Views)

AiR_GuNNeR,

 

You will not see the NI-Switch Soft Front Panel (SSFP) update to reflect the results of your Visual Studio code.  This is because NI-Switch is an IVI compliant driver, and IVI compliance for switches requires the driver to be able to open multiple driver sessions with one switch.  As a result, your C++ program and the SSFP have each established a seperate, independant IVI driver session to the switch.

 

For example, if your C++ program instructs Relay 1 to close, the relay will close.  Then, if the SSFP instructs Relay 1 to close, nothing will happen since the relay is already closed.  The SSFP can also instruct Relay 1 to open, and it will, regardless of the fact that your C++ program gave no such command.

 

As a result, it is important that for switching applications, you be sure that you only have one session open to a given switch at a time, otherwise you may see unexpected behavior.  This can even happen within an application.

 

You can lock a session within your application so that no other thread in your application can access that driver session.  Do this using the niSwitch_LockSession function.  You can find more information on this function in the NI-Switch shipping help.

Seth B.
Principal Test Engineer | National Instruments
Certified LabVIEW Architect
Certified TestStand Architect
0 Kudos
Message 2 of 2
(6,467 Views)