【pySerial】micro:bit에 시리얼 통신시 「could not open port '/dev/cu.」에러가 나왔을 때에 생각할 수 있는 것
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/serial/serialposix.py", line 265, in open
self.fd = os.open(self.portstr, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK)
FileNotFoundError: [Errno 2] No such file or directory: '/dev/cu.usbmodem14302'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "testSerial.py", line 4, in
ser = serial.Serial(port,115200,timeout=None)
File "/usr/local/lib/python3.8/site-packages/serial/serialutil.py", line 240, in init
self.open()
File "/usr/local/lib/python3.8/site-packages/serial/serialposix.py", line 268, in open
raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg))
serial.serialutil.SerialException: [Errno 2] could not open port/dev/cu.usbmodem14302: [Errno 2] No such file or directory: '/dev/cu.usbmodem14302'
Arduino의 직렬 포트를 열면 오류
오류의
could not open port
라는 내용에서 USB 포트가 사용 중일 가능성이 있습니다.제 경우에는 Arduino의 시리얼 모니터를 열고 있었기 때문이었습니다.
※디버그를 위해서 사용하고 있었습니다.

닫으면 정상적으로 시리얼 통신 할 수 있었습니다.
마지막으로
이번 에러는 Arduino의 시리얼 모니터와 같이 시리얼 포트를 전유하는 일을 하고 있지 않는가 하는 시점을 가지는 것이 대처법이 될 것 같습니다.
파이썬 측
testSerial.py
import serial
mac='/dev/cu.usbmodem14302'
ser = serial.Serial(port,115200,timeout = None)
ser.write(b'1')
time.sleep(1)
ser.close()
micro:bit측(JavaScript)
receiveSerial.js
serial.setBaudRate(BaudRate.BaudRate115200)
basic.forever(function () {
str = serial.readString()
if (str.indexOf("1") >= 0) {
basic.showIcon(IconNames.Heart)
}
})
Reference
이 문제에 관하여(【pySerial】micro:bit에 시리얼 통신시 「could not open port '/dev/cu.」에러가 나왔을 때에 생각할 수 있는 것), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/ohbashunsuke/items/ea829f79a723406e9876텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)