3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

python3 pyserial メモ

3
Posted at
Page 1 of 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
3
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
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?