필터 지우기
필터 지우기

Using the NI Switch Add-on

조회 수: 4 (최근 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개)

카테고리

Help CenterFile Exchange에서 Interface-Based Communication에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by