Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat design pattern is best employed to control a sequence of steps?
    primarykey
    data
    text
    <p>I have a winform tool that interfaces with hardware using a serial port.</p> <p>The serial port is used to send commands to the the hardware, which will acknowledge the commands and sometimes return data.</p> <p>To accomplish a task, several commands need to be sent to the hardware in a defined order.</p> <p>I have successfully implemented the tool using a switch statement to control the sending of the commands. However, while this works, I can't help thinking that there is a better, more OO way of doing this - is there?</p> <p>Current implementation is below:</p> <p>Each case is a command that needs sending to the hardware. Send method is passed a method to invoke and the ID of next step - which will be returned if command sent successfully.</p> <ul> <li>Tool will send a start session command to the hardware. </li> <li>Hardware acknowledges command.</li> <li>Tool sends a set direction command to the hardware. </li> <li>Hardware will acknowledge command.</li> </ul> <p>etc.</p> <pre><code>MessageID nextStep = MessageID.IMS; while (nextStep != MessageID.Stop) { switch (nextStep) { case MessageID.ISS: nextStep = Send( new ISS_StartSession(), MessageID.IE386); RaiseProgressEvent(10); //percentage complete break; case MessageID.IE386: nextStep = Send( new IE386_SetDirection(Direction.BOTH), MessageID.IE378); RaiseProgressEvent(20); break; //etc case MessageID.Error: HandleError(); //abort task if necessary break; } } </code></pre> <p>Is there a better way to do this..?</p> <p>Is there a well known design pattern I should look at?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload