Beispiel #1
0
        /// <summary>
        /// Create a new LogDownloader
        /// </summary>
        /// <param name="isAsyncTransfer">Determines if this machine will be set up asyncronus transfers.</param>
        /// <param name="threadName">The name to report in closing operations for this binary socket.</param>
        /// <param name="closingWorker">The closing worker to add this binary socket too.</param>
        protected ThreadedTransferMachine(bool isAsyncTransfer, string threadName, ClosingWorker closingWorker) : base(threadName)
        {
            // add thread to the closing worker
            closingWorker?.AddThread(this);

            // initialize the StateMachine
            WorkerState = new StateDefinition();

            if (isAsyncTransfer)
            {
                MachineFunctions.InitializeStates(WorkerStateMachine = new StepDefinition(threadName, true, WorkerState)
                {
                    #region StateMachine
                    SubSteps = new List <StepDefinition>
                    {
                        new StepDefinition("Transfer Packet")
                        {
                            Delegate = StateMachine_TransferPacket, DelayTimeMs = 500
                        },
                        new StepDefinition("Packet Timeout")
                        {
                            Delegate = StateMachine_PacketTimeout, DelayTimeMs = 0
                        },
                        new StepDefinition("Complete")
                        {
                            Delegate = StateMachine_Complete, DelayTimeMs = 200
                        }
                    }
                    #endregion // StateMachine
                });
            }
            else
            {
                MachineFunctions.InitializeStates(WorkerStateMachine = new StepDefinition(threadName, true, WorkerState)
                {
                    #region StateMachine
                    SubSteps = new List <StepDefinition>
                    {
                        new StepDefinition("Transfer Packet")
                        {
                            Delegate = StateMachine_TransferPacket, DelayTimeMs = 0
                        },
                        new StepDefinition("Complete")
                        {
                            Delegate = StateMachine_Complete, DelayTimeMs = 200
                        }
                    }
                    #endregion // StateMachine
                });
            }

            // start the StateMachine in the Complete state
            MachineFunctions.JumpToLast(WorkerStateMachine);

            // initialize ThreadingBase
            WorkerThreads = new List <ThreadInfo>
            {
                new ThreadInfo(new Thread(Worker), "State Machine", threadName, WorkerStateMachine)
            };
        }
Beispiel #2
0
        /// <summary>
        /// A function that blocks until all threads in the supplied closing worker are complete and closed.
        /// This function will display status in a persistent dialog.
        /// </summary>
        /// <param name="closingWorker">The ClosingWorker to perform the actions on.</param>
        public static void WaitForThreadsToCloseDialogOutput(this ClosingWorker closingWorker)
        {
            // run the closing worker until all child threads are closed
            ClosingInfo status;
            var         cycles = 0;

            while ((status = closingWorker.ShutdownThreads()).ShutdownReady == false)
            {
                if (++cycles % 6 == 0)
                {
                    if (!CrossThreadDialogs.MessageBoxPersistentExists())
                    {
                        CrossThreadDialogs.MessageBoxPersistentCreate(new DialogConfiguration
                        {
                            Message          = status.Message,
                            Title            = "CV-LS Dashboard Closing Status",
                            ButtonIsVisible  = false,
                            DialogWidth      = 600,
                            MessageAlignment = ContentAlignment.MiddleLeft
                        });
                    }
                    else
                    {
                        CrossThreadDialogs.MessageBoxPersistentUpdateMessage(status.Message);
                    }
                }
                TimeFunctions.Wait(50);
            }

            CrossThreadDialogs.MessageBoxPersistentClose();
        }
 /// <summary>
 /// A function that blocks until all threads in the supplied closing worker are complete and closed.
 /// This function will display status in the console.
 /// </summary>
 /// <param name="closingWorker">The ClosingWorker to perform the actions on.</param>
 public static void WaitForThreadsToCloseNoOutput(this ClosingWorker closingWorker)
 {
     // run the closing worker until all child threads are closed
     while (closingWorker.ShutdownThreads().ShutdownReady == false)
     {
         TimeFunctions.Wait(50);
     }
 }
        /// <summary>
        /// A function that blocks until all threads in the supplied closing worker are complete and closed.
        /// This function will display status in the console.
        /// </summary>
        /// <param name="closingWorker">The ClosingWorker to perform the actions on.</param>
        public static void WaitForThreadsToCloseConsoleOutput(this ClosingWorker closingWorker)
        {
            // run the closing worker until all child threads are closed
            ClosingInfo status;
            var         cycles        = 0;
            var         previousLines = 0;

            while ((status = closingWorker.ShutdownThreads()).ShutdownReady == false)
            {
                if (cycles++ % 6 == 0)
                {
                    ConsoleFunctions.ClearLine(previousLines);
                    Console.WriteLine(status.Message);
                    previousLines = status.Message.Split('\r').Length;
                }
                TimeFunctions.Wait(50);
            }

            // clean up console
            ConsoleFunctions.ClearLine(previousLines);
            Console.WriteLine("Shutdown Threads Complete!");
        }
