1 Star 0 Fork 0

youxinweizhi/IR_to_PC

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.py 1.31 KB
一键复制 编辑 原始数据 按行查看 历史
youxinweizhi 提交于 2019-02-20 15:41 +08:00 . First submission
#by:youxinweizhi
#precondition
# usb to ttl module
# IR decoding module
#wiring
# ttl IR
# 5V 5V
# gnd gnd
# Tx Rx
# Rx Tx
#
#
#main.py 后台程序
#config.conf 定义pc程序路径
import serial,os
import configparser
class IR_to_PC(object):
def __init__(self,com,baudrate=9600):
self.com=com
self.baudrate=baudrate
self.ser = serial.Serial(port=self.com,baudrate=self.baudrate)
self.cf=configparser.ConfigParser()
self.cf.read('./config.conf',encoding='utf-8')
self.map={}
self.map['69']='aj_1'
self.map['70']='aj_2'
self.map['71']='aj_3'
self.map['68']='aj_4'
self.map['64']='aj_5'
self.map['67']='aj_6'
self.map['7']='aj_7'
self.map['21']='aj_8'
self.map['9']='aj_9'
def control(self):
while 1:
try:
data=self.ser.read_all()
if len(data)>0:
if data[0]==0 and data[1]==255:
key=self.map[str(data[2])]
program_path=r'"%s"'%self.cf.get('config',key)
os.system(program_path)
print('开始运行:%s'%program_path)
except KeyError:
pass
test=IR_to_PC('com3')
test.control()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/youxinweizhi/IR_to_PC.git
git@gitee.com:youxinweizhi/IR_to_PC.git
youxinweizhi
IR_to_PC
IR_to_PC
master

搜索帮助