当前位置:   article > 正文

Jetson Nano 发送和接收串口数据_jetson nano串口发送变量

jetson nano串口发送变量

必要的包

pyserial模块封装了python对串口的访问,为多平台的使用提供了统一的接口。

sudo pip3 install pyserial
  • 1

程序

import serial 
import time
import binascii
num=[None]*5
ser=serial.Serial("/dev/ttyTHS1",115200) #使用THS1连接串行口,THS1,对应nano上面的物理引脚8 10
def recv():
    print("receive test.......")
    while True:
        for i in range (0,5):
            data=str(binascii.b2a_hex(ser.read(1)))[2:-1]
            num[i]=data     
        if((num[0]=='5a') and (num[1]=='a5')): 
            print(num)
def write():
    print("write test.......")
    while True:      
        flag="5AA50D8203105AA5010000020000"
        ser.write(bytes.fromhex(flag))
        time.sleep(1)        
op=input("enter the operation:")
if op =="0":
    recv()
elif op=="1":
    write()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

可能遇到的问题

串口权限不足的问题
解决办法:sudo chmod 777 /dev/ttyTHS1 (修改文件权限可读可写可执行)

提示

Serial.write() 发送的字节!!!!!!!
例如:用Serial.write(97) 发送的过程 【int 97 ——Serial.write() 发送97的ascii码(10010111)——串口监视器接收到ascii码,则会显示对应的字符即a,以十六进制显示的话为(0x61)】

参考

https://blog.csdn.net/qq_36895854/article/details/88925939

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/399369
推荐阅读
相关标签
  

闽ICP备14008679号