Beispiel #5
0
        public MainForm()
        {
            InitializeComponent();
            AppendVersionToFormTitle();
            _applicationSettings.ReadSettings();

            // this allows dialogs to be called from the DLLs
            CrossThreadDialogs.InitializeDialogs(this);

            // establish the closing worker
            _closingWorker = new ClosingWorker();

            // start child threads
            _cvlsThreadedComPort = new CVLSThreadedComPort("Com Port", _closingWorker, CVLSPortType.Usb);
            _cvlsThreadedComPort.RegisterConnectionUpdate(MessageBroker.MessageContext.NewThreadToGui, ComPortConnectionUpdate);

            // initialize form state
            InitializeFormState();

            // subscribe to form closing
            FormClosing += MainForm_FormClosing;
        }
        /// <summary>
        /// Creates a new ThreadedComPortBase object.
        /// </summary>
        /// <param name="threadName">The threadname to report during closing and error events.</param>
        /// <param name="closingWorker">The closing worker this thread should subscribe too.</param>
        /// <param name="connectionParameters">The ComParameters to use when testing connections</param>
        /// <param name="mode">Which connection mode to use when selecting ComPorts to test.</param>
        /// <param name="selectionRule">The selectionRule to use when mode = SelectionRule.</param>
        public ThreadedComPortBase(string threadName, ClosingWorker closingWorker, ComParameters connectionParameters,
                                   ConnectionMode mode, Func <ComPortInfo, bool> selectionRule = null) : base(threadName)
        {
            _threadName = threadName;
            closingWorker?.AddThread(this);
            ConnectionParameters.CopyFrom(connectionParameters);

            // initialize the StateMachine
            WorkerState = new StateDefinition();
            MachineFunctions.InitializeStates(WorkerStateMachine = new StepDefinition(threadName, true, WorkerState)
            {
                #region StateMachine
                SubSteps = new List <StepDefinition>
                {
                    new StepDefinition("Searching")
                    {
                        Delegate = StateMachine_Searching, DelayTimeMs = 200
                    },
                    new StepDefinition("Connection Check")
                    {
                        Delegate = StateMachine_ConnectionCheck, DelayTimeMs = 200
                    },
                    new StepDefinition("Complete")
                    {
                        Delegate = StateMachine_Complete, DelayTimeMs = 200
                    }
                }
                #endregion // StateMachine
            });

            // set the mode for this com port
            ChangeMode(mode, selectionRule);

            // initialize ThreadingBase
            WorkerThreads = new List <ThreadInfo>
            {
                new ThreadInfo(new Thread(Worker), "State Machine", threadName, WorkerStateMachine)
            };
        }
