具有struct和byte顺序的prob

编程入门 行业动态 更新时间:2024-10-08 00:31:47
本文介绍了具有struct和byte顺序的prob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

你好,所有。 i有一个困难的应用程序连接到服务器以获取 我们数据库的信息。 这个服务器是我们现场的一些设备的接入点,我们需要b $ b监视器。 消息通过套接字连接进入。根据他们的 (非常有限)文档,按特定顺序设置。喜欢 这个 STX [长度指示器] [消息类型] [消息体] ENX 长度指示器= 4字节的消息体长度 消息类型=发送什么类型消息的代码 例如200 =登录 message body =发送到服务器的实际命令 STX和ENX是指定用于启动和停止消息的值。 他们字面上是' 'STX''和''ENX'' 当我捕捉到一条消息时我可以将它打印到屏幕上并且''STX''在 的开头和''ENX''在最后是可辨别的,但其余的 消息看起来像这样.. \ x00 \ x00 \ x00,\ x00 \ x00 \ x00 \ e17758 \ x00 \ x00等等... ,其中包含一些逗号和其他符号。 (17758之前的e 上面有一顶小帽子) 如果我将它打印成文本文件,我会得到这个... STXNULNULNULea17758NULLNULL等.. 现在17758很重要,因为它是我们要监控的机器的实际单位数 。我只是不知道如何从这条消息中提取 的实际值。 任何人都知道从哪里开始?我已经尝试过struct, 但是对它不太了解。有没有人知道关于 学习字节码等的好教程。蟒蛇网站上的文档很好地解释了 模块,但我仍然不知道如何处理它。或者如何生成一条消息或拉开这些值以获得服务器发送给我们的信息 。 谢谢 sk

解决方案

ne ***** @ xit 写道:

你好,全部。 i有一个困难的应用程序连接到服务器以获取 我们数据库的信息。 这个服务器是我们在该领域的一些设备的接入点我们 显示器。 消息通过套接字连接进入。根据他们的 (非常有限)文档,按特定顺序设置。喜欢 这个 STX [长度指示器] [消息类型] [消息体] ENX 长度指示器= 4字节的消息体长度 消息类型=发送什么类型消息的代码 例如200 =登录 message body =发送到服务器的实际命令 STX和ENX是指定用于启动和停止消息的值。 他们字面上是' 'STX''和''ENX''

我相信你,但这显然是对单字符的歪曲 " ;开始传播和传输结束这是 ASCII字母表的一部分。因此协议设计师可能缺乏经验, 并且文档可能会混淆...

> 当我捕捉到一条消息时,我可以将它打印到屏幕上,并且STX在 开头,而ENX在结尾处是可辨别的,但其余的 消息看起来像这样.. \ x00 \ x00 \ x00,\ x00 \ x00 \ x00 \ e17758 \ x00 \ x00等等...... ,其中有一些逗号和其他符号。 (17758之前的e 上面有一顶小帽子) 如果我将它打印成文本文件,我会得到这个... STXNULNULNULea17758NULLNULL等..

\ x00"是包含 空字节的单字节字符串的Python repr()(即十进制值为零的字节)。

现在17758非常重要,因为它是我们想要监控的机器的实际单元数 。我只是不知道如何从这条消息中提取 的实际值。 任何人都知道从哪里开始?我已经尝试过struct, 但是对它不太了解。有没有人知道关于 学习字节码等的好教程。蟒蛇网站上的文档很好地解释了 模块,但我仍然不知道如何处理它。或者如何生成一条消息或拉开这些值,以便从服务器发送给我们的消息中获取消息。

好​​吧,如果您看到的字符串(当您从Python打印时)看起来像 " STX \ x00 \ x00 \ x00,\ x00 \ x0000 \ x00 \ e17758 \ x00 \ x00 ... ETX" 然后它看起来像你想要的字节可以获得,假设 字符串存储在变量s中,如s [12:17]。

>> s =" STX \x00 \ x00 \ x00,\ x00 \ x00 \ x00 \ e17758 \ x00 \ x00 ... ETX" s [12 :17]

''17758''

>>>

您可能需要稍微调整一下索引,但其中一个是的乐趣之一Python是交互式翻译非常合作的! 祝你好运。 问候 Steve - Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC / Ltd www.holdenweb Skype:holdenweb holdenweb.blogspot 最近的Ramblings del.icio.us/steve.holden

2006-07-24,Steve Holden< st *** @ holdenwebwrote:

ne ***** @ xit 写道:

>你好,所有。 我有一个困难的应用程序连接到服务器,以获取我们数据库的信息。这个服务器是我们监控的现场设备的接入点。 消息通过套接字连接进入。根据他们的(非常有限的)文档,按特定顺序设置。喜欢这个 STX [长度指示器] [消息类型] [消息体] ENX 长度指示器= 4字节消息体长度消息类型=正在发送什么类型消息的代码例如200 =登录消息正文=发送到服务器的实际命令 STX和ENX是指定用于启动和停止消息的值。它们实际上是''STX''和''ENX''

我相信你,但这显然是对 单字符传输开始的歪曲。和b / b 传输结束这是ASCII字母表的一部分。所以 协议设计师可能缺乏经验, 文档可能会混淆...

我有同样的反应:肯定他的意思是框架被提交 开头由ASCII STX字符(0x02)和结尾 由ETX字符(0x03) 。 如果某人确实发送三个字符串STX 来标记一个帧的开头并且ENX正在发送。为了纪念结束, 然后他们会非常困惑(并且不能拼写)。

>当我捕捉到一条消息时,我可以将它打印到屏幕上,并且在开头的'STX''和最后的''ENX'是可辨别的,但其余部分是可以辨别的。消息看起来像这样.. \ x00 \ x00 \ x00,\ x00 \ x00 \ x00 \ e17758 \ x00 \ x00等等等等在那里......还有一些逗号和其他符号。 (17758之前的e 上面有一个小帽子)

所以单位数是一个ASCII字符串。首先,我建议用十六进制打印消息: print''''。join(["%02.2x"%ord} (b)对于b中的消息]) 这应该可以更容易地计算出哪些字节索引 包含您正在寻找的信息。

>如果我把它打印成文本文件,我得到这个... STXNULNULNULea17758NULLNULL等..

我不知道如何打印上面显示的字符串 就像那样。 \ x00"是包含 空字节的单字节字符串的Python repr()(即十进制值为零的字节)。

>现在17758非常重要,因为它是我们想要监控的机器的实际单元数。我只是不知道如何从这条消息中提取出真正的价值。

什么是真实值?

>任何人都知道从哪里开始?我已经尝试过 struct,但对它不了解。有没有人知道关于学习字节码等的好教程。

什么是字节代码?

>蟒蛇网站上的文档很好地解释了模块,但我仍然不知道如何处理它。

您必须弄清楚您关心的对象的 消息中的格式和位置。一旦你知道了,你就用使用struct来取出适当的字节并将它们转换成Python对象。 如果你知道(或怀疑)消息中有IEEE 754 32位浮动点值,然后开始将所有可能的4个字节块转换为Python浮点数(使用两个endian 约定),直到看到你识别的数字。 64位浮点数和各种大小的整数值相同。 - 格兰特爱德华兹格兰特哇!人类REPLICAS 插入VATS visi NUTRITIONAL YEAST ...

好的,我做了这个打印''''。join([%02.2x"%ord(b)for b in message]) 我在文本文件中得到了这个 5354580000002c000000ea3137353834363638353500000000 000000000000000000000000000000000000d6090d54000000 00454e58 所以,是的,现在更多的信息似乎是可辨别的。 根据他们的文档,所有变量都以32bit的形式发送很长 int(优先unsigned long int)。 我们试图与之交谈的服务器上的开发人员发布了 api for C(也许是C ++),它出现在一个osx模块中,其中一个被认为是导入Visual Basic的。我没有开发Visual Basic,或者是 windows或C或C ++。所以我的挑战是在debian linux上从python中获得一些相同的 功能。 osx模块是他们给开发人员的东西 的应用程序需要与此服务器通信。 起始和结束的分隔符是ASCIISTX和ENX。我想知道为什么他们也这样做了。但他们确实这样做了。 消息长度是一个4字节的整数,表示消息 正文的持续时间。 消息type也是4个字节。文档中有一个表格, 描述了每种消息的类型。例如200 =登录, 等等... 文档中的重要内容是关于客户端如何需要字节 为了匹配服务器在Sun UltraSPARC上运行的拱门,我认为他们运行的是Solaris。 ,如果我听起来像我不知道我在说什么......有一个原因......我对这种与服务器的沟通很新。 我用python(我的第一语言)约有6个月。 感谢您的帮助,男士们。 -sk Grant Edwards写道:

2006-07-24,Steve Holden< st *** @ holdenwebwrote:

