private bool StateMachine_Complete(StepDefinition currentStep)
        {
            // clear out any old connections
            if (IsOpen)
            {
                IsConnected = false;
                CurrentConnection?.Disconnect();
                RunConnectionUpdate();
            }

            if (WorkerState.ThreadClosing)
            {
                WorkerState.StateMachineComplete = true;
            }
            return(StepReturn.RepeatStep);
        }
Example #2
0
 public void Disconnect()
 {
     CurrentConnection?.Disconnect();
 }
        private bool StateMachine_Searching(StepDefinition currentStep)
        {
            // get list of current system com ports
            var descriptions = ComPortInfo.GetDescriptions();

            // clear out any old connections
            if (IsOpen)
            {
                IsConnected = false;
                CurrentConnection?.Disconnect();
            }

            RunConnectionUpdate();

            switch (TargetMode)
            {
            case ConnectionMode.AnyCom:
                CurrentConnection = AutoConnectComPort(
                    descriptions.Select(s => s.Port).ToList(),
                    ConnectionParameters);
                break;

            case ConnectionMode.SelectionRule:
                CurrentConnection = AutoConnectComPort(
                    descriptions.Where(TargetSelectionRule).Select(s => s.Port).ToList(),
                    ConnectionParameters);
                break;

            case ConnectionMode.PersistentPort:
                descriptions = descriptions.Where(TargetSelectionRule).ToList();
                if (descriptions.Count == 1)
                {
                    CurrentConnection = ConnectComPort(
                        descriptions.Select(s => s.Port).First(),
                        ConnectionParameters);

                    CurrentConnection?.Connect();
                    if (CurrentConnection?.IsConnected != true)
                    {
                        CurrentConnection?.Disconnect();
                        CurrentConnection = null;
                    }
                }
                else if (descriptions.Count > 1)
                {
                    MachineFunctions.JumpToLast(currentStep);
                    return(StepReturn.JumpCommandUsed);
                }
                break;

            default:
                break;
            }

            // if we didn't open a port, try again
            if (!IsOpen)
            {
                return(StepReturn.RepeatStep);
            }

            // we opened a port, so update the listeners
            ConnectionEventRegister();
            RunConnectionUpdate();

            // move to the next step
            return(StepReturn.ContinueToNext);
        }