在Python中COM口的调用方法

yipeiwu_com5年前Python基础

如下所示:

import serial
import time

t = serial.Serial('com6', 115200) #USB COM number on your PC and the transfer bit rate of the COM port.
print t.portstr #Display the working UART port number on your PC.
n = t.write('logcat -c \r')
n = t.write('ampclient_samples 2 -O 3 /mnt/media_rw/B278-E25A/video_google_clips/New_Webm/bunny_1080P.webm \r')
time.sleep(3)
print "Does the stream output normally? Yes=1 or No=2"
Input = int(raw_input())
if Input == 1:
  print "Pass!!!"
  n = t.write(chr(0x03)) #Call for Ctrl+C command in UART port
  n = t.write('logcat -c \r')
else:
  print "Fail!!!"
  n = t.write(chr(0x03))
  #n = t.write('logcat -v threadtime /r')

以上这篇在Python中COM口的调用方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python中文乱码的解决方法

乱码原因: 源码文件的编码格式为utf-8,但是window的本地默认编码是gbk,所以在控制台直接打印utf-8的字符串当然是乱码了! 解决方法: 1、print mystr.deco...

python 实现返回一个列表中出现次数最多的元素方法

如下所示: # 返回一个列表中出现次数最多的元素 def showmax(lt):     index1 = 0  ...

Python常见文件操作的函数示例代码

复制代码 代码如下: # -*-coding:utf8 -*- ''' Python常见文件操作示例 os.path 模块中的路径名访问函数 分隔 basename() 去掉目录路径,...

python 使用opencv 把视频分割成图片示例

我就废话不多说了,直接上代码吧! #--coding:utf-8-- import cv2 #图像路径名字错误不提示 im=cv2.imread("timg.jpg",cv2...

python批量修改文件夹及其子文件夹下的文件内容

python批量修改文件夹及其子文件夹下的文件内容

前言:前几天我看一位同学要修改很多文件中的数据,该文件数据很规律,一行只有三个数,需要将每行最后一个数字改为负数,但文件有上千个,分布在每个文件夹下面以及它的多级子文件夹下,看他用exc...