LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using python for protocol buffer

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.

0 Kudos
Message 1 of 5
(2,769 Views)

I'd just do the message in LabVIEW.  It's pretty straightforward to do.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 2 of 5
(2,737 Views)

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.

0 Kudos
Message 3 of 5
(2,732 Views)

@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.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 4 of 5
(2,722 Views)

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.

 

0 Kudos
Message 5 of 5
(2,693 Views)