用Python读取LabVIEW TCP数据(扁平字符串/数据簇) [英] Reading LabVIEW TCP data (Flattened String / Data Cluster) in Python

查看:456
本文介绍了用Python读取LabVIEW TCP数据(扁平字符串/数据簇)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个LabVIEW应用程序,该应用程序在将TCP/IP传输到我的python应用程序之前,将Doubles的簇(数组)展平为一个字符串.这样做是因为TCP/IP仅会传输字符串.

I have a LabVIEW application that is flattening a cluster (array) of Doubles to a string, before transmitting over TCP/IP to my python application. It does this because TCP/IP will only transmit strings.

问题是python将字符串作为无意义的ASCII字符读取,并且我似乎无法将它们解译回原始的双精度数组.

The problem is that python reads the string as a load of nonsense ASCII characters, and I can't seem to unscramble them back to the original array of doubles.

在扁平化数据字符串后,如何解释LabVIEW发送的字符串数据.在Google工作了几个小时后,我唯一有用的提示是一个名为pyLFDS的PyPI条目,但是此后就被删除了.

How do I interpret the string data that LabVIEW sends after flattening a data strings. My only hint of useful information after hours of google was a PyPI entry called pyLFDS, however it has since been taken down.

推荐答案

IEEE 754格式存储.

The LabVIEW flattened data format is described in some detail here. That document doesn't explicitly describe how double-precision floats (DBL type) are represented, but a little more searching found this which clarifies that they are stored in IEEE 754 format.

但是,以标准文本格式(例如XML或JSON)发送数据可能会更简单,更可靠,因为LabVIEW中的内置函数和Python中的标准库模块都支持这两种格式.

However it would probably be simpler and more future proof to send your data in a standard text format such as XML or JSON, both of which are supported by built-in functions in LabVIEW and standard library modules in Python.

如果可以选择,不使用LabVIEW展平数据与其他程序交换的另一个原因是,展平字符串不包含类型描述符,您需要将其转换回原始数据类型-您需要知道数据是什么类型以便对其进行解码.

A further reason not to use LabVIEW flattened data for exchange with other programs, if you have the choice, is that the flattened string doesn't include the type descriptor you need to convert it back into the original data type - you need to know what type the data was in order to decode it.

这篇关于用Python读取LabVIEW TCP数据(扁平字符串/数据簇)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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