Actor Framework Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Parsing ASCII messages efficiently with AF

Hi all,

My program is built of a number of actors. I want to implement an API to control my program from an external source using text(ASCII) messages. I need an algorithm to map a given command and its parameters to a specific send msg VI. Other than the obvious huge case loop that checks command name, parses the parmaeters, and calls the correct function, does anyone have any ideas? I would like something that is easy to maintain and change, as I am sure we will add/change a number of commands. At the moment we are looking at more than 50 commands.

The current ideas were:

1. Create a MyMsg class that all messages will inherit from, that has ToString and FromString functions and a stringCommand datatype; create a dictionary between comand names (StringCommand) and messages names; use FromString function to send the correct message.

2. Create Dictionary directly between command names and send msg VIs.

3. Create parser VI with a huge case loop.

Any ideas would be appreciated.

Thanks!

Danielle

"Wisdom comes from experience. Experience is often a result of lack of wisdom.”
― Terry Pratchett
0 Kudos
Message 1 of 2
(5,373 Views)

If your command names are unique and can be extracted from the incomming text message then store your specific message objects (using the parent MyMsg.class type) in your dictionary under the command name. An efficient way is to use the Variant Attributes for this.

So when you get an incomming string you

- exteract the command name

- read the message object belonging to this command name from your variant dictionary (get attribute)

- Call your FromString method to initialize the message object according to the incomming string.

- enque the initialized message object in the message queue of the destination actor.

I did this in a similar way to map SCPI command from a GPIB interface to messages for an actor and this works well.

Hope this helps,

Karsten

Message 2 of 2
(2,945 Views)