Beispiel #7
0
 /// <summary>
 /// Create a CVLSThreadedComPort for a CVLS unit. This port type should be used when the unit connection
 /// state is unknown. Functions are provided to be notified of connections and status changes. When using
 /// a static configuration, consider using the CVLSComPort classes instead.
 /// </summary>
 /// <param name="threadName">Name of the thread.</param>
 /// <param name="closingWorker">The ClosingWorker to add this thread too</param>
 /// <param name="portName">The port to connect to in format 'COM#'</param>
 public CVLSThreadedComPort(string threadName, ClosingWorker closingWorker, string portName)
     : base(threadName, closingWorker, CVLSComPort.ComParameters(), ConnectionMode.SelectionRule, port => port.Port == portName)
 {
     InitializeFirmwareUploader();
 }
Beispiel #8
0
 /// <summary>
 /// Create a CVLSThreadedComPort for a CVLS unit. This port type should be used when the unit connection
 /// state is unknown. Functions are provided to be notified of connections and status changes. When using
 /// a static configuration, consider using the CVLSComPort classes instead.
 /// </summary>
 /// <param name="threadName">Name of the thread.</param>
 /// <param name="closingWorker">The ClosingWorker to add this thread too</param>
 /// <param name="cvlsPortType">Select the CVLSPortType, can use multiple flags</param>
 /// <param name="serialNumber">The serial number to connect too</param>
 public CVLSThreadedComPort(string threadName, ClosingWorker closingWorker, CVLSPortType cvlsPortType, int serialNumber)
     : base(threadName, closingWorker, CVLSComPort.ComParameters(serialNumber), CVLSComPort.ComMode(cvlsPortType), CVLSComPort.SelectionRule(cvlsPortType))
 {
     InitializeFirmwareUploader();
 }
Beispiel #9
0
 /// <summary>
 /// Create a new LogDownloader
 /// </summary>
 /// <param name="comPort">The ThreadedComPort to attach this LogDownloaderSerial too</param>
 /// <param name="threadName">The name to report in closing operations for this binary socket.</param>
 /// <param name="closingWorker">The closing worker to add this binary socket too.</param>
 public LogDownloaderSerial(CVLSThreadedComPort comPort, string threadName, ClosingWorker closingWorker) : base(false, threadName, closingWorker)
 {
     // hook up to the comPort
     _comPortRef = comPort;
 }
 /// <summary>
 /// Create a VisiLEDThreadedComPort for a VisiLED unit. This port type should be used when the unit connection
 /// state is unknown. Functions are provided to be notified of connections and status changes. When using
 /// a static configuration, consider using the VisiLEDComPort classes instead.
 /// </summary>
 /// <param name="threadName">Name of the thread.</param>
 /// <param name="closingWorker">The ClosingWorker to add this thread too</param>
 /// <param name="portName">The port to connect to in format 'COM#'</param>
 public VisiLEDThreadedComPort(string threadName, ClosingWorker closingWorker, string portName)
     : base(threadName, closingWorker, VisiLEDComPort.ComParameters(), ConnectionMode.SelectionRule, port => port.Port == portName)
 {
 }
 /// <summary>
 /// Create a VisiLEDThreadedComPort for a VisiLED unit. This port type should be used when the unit connection
 /// state is unknown. Functions are provided to be notified of connections and status changes. When using
 /// a static configuration, consider using the VisiLEDComPort classes instead.
 /// </summary>
 /// <param name="threadName">Name of the thread.</param>
 /// <param name="closingWorker">The ClosingWorker to add this thread too</param>
 public VisiLEDThreadedComPort(string threadName, ClosingWorker closingWorker)
     : base(threadName, closingWorker, VisiLEDComPort.ComParameters(), ConnectionMode.AnyCom)
 {
 }
 /// <summary>
 /// Create a new FirmwareUploader
 /// </summary>
 /// <param name="binarySocket">The BinarySocket to attach this FirmwareUploader too</param>
 /// <param name="threadName">The name to report in closing operations for this binary socket.</param>
 /// <param name="closingWorker">The closing worker to add this binary socket too.</param>
 public FirmwareUploader(BinarySocket binarySocket, string threadName, ClosingWorker closingWorker) : base(true, threadName, closingWorker)
 {
     // hook up to the BinarySocket
     _binarySocketRef = binarySocket;
 }