derole
Help with writing a command queueing system for a serial device
Hi there, I'm currently writing a library for an old IO device which operates over an RS485 serial connection.
The way it accepts commands is it takes an array of request packets in binary:
Then the board will respond like this, also in binary:
Currently I have a concept in my head of how this would work, ideally I would like to be able to queue up a bunch of request classes (Which I will refer to herein as TRequest), then call a ProcessCommands function which sends these to the IO board, receives a response, and then I can de-queue response classes that are a match for the TRequests passed to the function with the response data.
My question is, how would I be best to go about this, I've currently tried something with generic types however am struggling to do what I want with it. Heres what I have currently:
Please see attached cs file, the code is too large to write into a discord message
CommandPayload is an abstract class containing a command code as well as an abstract Serialise() function which serialises from its own parameters, and Report is an abstract class containing a status code along with a Deserialise() function which deserialises to its own paramters
Am I going the right way about this? Please note the Enqueue line, where im really not sure how to get back to the Report superclass after the ChangeType (If I can even do a ChangeType like this?)
I'm really hoping this makes sense, anything that isnt clear/is awful please do ask. Any assistance would be greatly appreciated :)
135 replies
Xml generic type deserialisation based on attribute
Hi there,
I'm working on a server for a client app which sends requests in a fixed xml format, it has a root node with a method attribute and depending on the method there are different objects serialised into the root node.
My question is, I want something which can deserialise to the root node object and then be casted later down the line to an object with the proper generic type. Said generic type will contain the correct xml model for the given method attribute.
Is there a way to do this with C# xml serialisation by default. I don't need any specific code and am fine with just docs/a writeup to research into just want to know if what I am wanting to do if possible and if not, possibly an alternative way to achieve it.
I cannot change how the client works unfortunately.
Hope this all makes sense.
1 replies