function sosibitsub(spo,bit,mode) % SOSI-M2 V1.0 MATLAB M-file % % Set channel mode to analog, digital input, or digital output % % Arguments: sosibit(spo,bit,mode) % % spo: serial port object % bit: channel 0 - 6 % mode: 'ai' analog input % 'do' digital output % 'di' digital input delayt=0.1; % set up channel number string s1=sprintf('#sec%d',bit) % Set up mode and I/O strings if mode(1)=='a' s2='#a'; % analog elseif mode(1)=='d' s2='#d'; if mode(2)=='o' s3='#o'; elseif mode(2)=='i' s3='#i'; else disp('error: (mode) string'); return; end else disp('error: (mode) string'); return; end cmd(spo,s1,delayt); % Set channel number cmd(spo,s2,delayt); % Set channel type if mode(1)=='d' cmd(spo,s3,delayt); % Set I/O if digital end cmd(spo,'#e',0.5); % exit, extra delay % Set output channel state % s3=sprintf('#o%dh',bit); % output n high % s4=sprintf('#o%dl',bit); % output n low % cmd(spo,s3,delayt); return;