Python 3 TCP / IP ascii命令 [英] Python 3 TCP/IP ascii command

查看:408
本文介绍了Python 3 TCP / IP ascii命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向我的步进驱动器发送ascii命令(RV是移动命令)。
但是我尝试过的所有内容都以Python(我认为)为string的开头添加了一个额外的字符;在这种情况下,它添加了一个g。步进器命令终端不添加g。

I am trying to send an ascii command to my stepper drive (RV which is the move command). but everything that I have tried ends up with Python (I think) adding an extra character to the beginning of the "string"; in this case it added a "g". The stepper command terminal does not add the "g".

来自Wireshark

0000  00 04 a3 22 56 6e f0 1f  af 0b ba fd 08 00 45 00   ..."Vn.. ......E.
0010  00 20 35 b5 00 00 80 11  00 00 c0 a8 4b 62 c0 a8   . 5..... ....Kb..
0020  4b 96 d6 a3 1e 5f 00 0c  18 67 52 56 0a 20         K...._.. .gRV.   

Python

def main():
    import socket

    data1 = bytes('RV\n ', 'ascii')
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.connect(("108.108.108.150",7775))
    s.send(data1)


if __name__ == '__main__':
    main()


推荐答案

除非你知道每个字节的含义,否则你不应该对数据包中的任何可打印字符串做出假设。
在这种特殊情况下,字节' .g'或0x18 0x67是UDP chec ksum.AFAIK,它可以以某种方式被禁用。如果您的接收器将获得此数据包,则其数据字段中将包含52 56 0a 20(RV \ n)。
这就是为什么你总是通过略微改变有效载荷和[可能] udp源端口获得'cRV'或'eRV'。

You should never make an assumption on any 'printable' strings in packets, unless you know the meaning of every byte. In this particular case, bytes '.g', or 0x18 0x67 are UDP checksum. AFAIK, it can be disabled somehow. If your receiver will get this packet, it will have 52 56 0a 20 ("RV\n ") in its data field. Thats why you always get 'cRV' or 'eRV' by slightly changing payload and [maybe] udp source port.

这篇关于Python 3 TCP / IP ascii命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