Using the NI Switch Add-on

2 ビュー (過去 30 日間)
SnukeN3
SnukeN3 2020 年 6 月 10 日
回答済み: Nathan Davey 2020 年 6 月 23 日
I am looking for any information on using the NI-Switch add-on to control RF switches, example code, or a list of commands in NI-Switch. I am trying to control a NI-2545 and NI -2548 in a PXI chassis. Any help would be greatly appreciated!

採用された回答

Nathan Davey
Nathan Davey 2020 年 6 月 23 日
This works. The key is, you must disconnect from the switch after each action or you won't be able to make a new connection
%%Intialization Section
%set the address for the respective switchs. Second char is the location
%as seen by matlab
switch41 = icdevice('niswitch.mdd', 'Dev1');
switch42 = icdevice('niswitch.mdd', 'PXI1Slot6');
switch81 = icdevice('niswitch.mdd', 'PXI1Slot3');
switch82 = icdevice('niswitch.mdd', 'PXI1Slot7');
% Connect to the switches
connect(switch41);
connect(switch42);
connect(switch81);
connect(switch82);
%%Variable Creation and Conversion Section
%Convert channel strings to doubles
%NI_2548 switch position definitions
for i=0:3
eval(sprintf('com%i = [double(char(string("com%i"))) 0];', i, i));
end
for i=0:3
eval(sprintf('nc%i = [double(char(string("nc%i"))) 0];', i, i));
end
for i=0:3
eval(sprintf('no%i = [double(char(string("no%i"))) 0];', i, i));
end
%NI_2545 switch position definitions
com = [double('com') 0];
for i=0:3
eval(sprintf('ch%i = [double(char(string("ch%i"))) 0];', i, i));
end
%%Switch Manipulation Section
%create the child object for the switches
Chan_con_1 = get(switch41, 'Route');
Chan_con_2 = get(switch42, 'Route');
Chan_con_3 = get(switch82, 'Route');
Chan_con_4 = get(switch81, 'Route');
%Prior to switching to a position you must ensure that it is not already connected and you must...
%disconnect from the switch after use before being able to move the switch position to a new one.
%connects the common to desired switch position
invoke(Chan_con_1, 'connect', ch3, com );
pause(1);
invoke(Chan_con_2, 'connect', ch1, com );
pause(1);
invoke(Chan_con_3, 'connect', no0, com0 );
pause(1);
invoke(Chan_con_4, 'connect', no0, com0 );
pause(2);
%disconnect the switch channels
invoke(Chan_con_1, 'disconnectall');
pause(1);
invoke(Chan_con_2, 'disconnectall');
pause(1);
invoke(Chan_con_3, 'disconnect', no0, com0);
pause(1);
invoke(Chan_con_4, 'disconnect', no0, com0);
%%close the instrument object
disconnect(switch41);
disconnect(switch42);
disconnect(switch81);
disconnect(switch82);
%%clear the insrument object from the object list
delete(switch41);
delete(switch42);
delete(switch81);
delete(switch82);

その他の回答 (0 件)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by