lundi 4 octobre 2021

Design Pattern for connecting to Hardware

I have a C# software application that collects data from various hardware and performs live data analysis on it before uploading to a database.

I have created an abstract Device class with a concrete implementation of the device e.g. TemperatureSensor. These devices are created through a Factory Pattern. The hardware devices have their own internal clock and send data to my C# application through events managed through their API. The devices generally send data in a string format that needs to be parsed and then stored in an appropriate measurement class.

I am trying to separate the device setup/connection from the device data to ensure that any changes/upgrades to the hardware do not affect the analysis layer.

1.) Is there are Design Pattern that would suit this scenario? My current design is shown in this image Design. For each Device the factory creates I am proposing creating a separate DeviceData class to store the data in and sending the data for each measurement through an event.

2.) Should I parse the data in the concrete Device or should I parse it in the DeviceData?

3.) Is decoupling the device (TemperatureSensor) from the data (TemperatureData) using events and the observer pattern the best solution? We potentially will connect to many devices in the future and I need to ensure that it is scalable so all suggestions are welcome.

Aucun commentaire:

Enregistrer un commentaire