LoginSignup
3
2

More than 5 years have passed since last update.

python3 pyserial メモ

Posted at
1 / 2

ubuntu: permission denied

/dev/ttyのアクセスでpermission denied食らって,
ユーザーがttyのグループに入ってなかったら

$gpasswd -a USERNAME dialout

でユーザー追加する.(/dev/ttyのグループ: dialout)
一旦ログアウトして,ログインし直したらできるようになってるはず.

読み書き

write

byteで書き込む

serial.py
import serial

with open("/dev/tty~~", 38400) as ser:
   ser.write(b"hoge")
   ser.write("hoge".encode('utf-8'))

read

ser.read(n)
ser.readline()

read(n)でn文字読み込む
readlineで"\n"まで読み込む
"\n"が来るかわからないときはread()で読み込む.
全部byteで返ってくるくるからdecode('utf-8')とかする.

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2