01-27-2014 06:06 AM
Hello,
i have a problem with. I try to controll a PXI- 2527-switch by using c++ and I`m not very familiar with the subject. This is my code so far:
#include "stdafx.h"
#include "niswitch.h"
int _tmain(int argc, _TCHAR argv[])
{
ViSession Name = VI_NULL;
ViRsrc MUX = "PXI15::14";
ViConstString channel1 ="ch0";
ViConstString channel2 = "com0";
ViConstString topology = NISWITCH_TOPOLOGY_CONFIGURED_TOPOLOGY;
niSwitch_InitWithTopology(MUX, topology, VI_FALSE, VI_TRUE, &Name);
return 0;
-------------------------------
If I try to build this I got an error massage:
error LNK2019: unresolved external symbol "_niSwitch_InitWithTopology@20" in Funktion "_wmain".
But the function "niSwitch_InitWithTopology" is defined in the included header "niswitch.h".
Can somebody tell what I did wrong?
Thank you.
Peter
01-29-2014 06:21 AM
Hi,
this looks like you did not tell your development environment where to find the header file.
Follow these steps:
http://zone.ni.com/reference/en-XX/help/370388Y-01/switch/niswitch_c/
I hope this approach will solve your problem with the linker.
Best Regards,
JoLe
National Instruments
Applications Engineering
01-29-2014 09:13 AM
I don´t think that is the problem. Visual Studio has a seperate massage for an unlinked header. I´ve got that earlier. Maybe it is a Problem with the "niswitch.lib". I´ve linked it too but it isn´t included in the code.
02-03-2014 10:42 AM
disregarding you dont think that this is the problem, have actually tried to apply this step?
Specify the directory that contains the NI-SWITCH header file under the Preprocessor»Additional include directories settings in your compiler—for Visual C++ 6.0 these files are under Project»Settings»C/C++. The NI-SWITCH header files are located in the .\Include directory within your NI-SWITCH directory.
Add the NI-SWITCH import library niswitch.lib to the project under Link»General»Object/Library Modules. The NI-SWITCH import library files are located at IVI\Lib\msc.
Do you still get the error after applying this?
Best Regards,
JoLe
National Instruments
Applications Engineering
02-03-2014 11:41 AM
Hi JoLe,
I still get the error.
I have added the following directories under "Project - Properties - C/C++ - general - additional include directories":
IVI Foundation\VISA\Win64\Include
and
IVIFoundation\IVI\Include.
They both contain "niswitch.h" and a lot of other headers like "niswitchTopologies.h" and "visa.h". (They don´t contain the "niswitchErrorHandler.h")
The .lib directory is added under
"Project - Properties - Linker - general". The directory name is "IVIFoundation\IVI\Lib_x64\msc".
Thank you
einszweidrei456
02-05-2014 06:43 AM
Hi JoLe,
I have found my mistake. I have tried to build a 32bit-programm with a 64bit-library. Now the programm is compiled but it still doesn´t work. In the example code is the line
ViSession switchSession=VI_NULL
and I think VI_NULL is not the right parameter for my Session(, or is it?). Where can I get the right one?
Thank you.
Peter
02-05-2014 07:59 AM
Hi einszweidrei456,
great to hear, that you could fix the error with the library!
What you are asking now is a bit too unspecific to really know what you are doing and hence expecting.
- what exactly does not work?
- what are you doing? Are you trying to do a switching operation with existing hardware, which one?
- how is your code looking meanwhile?
- what do you expect your code to do?
- What should work, what do you expect to observe?
- You write "in the example code"
On which example do you actually build up your code?
- if you look to the examples which are delivered with the NI-Switch driver (C:\Program Files (x86)\IVI Foundation\IVI\Drivers\niSwitch\Examples\C), you will find this line in each of the examples:
ViSession switchSession = VI_NULL;
This is the initial value for this parameter. VI_NULL in the NI-Switch driver is the same as the usual NULL parameter in C++
In the following example code, you can see, that if the parameter switchSession has a different value from VI_NULL, it is an error case and the session to the switching hardware is closed.
/*
National Instruments - NI-SWITCH - CVI Examples
Controlling an Individual Relay
This example demonstrates how to control an individual relay on a switch module.
Refer to the NI Switches Help for the valid relay names for your switch module.
NI-SWITCH functions utilized:
niSwitch_InitWithTopology
niSwitch_RelayControl
niSwitch_WaitForDebounce
niSwitch_close
*/
#include "niswitch.h"
#include "niSwitchErrorHandler.h"
int main (void)
{
ViSession switchSession = VI_NULL;
ViStatus switchError = VI_SUCCESS;
ViRsrc resourceName = "Dev1";
ViConstString relayName = "b1r0c0";
ViInt32 relayAction = NISWITCH_VAL_CLOSE_RELAY; //NISWITCH_VAL_OPEN_RELAY to open relay.
ViConstString topology = NISWITCH_TOPOLOGY_CONFIGURED_TOPOLOGY;
//Open a session to the switch module and set the topology.
niSwitchCheckErr(niSwitch_InitWithTopology(
resourceName,
topology,
VI_FALSE,
VI_TRUE,
&switchSession));
//Open or Close the relay.
niSwitchCheckErr(niSwitch_RelayControl(
switchSession,
relayName,
relayAction));
//Wait for the relay to activate and debounce.
niSwitchCheckErr(niSwitch_WaitForDebounce(switchSession, 5000));
Error:
if (switchError < VI_SUCCESS)
{
//Display errors (if any).
niSwitch_ErrorHandler(switchSession, switchError);
}
if (switchSession != VI_NULL)
{
//Close the session to switch module.
niSwitch_close(switchSession);
}
return 0;
}
02-05-2014 08:34 AM
Hi,
i just want to connect and disconnect 2 channels on my PXI2527. This is the code that i have build to an .exe and it seems that the exe works but the switch doesn´t make the connections and I don´t see why not?
#include "stdafx.h"
#include "niswitch.h"
int _tmain(int argc, _TCHAR argv[])
{
ViSession Name = VI_NULL;
ViRsrc MUX = "PXI15::14";
ViConstString channel1 ="ch0";
ViConstString channel2 = "com0";
ViConstString topology = NISWITCH_TOPOLOGY_CONFIGURED_TOPOLOGY;
niSwitch_InitWithTopology(MUX, topology, VI_FALSE, VI_TRUE, &Name);
niSwitch_DisconnectAll(Name);
getchar();
niswitch_connect(Name, channel1, channel2);
getchar();
niSwitch_disconnect(Name, channel1, channel2);
getchar();
return 0;
Thank you.
Peter
02-07-2014 10:27 AM
Hi Peter,
please refer to the following example (delivered with the NI switch driver) to connect the channels of your switching modul.
You will find these examples in
C:\Program Files (x86)\IVI Foundation\IVI\Drivers\niSwitch\Examples\C (for a 64-bit machine)
Please post if deploying this code did work on your system.
Best Regards,
JoLe
National Instruments
Applications Engineering
/*
National Instruments - NI-SWITCH - CVI Examples
Making Connections on a Switch
This example demonstrates how to connect channels on a switch module.
Refer to the NI Switches Help for the valid channel names for your switch module.
NI-SWITCH functions utilized:
niSwitch_InitWithTopology
niSwitch_Connect
niSwitch_WaitForDebounce
niSwitch_close
*/
#include "niswitch.h"
#include "niSwitchErrorHandler.h"
int main (void)
{
ViSession switchSession = VI_NULL;
ViRsrc resourceName = "Dev1" ;
ViConstString channel1 = "r0";
ViConstString channel2 = "c0";
ViConstString channel3 = "r1";
ViConstString channel4 = "c1";
ViStatus switchError = VI_SUCCESS;
ViConstString topology = NISWITCH_TOPOLOGY_CONFIGURED_TOPOLOGY;
//Open a session to the switch module and set the topology.
niSwitchCheckErr(niSwitch_InitWithTopology(
resourceName,
topology,
VI_FALSE,
VI_TRUE,
&switchSession));
//Connect channel1 and channel2.
niSwitchCheckErr(niSwitch_Connect(switchSession, channel1, channel2));
//Wait for any relays to activate and debounce.
niSwitchCheckErr(niSwitch_WaitForDebounce(switchSession,5000));
//Connect channel3 and channel4
niSwitchCheckErr(niSwitch_Connect(switchSession, channel3, channel4));
//Wait for any relays to activate and debounce.
niSwitchCheckErr(niSwitch_WaitForDebounce(switchSession,5000));
Error:
if (switchError < VI_SUCCESS)
{
//Display errors (if any).
niSwitch_ErrorHandler(switchSession, switchError);
}
if (switchSession != VI_NULL)
{
//Close the session to switch module.
niSwitch_close(switchSession);
}
return 0;
}