串口对象无法在MATLAB中读取数据

问题描述

我创建了一个 MATLAB 应用程序,该应用程序从由柔性传感器创建的数字信号中获取数据。当我尝试运行该应用程序时,它提示警告:

警告:指定数量的数据未在指定时间内返回 'readline' 的超时期限。 'serialport' 无法读取任何数据。有关可能的更多信息 原因,请参阅串行端口读取警告。

我已经检查了硬件连接到哪个串口,我已经检查了configureTerminator,以及串口对象是否被正确创建。有没有人碰巧知道导致问题的原因是什么???

下面是我为 MATLAB 应用程序编写的代码,它应该在单击“开始”按钮时获取数据,并可以选择将数据保存到 .csv 文件。

app.SerialPortDropDown.Value 链接到 serialportlist("available")。

    % Button pushed function: StartButton
    function StartButtonPushed(app,event)
        app.stopButtonPressed = false;

        try 
        app.arduinoObj = serialport(app.SerialPortDropDown.Value,str2double(app.BaudRateDropDown.Value));
        catch 
            warning('Problem with Serial Port');
            delete(app.arduinoObj);
            return;
        end
        
        configureTerminator(app.arduinoObj,"CR/LF");
        app.arduinoObj.DataBits = 8;
        app.arduinoObj.StopBits = 1;
        flush(app.arduinoObj);
        app.arduinoObj.UserData = struct("Data",[],"Count",1);

        t0 = clock;
        app.startTime = datetime;
        i = 1;
        
        while (etime(clock,t0) < app.RecordingDurationsSpinner.Value) && (app.stopButtonPressed == false)
            app.data(i) = str2double(readline(app.arduinoObj));
            app.times(i) = etime(clock,t0);
            
            if not(isnan(app.data(i)))
                app.DegreeofFlexGauge.Value = app.data(i);
                
                percent = 100.*app.times(i)./app.RecordingDurationsSpinner.Value;
                
                if round(percent) == 100
                    percent = 100;
                end
                
                app.ElapsedTimeLabel.Text = ['Elapsed time: ' num2str(percent) '%'];
                i = i+1;
            end
        end
        
        app.SavetoFileButton.Enable = true;

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...