往特定端口发送特定数据
代码如下:
#!/usr/bin/python
#-*- encoding: utf-8 -*-
# By Linc Hu
# Date: 2017-02-15
import socket
import time
cubi_host = '192.168.168.168'
cubi_port = 88
if __name__=="__main__":
cubi_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
cubi_sock.connect((cubi_host, cubi_port))
print ('Sending Command...')
cubi_sock.send('\x02\x4D\x03\x0D\x0A')
# Must have time sleep, or else, data may not completed received.
time.sleep(2)
str_received = cubi_sock.recv(1024)
cubi_sock.close()
print (str_received)
# Save string to file for further analysis(Hex)
file_obj =open('cubiscan.txt','w')
file_obj.write(str_received)
file_obj.close()
另外附上Cubiscan 100的PDF说明文档,里面有提到指令这一块的内容:
m_Cubiscan100_v4.1.pdf
转载请注明:Linc Hu » 写写代码:Python Socket 通讯