打开串行端口时出错 - Arduino

打开串行端口时出错 - Arduino

我尝试将 arduino 代码上传到 Arduino Mega。第一次插入电路板时检测到串行端口。上传后,我收到一条错误消息,提示“打开串行端口时出错”。然后串行端口选项在一段时间内不可用。下次尝试上传时,错误会重复出现。

Binary sketch size: 1,500 bytes (of a 258,048 byte maximum)
processing.app.SerialException: Error opening serial port    '/dev/ttyACM0'.
at processing.app.Serial.<init>(Serial.java:178)
at processing.app.Serial.<init>(Serial.java:77)
at processing.app.debug.Uploader.flushSerialBuffer(Uploader.java:77)
at processing.app.debug.AvrdudeUploader.uploadViaBootloader(AvrdudeUploader.java:175)
at processing.app.debug.AvrdudeUploader.uploadUsingPreferences(AvrdudeUploader.java:67)
at processing.app.Sketch.upload(Sketch.java:1671)
at processing.app.Sketch.exportApplet(Sketch.java:1627)
at processing.app.Sketch.exportApplet(Sketch.java:1599)
at processing.app.Editor$DefaultExportHandler.run(Editor.java:2380)
at java.lang.Thread.run(Thread.java:745)
Caused by: gnu.io.UnsupportedCommOperationException: Invalid Parameter
at gnu.io.RXTXPort.setSerialPortParams(RXTXPort.java:213)
at processing.app.Serial.<init>(Serial.java:163)
  ... 9 more
processing.app.debug.RunnerException: Error opening serial port '/dev/ttyACM0'.
at processing.app.debug.Uploader.flushSerialBuffer(Uploader.java:101)
at      processing.app.debug.AvrdudeUploader.uploadViaBootloader(AvrdudeUploader.java:175)
at
processing.app.debug.AvrdudeUploader.uploadUsingPreferences(AvrdudeUploader.java:67)
at processing.app.Sketch.upload(Sketch.java:1671)
at processing.app.Sketch.exportApplet(Sketch.java:1627)
at processing.app.Sketch.exportApplet(Sketch.java:1599)
at processing.app.Editor$DefaultExportHandler.run(Editor.java:2380)
at java.lang.Thread.run(Thread.java:745)

答案1

为了解决这个问题,我将自己添加到拥有端口设备的组(记忆中的拨号或拨出组)。要么这样做,要么使端口设备可全部写入。

答案2

可能是Mega不在串行端口/dev/ttyACM0:首先检查端口是否正确。

如果端口号正确,那么串口可能没有权限在用户模式下打开。尝试通过输入以下内容进行调整

sudo chmod a+rw /dev/ttyACM0

在终端上(通过Ctrl+ Alt+打开T)。

相关内容