matlab读串口数据问题
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了matlab读串口数据问题相关的知识,希望对你有一定的参考价值。
用matlab设计GUI界面,使他具有读串口数据的功能,请问,应该如何编程,使它能不断连续读串口,而不用人工一直去控制它读!!!
总而言之,就是当我只要按一次开始读串口按钮,然后它就会自动的一直读数据,再经过处理就可以实时的实现某种功能!!!1
comPort=get(handles.pumComPort,'String');
handles.u_sCom=serial(comPortget(handles.pumComPort,'Value'));
baudRate=get(handles.pumBaudRate,'String');
set(handles.u_sCom,'BaudRate',str2double(baudRateget(handles.pumBaudRate,'Value')));
dataBits=get(handles.pumDataBits,'String');
set(handles.u_sCom,'DataBits',str2double(dataBitsget(handles.pumDataBits,'Value')));
stopBits=get(handles.pumStopBits,'String');
set(handles.u_sCom,'StopBits',str2double(stopBitsget(handles.pumStopBits,'Value')));
parity=get(handles.pumParity,'String');
if strcmp(parity,'无')==1
set(handles.u_sCom,'Parity','none');
else
if strcmp(parity,'奇校验')==1
set(handles.u_sCom,'Parity','odd');
else
if strcmp(parity,'偶校验')==1
set(handles.u_sCom,'Parity','even');
else
set(handles.u_sCom,'Parity','none');
end
end
end
flowControl=get(handles.pumFlowControl,'String');
if strcmp(flowControl,'无')==1
set(handles.u_sCom,'FlowControl','none');
else
if strcmp(flowControl,'硬件')==1
set(handles.u_sCom,'FlowControl','hardware');
else
if strcmp(flowControl,'软件')==1
set(handles.u_sCom,'FlowControl','software');
else
set(handles.u_sCom,'FlowControl','none');
end
end
end
set(handles.u_sCom,'Timeout',1);
set(handles.u_sCom,'InputBufferSize',1024);
set(handles.u_sCom,'BytesAvailableFcnMode','byte');
set(handles.u_sCom,'BytesAvailableFcnCount',1);
set(handles.u_sCom,'BytesAvailableFcn',@BytesAvailableFcnCallback,handles);
fopen(handles.u_sCom);
set(handles.txtStatus,'String','打开端口成功');
set(hObject,'Enable','off');
set(handles.btnClosePort,'Enable','On');
guidata(hObject,handles);
set(handles.btnSendData,'Enable','On');
至于全部程序已经发给你了。 参考技术A 记得 有个 网友 有 这样的 程序包
找找
祝你顺利
知道了
彭军 <pj0377@gmail.com> 参考技术B 兄弟能发我一份么?十分感谢啊 h254180743@126.com
matlab读.mat写入txt
问题:
读VehicleInfo.mat里面的数据,存入一个.txt文件中
代码:
load(‘VehicleInfo.mat‘); sz = size(VehicleInfo); nums = sz(1); anno = VehicleInfo; fout=fopen(‘bit_vehicles_anno.txt‘, ‘w‘); for i=1:nums name = anno(i).name; height = anno(i).height; width = anno(i).width; vehicles = anno(i).vehicles; nVehicles = anno(i).nVehicles; for j=1:nVehicles left = num2str(vehicles(j).left); top = num2str(vehicles(j).top); right = num2str(vehicles(j).right); bottom = num2str(vehicles(j).bottom); cls_name = vehicles(j).category; %fprintf(fout, ‘%s;%d;%d;%d;%d;%d;%d;%s ‘, % name, height, width, left, top, right, bottom, cls_name); outline = [name, ‘;‘, left, ‘;‘, top, ‘;‘, right, ‘;‘, bottom, ‘;‘, cls_name, ‘ ‘]; fprintf(fout, outline); end end fclose(fout);
以上是关于matlab读串口数据问题的主要内容,如果未能解决你的问题,请参考以下文章