ne*****@xit 写道: 你好,所有。 i有一个困难的应用程序连接到服务器以获取信息 我们的数据库在这里。 这个服务器是我们现场的一些设备的接入点,我们 监视器。 消息来自套接字连接。根据他们的 (非常有限)文档,按特定顺序设置。喜欢 这个 STX [长度指示器] [消息类型] [消息体] ENX 长度指示器= 4字节的消息体长度 消息类型=发送什么类型消息的代码 例如200 =登录 message body =发送到服务器的实际命令 STX和ENX是指定用于启动和停止消息的值。 他们字面上是' 'STX''和''ENX''

我相信你,但这显然是对的歪曲单字符传输开始和b / b 传输结束这是ASCII字母表的一部分。所以 协议设计师可能缺乏经验, 文档可能会混淆...

我有同样的反应:肯定他的意思是框架被提交 开头由ASCII STX字符(0x02)和结尾 由ETX字符(0x03) 。 如果某人确实发送三个字符串STX 来标记一个帧的开头并且ENX正在发送。为了纪念结束, 然后他们会非常困惑(并且不能拼写)。

当我捕捉到一条消息时,我可以将它打印到屏幕上,并且STX在 开头,而ENX在结尾处是可辨别的,但剩下的 消息看起来像这样.. \ x00 \ x00 \ x00,\ x00 \ x00 \ x00 \ e17758 \\ \\ x00 \ x00等等...... ,其中有一些逗号和其他符号。 (17758之前的e 上面有一个小帽子)

