06-04-2019 12:50 PM
Hello. I need to use a protocol buffer for communications.
I am trying to use Python tools to serialize message. The function works just fine in Python environment.
I am trying to use Labview to call Python function get the message and put it on UDP port.
The Python node function requires input for the return data type. Protobuf uses SerializeToString function to generate a string, which is a binary format.
SerializeToString(self) |
source code |
Serializes the protocol message to a binary string. Returns: A binary string representation of the message if all of the required fields in the message are set (i.e. the message is initialized).
I am getting errors class 'TypeError" error and no return value. How would I format input for the node function to fix an error.
06-04-2019 04:19 PM
I'd just do the message in LabVIEW. It's pretty straightforward to do.
06-04-2019 04:47 PM
I wish I could. The Labview PC will be communicating with the Linux system. Linux system will send multiple messages that serialized using proto buffer serializer all based in Python.
We were planning to use the same proto files, that way I do not have decode messages.
06-04-2019 10:25 PM - edited 06-04-2019 10:26 PM
@Rus_K wrote:
I wish I could. The Labview PC will be communicating with the Linux system. Linux system will send multiple messages that serialized using proto buffer serializer all based in Python.
We were planning to use the same proto files, that way I do not have decode messages.
I understand, though sometimes implementing the "easy" solution turns out to be harder than the "hard" solution.
06-09-2019 04:26 PM
I'm just looking into the possibility of using the ProtoBuf functionality for exactly this use case LabVIEW <> Linux, so it should be interesting to see how this works out for you.
If you are using the python libraries but can't get the datatype heading in as the right type, you should be able to pass the data as JSON.
308 -def Parse(text, message, ignore_unknown_fields=False): 309 """Parses a JSON representation of a protocol message into a message. 310 311 Args: 312 text: Message JSON representation. 313 message: A protocol beffer message to merge into. 314 ignore_unknown_fields: If True, do not raise errors for unknown fields. 315 316 Returns: 317 The same message passed as argument.
Thereby using the python interpreter to go from JSON string (LabVIEW readable, depending on format) to binary string (LabVIEW reable) and then you can handle the actual UDP messaging etc inside of the LabVIEW.
I can't attest to how fast this process will be but if at this stage the only requirement is to get the data moving this might be a good starting point.