poster
2019-12-10, 20:41
没有仪器控制工具箱,是否可以使用MATLAB建立GPIB连接? (我没有)。 MATLAB还提供了一种方法来了解外部设备的RS232参数值(波特率,停止位等)。对于RS232连接,我具有以下代码:
% This function is meant to send commands to Potentiostat Model 263A. % A run includes turning the cell on, reading current for time t1, turning % the cell off, waiting for time t2. % t1 is the duration [secs] for which the Potentiostat must run (cell is on) % t2 is the duration [secs] to on after off % n is the number of runs % port is the serial port name such as COM1 function [s] = Potentiostat_control(t1,t2,n) port = input('type port name such as COM1', 's') s = serial(port); set(s,'BaudRate', 9600, 'DataBits', 8, 'Parity', 'even', 'StopBits', 2 ,'Terminator', 'CR/LF'); fopen(s) %fprintf(s,'RS232?') disp(['Total runs requested = ' num2str(n)]) disp('i denotes number of runs executed so far..'); for i=1:n i %data1 = query(s, '*IDN?') fprintf(s,'%s','CELL 1'); % sends the command 'CELL 1' %fprintf(s,'%s','READI'); pause(t1); fprintf(s,'%s','CELL 0'); %fprintf(s,'%s','CLEAR'); pause(t2); end fclose(s)
回答:
对于您的GPIB问题,GPIB卡是否带有可调用的库(如果您在Windows上,则为DLL)? Matlab有一个用于调用外部库 (http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/f43202.html)的接口。基本程序是具有使用Matlab的解析头文件LOADLIBRARY ,然后查看使用可用功能LIBFUNCTIONS和使用呼叫功能CALLLIB 。
对于您的RS232问题,我认为在没有外部文档的情况下,主机端无法通过任何方式了解设备端的参数。
更多&回答... (https://stackoverflow.com/questions/2829650)
% This function is meant to send commands to Potentiostat Model 263A. % A run includes turning the cell on, reading current for time t1, turning % the cell off, waiting for time t2. % t1 is the duration [secs] for which the Potentiostat must run (cell is on) % t2 is the duration [secs] to on after off % n is the number of runs % port is the serial port name such as COM1 function [s] = Potentiostat_control(t1,t2,n) port = input('type port name such as COM1', 's') s = serial(port); set(s,'BaudRate', 9600, 'DataBits', 8, 'Parity', 'even', 'StopBits', 2 ,'Terminator', 'CR/LF'); fopen(s) %fprintf(s,'RS232?') disp(['Total runs requested = ' num2str(n)]) disp('i denotes number of runs executed so far..'); for i=1:n i %data1 = query(s, '*IDN?') fprintf(s,'%s','CELL 1'); % sends the command 'CELL 1' %fprintf(s,'%s','READI'); pause(t1); fprintf(s,'%s','CELL 0'); %fprintf(s,'%s','CLEAR'); pause(t2); end fclose(s)
回答:
对于您的GPIB问题,GPIB卡是否带有可调用的库(如果您在Windows上,则为DLL)? Matlab有一个用于调用外部库 (http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/f43202.html)的接口。基本程序是具有使用Matlab的解析头文件LOADLIBRARY ,然后查看使用可用功能LIBFUNCTIONS和使用呼叫功能CALLLIB 。
对于您的RS232问题,我认为在没有外部文档的情况下,主机端无法通过任何方式了解设备端的参数。
更多&回答... (https://stackoverflow.com/questions/2829650)