赞
踩
一.serial串口通信
#!/usr/bin/python import serial ser = serial.Serial('COM5', 115200)#串口通信链接:端口号、波特率、时间 ''' 端口通信格式: ser = serial.Serial('port', baudrate) ser.write("指令协议")''' class Can_Off: def __init__(self): self.TYPE_ID = [0xA0] self.NODE_IDA = [0x0J]#电机版1 self.NODE_IDB = [0x0K]#电机版2 self.LENGTH = [0x05, 0x00] self.data1 = [0x0a, 0x0f, 0x0f, 0x0f] def co_action(self, arg=1): # arg:0-路径1,1路径2 try: ser.write(cal.PacketData(self.TYPE_ID, self.NODE_IDA, self.LENGTH, self.data1, arg)) ser.write(cal.PacketData(self.TYPE_ID, self.NODE_IDB, self.LENGTH, self.data1, arg)) except Exception as ex: print(ex) if __name__ == "__main__": Can_off.co_action()
#!/usr/bin/python import socket class Aut: def __init__(self,addr): self.addr = RemoteAddr#测试机“IP+端口号” self.ab = b'\x01' def au_one(self): try: s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.sendto(self.ab, self.addr) except Exception as ex: print(ex) RemoteAddr=(“*.*.*.*”,*) au=Aut(RemoteAddr) if __name__ == "__main__": au.au_one()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。