Trying to wrap my head around class structure for domain-specific language

Posted by svaha on Programmers See other posts from Programmers or by svaha
Published on 2012-04-06T16:26:21Z Indexed on 2012/04/06 17:41 UTC
Read the original article Hit count: 216

Filed under:
|
|

My work is mostly in embedded systems programming in C, and the proper class structure to pull this off eludes me. Currently we communicate via C# and Visual Basic with a large collection of servos, pumps, and sensors via a USB-to-CAN hid device.

Right now, it is quite cumbersome to communicate with the devices. To read the firmware version of controller number 1 you would use:

SendCan(Controller,1,ReadFirmwareVersion) or
SendCan(8,1,71)

This sends three bytes on the CAN bus: (8,1,71)

Connected to controllers are various sensors.

SendCan(Controller,1,PassThroughCommand,O2Sensor,2,ReadO2)

would tell Controller number 1 to pass a command to O2 Sensor number 2 to read O2 by sending the bytes 8,1,200,16,2,0

I would like to develop a domain-specific language for this setup. Instead of commands issued like they are currently, commands would be written like this:

Controller1.SendCommand.O2Sensor2.ReadO2

to send the bytes 8,1,200,16,0

What's the best way to do this? Some machines have 20 O2 Sensors, others have 5 controllers, so the numbers and types of controllers and sensors, pumps, etc. aren't static.

© Programmers or respective owner

Related posts about c#

Related posts about .NET