Navigation: Processing Concepts >

Parsing Message Strings for Plotting

 

 

 

 

Many times you may be working with a device that sends ASCII messages that are in a format incompatible with MPJ's analog data format of value,value,value... The ADC-10-F130C is one such device as well as other devices.

 

As long at the string end with a carriage return or line feed (which is most all), AND the values are a constant length, the string can be treated as a message and manually parsed to pull out the data for plotting and other uses.

 

Take for example a device which send the string of:
volts=4.502

 

When sent to MPJ the above will be treated as a Message String, stored in [messageString] and processed with <message> event triggers of various controls.

 

Using a prefix-math operation, subString, the string can be parsed to take get the value from the message:

!makeVar varValue={:: [messageString]::6::5::subString }

 

(note using :: between parameters with a string that may contain spaces is required).

 

In the subString the characters from position 6 (first character is at 0), for 5 character's worth, is extracted and stored in varValue.

 

The value of varValue can be accessed with [varValue].

 

To plot this, code is placed where message data is processed, such as the Main Interface's Event Code being triggered off the reception of a message. Then, the value is used to plot manually using the plotChan instruction:
!plot.plotChan channel, value

 

So, mousing over the back ground and hitting F3 will open the Main's properties Window where the event code may be entered:

 

<message>!makeVar varValue={:: [messageString]::6::5::subString }

<message>!plot.plotChan 1,[varValue]  // Use plot's channel 1 for value

 

These operations may be combined for the following:
<message>!plot.plotChan 1,{:: [messageString]::6::5::subString }

 

 

Once plotted, the value may be accessed by other controls as: [plot.ch1].

 


 

 

 

 

 

 

 

 

 

 

Copyright © 2024 SelmaWare Solutions, LLC