當前位置:首頁 » 安全設置 » python設置網路通訊協議
擴展閱讀
異種網路連接方法 2024-05-24 01:14:10
華為p40手機網路斷流 2024-05-24 00:55:16

python設置網路通訊協議

發布時間: 2024-04-22 06:17:01

㈠ 濡備綍閲囩敤tcp閫氫俊璁捐″湪綰跨洃嫻嬬郴緇

閲囩敤tcp閫氫俊璁捐″湪綰跨洃嫻嬬郴緇熸ラゅ備笅錛
1銆佺『瀹氶氫俊闇奼傦細鏄庣『鍦ㄧ嚎鐩戞祴緋葷粺鐨勯氫俊闇奼傦紝鍖呮嫭闇瑕佸疄鏃朵紶杈撶殑鏁版嵁綾誨瀷銆佹暟鎹浼犺緭棰戠巼銆侀氫俊寤惰繜瑕佹眰絳夈傛牴鎹闇奼傜『瀹氶噰鐢═CP閫氫俊鍗忚銆
2銆佺綉緇滄灦鏋勮捐★細璁捐″湪綰跨洃嫻嬬郴緇熺殑緗戠粶鏋舵瀯錛屽寘鎷鏈嶅姟鍣ㄥ拰瀹㈡埛絝涔嬮棿鐨勮繛鎺ユ柟寮忓拰鎷撴墤緇撴瀯銆傛湇鍔″櫒浼氫綔涓烘暟鎹涓蹇冿紝鑰屽㈡埛絝璁懼囦細榪炴帴鍒版湇鍔″櫒榪涜屾暟鎹浼犺緭銆
3銆侀夋嫨緙栫▼璇璦鍜屽紑鍙戝鉤鍙幫細鏍規嵁瀹為檯闇奼傚拰璁懼囧鉤鍙伴夋嫨鍚堥傜殑緙栫▼璇璦鍜屽紑鍙戝鉤鍙版潵瀹炵幇TCP閫氫俊鍔熻兘銆傚父瑙佺殑緙栫▼璇璦濡侾ython銆丆++銆丣ava絳夐兘鏀鎸乀CP閫氫俊搴擄紝鍙浠ユ牴鎹寮鍙戣呯殑鐔熸倝紼嬪害鍜岄」鐩闇奼傝繘琛岄夋嫨銆
4銆佸疄鐜癟CP閫氫俊錛氫嬌鐢ㄩ夊畾鐨勭紪紼嬭璦鍜屽紑鍙戝鉤鍙幫紝緙栧啓鏈嶅姟鍣ㄥ拰瀹㈡埛絝鐨勪唬鐮佸疄鐜癟CP閫氫俊鍔熻兘銆傛湇鍔″櫒璐熻矗鎺ユ敹鏉ヨ嚜瀹㈡埛絝鐨勬暟鎹璇鋒眰鍜岃繑鍥炴暟鎹錛屽㈡埛絝璐熻矗鍙戦佹暟鎹緇欐湇鍔″櫒銆
5銆佹暟鎹浼犺緭鏍煎紡錛氳捐″湪綰跨洃嫻嬬郴緇熺殑鏁版嵁浼犺緭鏍煎紡錛屽彲浠ヤ嬌鐢↗SON銆乆ML絳夊父瑙佺殑鏁版嵁鏍煎紡錛屼互渚垮湪鏈嶅姟鍣ㄥ拰瀹㈡埛絝涔嬮棿榪涜屾暟鎹鐨勮В鏋愬拰浼犺緭銆

㈡ Python濡備綍榪涜屽氫覆鍙i氫俊錛熶竴涓涓插彛鎺у埗鐢墊満 涓涓涓插彛閲囬泦鏁版嵁錛

涓嬭澆 pyserial鍖
def OpenCom(self,*args): #璁劇疆絝鍙e拰娉㈢壒鐜 selComPort =鈥榗om2鈥 #娉㈢壒鐜 selBaudRate =9600 #濂囧伓鏍¢獙 selParity = 'N' try: if(not self.mySerial): self.mySerial = serial.Serial(port=selComPort, baudrate=selBaudRate,bytesize=8,parity=selParity,stopbits=1,timeout=5) else: if(self.mySerial.isOpen()): self.mySerial.close() self.mySerial = serial.Serial(port=selComPort, baudrate=selBaudRate, bytesize=8, parity=selParity, stopbits=1, timeout=5) self.lblInfo['text'] = '鎵撳紑鎴愬姛錛' except Exception as ex: self.lblInfo['text'] = '鎵撳紑澶辮觸錛'

#浣跨敤com鍙e彂閫乵odbus鍗忚緇欑粓絝璁懼囥
def btnEmId_Click(self):
barray = bytearray([0x05, 0x03, 0xA#, 0x54, 0x00, 0x08])
vOldEmId = self.txbOldEmId.get()
vNewEmId = self.txbNewEmId.get()
barray[0] = int(vOldEmId)
barray[5] = int(vNewEmId)
#crc鏍¢獙
strInput = utils.crc16_append(barray)
print(barray)
n = self.mySerial.write(barray)
if(n > 0):
str = self.mySerial.readall()
self.lblInfo['text'] = 'success錛'
# for s in str:
# print (hex(s))
else:
self.lblInfo['text'] = 'error錛'