最新消息:因从typecho切换到wordpress, 由于转换导入问题,文章可能存在部分乱码或者排版问题,逐个排查修复中...

写写代码:Python Socket 通讯

写写代码 admin 935浏览 0评论

往特定端口发送特定数据
代码如下:

    #!/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 通讯

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址