所以单位数是一个ASCII字符串。首先,我建议用十六进制打印消息: print''''。join(["%02.2x"%ord} (b)对于b中的消息]) 这应该可以更容易地计算出哪些字节索引 包含您正在寻找的信息。

如果我把它打印成文本文件,我会得到这个... STXNULNULNULea17758NULLNULL等..

我很困惑,但是上面显示的字符串是如何被打印的那样。 就是这样。

\ x00"是包含 空字节的单字节字符串的Python repr()(即十进制值为零的字节)。

现在17758非常重要,因为它是我们想要监控的机器的实际单元数 。我只是不知道如何从这条消息中提取 的实际价值。

什么是真实值?

任何人都知道从哪里开始?我已经尝试了 struct,但对它不了解。有没有人知道关于学习字节码等的好教程。

什么是字节代码?

蟒蛇网站上的文档很好地解释了模块,但是我还是不知道如何处理它。

您必须弄清楚您关心的对象的 消息中的格式和位置。一旦你知道了,你就用使用struct来取出适当的字节并将它们转换成Python对象。 如果你知道(或怀疑)消息中有IEEE 754 32位浮动点值,然后开始将所有可能的4个字节块转换为Python浮点数(使用两个endian 约定),直到看到你识别的数字。 64位浮点数和各种大小的整数值相同。 - 格兰特爱德华兹格兰特哇!人类REPLICAS 加入VATS visi NUTRITIONAL YEAST ...

hello there, all. i have a difficult app that connects to a server to get information for our database here. this server is our access point to some equipment in the field that we monitor. the messages come in over a socket connection. And according to their (very limited) documentation, are set up in a particular order. like this STX [length indicator] [message type] [message body] ENX length indicator = length of the message body in 4 bytes message type = the code for what type of message is being sent for example 200 = login message body = the actual command to send to the server STX and ENX are the values assigned to start and stop a message. they are literally ''STX'' and ''ENX'' when i capture a message i can print it to the screen and the ''STX'' at the beginning and the ''ENX'' at the end are discernable, but the rest of the message looks like this.. \x00\x00\x00,\x00\x00\x00\e17758\x00\x00 and so on and so forth... with some commas and other symbols in there. (the e before the 17758 has a little hat on it) If i print it out to a text file, i get this... STXNULNULNULea17758NULLNULL etc.. now the 17758 is significant because it is the actual unit number of the machine we want to monitor. I just dont know how to extract the real values out of this message. anyone have an idea where to start? i have experimented with struct, but do not know enough about it. Does anyone know a good tutorial about learning byte codes and such. The docs on pythons website explain the module well, but i still do not know what to do with it. Or how to generate a message or pull apart these values to get a message out of what the server sends us. thanks sk

解决方案

ne*****@xit wrote:

hello there, all. i have a difficult app that connects to a server to get information for our database here. this server is our access point to some equipment in the field that we monitor. the messages come in over a socket connection. And according to their (very limited) documentation, are set up in a particular order. like this STX [length indicator] [message type] [message body] ENX length indicator = length of the message body in 4 bytes message type = the code for what type of message is being sent for example 200 = login message body = the actual command to send to the server STX and ENX are the values assigned to start and stop a message. they are literally ''STX'' and ''ENX''

I believe you, but this is clearly a perversion of the single-character "start of transmission" and "end of transmission" that are part of the ASCII alphabet. So the protocol designer may have been inexperienced, and the documentation may be confused ...

> when i capture a message i can print it to the screen and the ''STX'' at the beginning and the ''ENX'' at the end are discernable, but the rest of the message looks like this.. \x00\x00\x00,\x00\x00\x00\e17758\x00\x00 and so on and so forth... with some commas and other symbols in there. (the e before the 17758 has a little hat on it) If i print it out to a text file, i get this... STXNULNULNULea17758NULLNULL etc..

The "\x00" is the Python repr() of a single-byte string containing a null byte (i.e. a byte whose decimal value is zero).

now the 17758 is significant because it is the actual unit number of the machine we want to monitor. I just dont know how to extract the real values out of this message. anyone have an idea where to start? i have experimented with struct, but do not know enough about it. Does anyone know a good tutorial about learning byte codes and such. The docs on pythons website explain the module well, but i still do not know what to do with it. Or how to generate a message or pull apart these values to get a message out of what the server sends us.

Well if the string you are seeing (when you print it from Python) looks like "STX\x00\x00\x00,\x00\x00\x00\e17758\x00\x00 ... ETX" then it looks like the bytes you want can be obtained, supposing the string is stored in variable s, as s[12:17].

>>s = "STX\x00\x00\x00,\x00\x00\x00\e17758\x00\x00 ... ETX"s[12:17]

''17758''

>>>

You may need to juggle about with the indexes a little, but one of the joys of Python is that the interactive interpreter is so cooperative! Good luck. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd www.holdenweb Skype: holdenweb holdenweb.blogspot Recent Ramblings del.icio.us/steve.holden

On 2006-07-24, Steve Holden <st***@holdenwebwrote:

ne*****@xit wrote:

>hello there, all.i have a difficult app that connects to a server to get information forour database here.this server is our access point to some equipment in the field that wemonitor.the messages come in over a socket connection. And according to their(very limited) documentation, are set up in a particular order. likethisSTX [length indicator] [message type] [message body] ENXlength indicator = length of the message body in 4 bytesmessage type = the code for what type of message is being sent for example 200 = loginmessage body = the actual command to send to the serverSTX and ENX are the values assigned to start and stop a message.they are literally ''STX'' and ''ENX''

I believe you, but this is clearly a perversion of the single-character "start of transmission" and "end of transmission" that are part of the ASCII alphabet. So the protocol designer may have been inexperienced, and the documentation may be confused ...

I had the same reaction: surely he means the frame is delmited at the beginning by the ASCII STX character (0x02) and the end by the ETX character (0x03). If somebody is indeed sending the three character string "STX" to mark the beginning of a frame and "ENX" to mark the end, then they''re seriously confused (and can''t spell).

>when i capture a message i can print it to the screen and the ''STX'' atthe beginning and the ''ENX'' at the end are discernable, but the rest ofthe message looks like this..\x00\x00\x00,\x00\x00\x00\e17758\x00\x00 and so on and so forth...with some commas and other symbols in there. (the e before the 17758has a little hat on it)

So the unit number is an ASCII string. Firstly, I''d recommend printing the message in hex: print '' ''.join(["%02.2x" % ord(b) for b in message]) That should make it easier to figure how which byte indexes contain the info you''re looking for.

>If i print it out to a text file, i get this...STXNULNULNULea17758NULLNULL etc..

I''m a but baffled how the string shown above would get printed like that.

The "\x00" is the Python repr() of a single-byte string containing a null byte (i.e. a byte whose decimal value is zero).

>now the 17758 is significant because it is the actual unit number ofthe machine we want to monitor. I just dont know how to extract thereal values out of this message.

What is meant by "real values"?

>anyone have an idea where to start? i have experimented withstruct, but do not know enough about it. Does anyone know agood tutorial about learning byte codes and such.

What are "byte codes"?

>The docs on pythons website explain the module well, but istill do not know what to do with it.

You''ve got to figure out the format and location within the message of the objects you care about. Once you know that, you use struct to pull out the appropriate bytes and convert them into Python objects. If you know (or suspect) there are IEEE 754 32-bit floating point values in the message, then start converting all of the possible 4-byte chunks into Python floats (using both endian conventions) until you see numbers you recognize. Same for 64-bit floats and interger values of various sizes. -- Grant Edwards grante Yow! HUMAN REPLICAS are at inserted into VATS of visi NUTRITIONAL YEAST...

ok, i did this print '' ''.join(["%02.2x" % ord(b) for b in message]) and i got this in the text file 5354580000002c000000ea3137353834363638353500000000 000000000000000000000000000000000000d6090d54000000 00454e58 so, yes, more of the info seems discernable now. according to their docs, all of their variables are sent as 32bit long int (prefferably unsigned long int). the developers at the server we are trying to talk to have released an api for C (maybe C++) that comes in an osx module that one is supposed to import into visual basic. I am not developing in visual basic, or windows or C or C++. So my challenge is to get some of the same functionality out of python on debian linux. the osx module is what they give out to developers who have apps that need to talk with this server. the starting and ending deliminators are ASCII ''STX'' and ''ENX''. i wondered why they did it like that also. But they did. the message length is a 4 byte integer indicating how long the message body is. the message type is also 4 bytes. There is a table in the docs that describe what each message type is. for example 200 = login, etc...etc... the big deal in the docs goes on about how the clients need the byte order to match that of the arch that the server runs on ''Sun UltraSPARC'' , i think they run Solaris. if i sound like i do not know what i am talking about... there is a reason... i am very new to this type of communication with the server. I have about 6 months with python ( my first language ). thanks for your help, gents . -sk Grant Edwards wrote:

On 2006-07-24, Steve Holden <st***@holdenwebwrote:

ne*****@xit wrote:

hello there, all. i have a difficult app that connects to a server to get information for our database here. this server is our access point to some equipment in the field that we monitor. the messages come in over a socket connection. And according to their (very limited) documentation, are set up in a particular order. like this STX [length indicator] [message type] [message body] ENX length indicator = length of the message body in 4 bytes message type = the code for what type of message is being sent for example 200 = login message body = the actual command to send to the server STX and ENX are the values assigned to start and stop a message. they are literally ''STX'' and ''ENX''

I believe you, but this is clearly a perversion of the single-character "start of transmission" and "end of transmission" that are part of the ASCII alphabet. So the protocol designer may have been inexperienced, and the documentation may be confused ...

I had the same reaction: surely he means the frame is delmited at the beginning by the ASCII STX character (0x02) and the end by the ETX character (0x03). If somebody is indeed sending the three character string "STX" to mark the beginning of a frame and "ENX" to mark the end, then they''re seriously confused (and can''t spell).

when i capture a message i can print it to the screen and the ''STX'' at the beginning and the ''ENX'' at the end are discernable, but the rest of the message looks like this.. \x00\x00\x00,\x00\x00\x00\e17758\x00\x00 and so on and so forth... with some commas and other symbols in there. (the e before the 17758 has a little hat on it)

So the unit number is an ASCII string. Firstly, I''d recommend printing the message in hex: print '' ''.join(["%02.2x" % ord(b) for b in message]) That should make it easier to figure how which byte indexes contain the info you''re looking for.

If i print it out to a text file, i get this... STXNULNULNULea17758NULLNULL etc..

I''m a but baffled how the string shown above would get printed like that.

The "\x00" is the Python repr() of a single-byte string containing a null byte (i.e. a byte whose decimal value is zero).

now the 17758 is significant because it is the actual unit number of the machine we want to monitor. I just dont know how to extract the real values out of this message.

What is meant by "real values"?

anyone have an idea where to start? i have experimented with struct, but do not know enough about it. Does anyone know a good tutorial about learning byte codes and such.

What are "byte codes"?

The docs on pythons website explain the module well, but i still do not know what to do with it.

You''ve got to figure out the format and location within the message of the objects you care about. Once you know that, you use struct to pull out the appropriate bytes and convert them into Python objects. If you know (or suspect) there are IEEE 754 32-bit floating point values in the message, then start converting all of the possible 4-byte chunks into Python floats (using both endian conventions) until you see numbers you recognize. Same for 64-bit floats and interger values of various sizes. -- Grant Edwards grante Yow! HUMAN REPLICAS are at inserted into VATS of visi NUTRITIONAL YEAST...

更多推荐

具有struct和byte顺序的prob

本文发布于:2023-11-25 21:01:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1631331.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:顺序   struct   byte   prob

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!