private string AlterarEstadoDaPorta(string portName, PortStates targetPortState, IDevicePortState portState)
        {
            string result;
            var    changePortStateContex = new ChangePortStateContext()
            {
                RequestId      = "",
                SetState       = targetPortState,
                TargetPortName = portName
            };

            _thinkerThingsSignalRHubContext.Clients.Client(portState.ConnectionId).ChangePortState(changePortStateContex);
            switch (targetPortState)
            {
            case PortStates.Actived:
                result = $"{portName} será ligado";
                break;

            case PortStates.Deactived:
                result = $"{portName} será desligado";
                break;

            default:
                result = $"Não estou certo do que acontecerá com {portName}";
                break;
            }

            return(result);
        }
Ejemplo n.º 2
0
 private void btnStop_Click(object sender, EventArgs e)
 {
     if (currentPortState == PortStates.PORT_RUNNING_TRANSMIT)
     {
         currentPortState = PortStates.PORT_RUNNING_IDLE;
     }
 }
Ejemplo n.º 3
0
        protected virtual void OnPortStateChanged(object sender, PortStates state)
        {
            Console.WriteLine("Port[{0}]: changing state to '{1}', terminal {2} now {3}.\n",
                              this.PortId, state, _terminal.Number, _terminal.State);

            PortStateChanging?.Invoke(sender, state);
        }
Ejemplo n.º 4
0
        private void ChangePortState(OutputPin outputPin, PortStates portState)
        {
            var gpioPinValue = PortStateToGpioPinValue(portState);

            if (gpioPinValue.HasValue)
            {
                outputPin.GpioPinValue = gpioPinValue.Value;
            }
        }
Ejemplo n.º 5
0
 private void ChangePortState(PinConfiguration pinConfiguration, PortStates portState)
 {
     switch (pinConfiguration.PortType)
     {
     case PortTypes.Switch:
     case PortTypes.Pulse:
         var outputPin = _outputPins.First(p => p.PinId == pinConfiguration.PinId);
         ChangePortState(outputPin, portState);
         break;
     }
 }
Ejemplo n.º 6
0
        // Подписки на события от АТС
        protected void IncommingCallReceived(object sender, CallEventArgs e)
        {
            PortState = PortStates.Busy;

            //Debug.WriteLine("[Port.IncommingCallReceived] PortId: {0}", PortId);
            //Debug.WriteLine(e);

            OnPortStateChanged(new PortEventArgs()
            {
                Port = this
            });
            OnCallReceived(e);
        }
Ejemplo n.º 7
0
 private void btnConnect_Click(object sender, EventArgs e)
 {
     // state    -   PORT_CLOSED
     // type     -   permanent state
     // performs -   CLOSED -> OPENING transition
     if (currentPortState == PortStates.PORT_CLOSED)
     {
         currentPortState = PortStates.PORT_OPENING;
     }
     else if ((currentPortState == PortStates.PORT_RUNNING_IDLE) || (currentPortState == PortStates.PORT_RUNNING_TRANSMIT))
     {
         currentPortState = PortStates.PORT_CLOSING;
     }
 }
Ejemplo n.º 8
0
        // Как входящий, так и исходящий
        protected void TerminalCallEnded(object sender, CallEventArgs e)
        {
            //Debug.WriteLine("[Port.TerminalCallEnded] PortId: {0}", PortId);
            //Debug.WriteLine(e);

            if (PortState != PortStates.NotConnected)
            {
                PortState = PortStates.Connected;
            }
            OnPortStateChanged(new PortEventArgs()
            {
                Port = this
            });
            OnApeCallEnded(e);
        }
Ejemplo n.º 9
0
        // Подписки на события от подключенного терминала
        protected void TerminalCallStarted(object sender, CallEventArgs e)
        {
            //Debug.WriteLine("[Port.TerminalCallStarted] PortId: {0}", PortId);
            //Debug.WriteLine(e);

            PortState = PortStates.Busy;
            if (e != null && e.SourcePortId == null)
            {
                e.SourcePortId = PortId;
            }
            OnPortStateChanged(new PortEventArgs()
            {
                Port = this
            });
            OnApeCallStarted(e);
        }
Ejemplo n.º 10
0
        public Port(IPhoneExchange phoneExchange, IPortId portId)
        {
            if (phoneExchange == null)
            {
                throw new ArgumentNullException("phoneExchange", "phoneExchange cannot be null.");
            }
            if (portId == null)
            {
                throw new ArgumentNullException("portId", "portId cannot be null.");
            }

            PortId    = portId;
            PortState = PortStates.NotConnected;

            phoneExchange.PortAdded += PortAddedToApe;
        }
Ejemplo n.º 11
0
 public virtual void Disconnect()
 {
     if (_terminal != null)
     {
         PortState = PortStates.NotConnected;
         OnPortStateChanged(new PortEventArgs()
         {
             Port = this
         });
         PortStateChanged       -= _terminal.PortStateChanged;
         _terminal.CallStarted  -= TerminalCallStarted;
         _terminal.CallEnded    -= TerminalCallEnded;
         _terminal.CallAccepted -= TerminalCallAccepted;
         _terminal = null;
     }
 }
Ejemplo n.º 12
0
        protected void IncommingCallEnded(object sender, CallEventArgs e)
        {
            if (PortState != PortStates.NotConnected)
            {
                PortState = PortStates.Connected;
            }

            //Debug.WriteLine("[Port.IncommingCallEnded] PortId: {0}", PortId);
            //Debug.WriteLine(e);

            OnPortStateChanged(new PortEventArgs()
            {
                Port = this
            });
            OnCallEnded(e);
        }
Ejemplo n.º 13
0
        public virtual bool Connect(ITerminal terminal)
        {
            if (terminal == null || _terminal != null)
            {
                return(false);
            }

            _terminal               = terminal;
            _terminal.CallStarted  += TerminalCallStarted;
            _terminal.CallEnded    += TerminalCallEnded;
            _terminal.CallAccepted += TerminalCallAccepted;
            PortStateChanged       += _terminal.PortStateChanged;

            PortState = PortStates.Connected;
            OnPortStateChanged(new PortEventArgs()
            {
                Port = this
            });
            return(true);
        }
Ejemplo n.º 14
0
        private GpioPinValue?PortStateToGpioPinValue(PortStates portState)
        {
            GpioPinValue?result;

            switch (portState)
            {
            case PortStates.Actived:
                result = GpioPinValue.Low;
                break;

            case PortStates.Deactived:
                result = GpioPinValue.High;
                break;

            default:
                result = null;
                break;
            }

            return(result);
        }
Ejemplo n.º 15
0
        private void timerComHandler_Tick(object sender, EventArgs e)
        {
            // keep track of incoming bytes
            int result     = 0;
            int totalBytes = 0;

            string response;
            int    confirmationsReceived = 1;

            // string to be sent via Serial
            string textOut = "";

            // state    -   PORT_RUNNING
            // type     -   permanent state
            // performs -   continuosly read COM port data and request redrawing of newly incoming data
            if ((currentPortState == PortStates.PORT_WAITING_GRBL_HEADER) ||
                (currentPortState == PortStates.PORT_RUNNING_IDLE) ||
                (currentPortState == PortStates.PORT_RUNNING_TRANSMIT))
            {
                byte[] localData = new byte[1024];
                totalBytes = serialPort.BytesToRead;
                int readBytes = totalBytes;

                //if (serialPort.ReadBufferSize > 0)
                //{
                response = serialPort.ReadExisting();

                // filter out empty responses

                if (response != "")
                {
                    ComHandler.ConsoleWrite(response);
                }

                // if "Grbl" substring has arrived, then we definitely are connected to a GRBL machine
                if (response.Contains("Grbl"))
                {
                    currentPortState = PortStates.PORT_RUNNING_IDLE;
                }
                else
                {   // process normal incoming data
                    confirmationsReceived = ComHandler.ProcessIncomingData(response);
                }

                if (confirmationsReceived > 0)
                {
                    currentTxState = TransmitStates.TX_IDLE;
                }

                //Console.Write(confirmationsReceived);
                //glControl1.Invalidate();

                //}

                // hadle transmission of GCODE file
                if (currentPortState == PortStates.PORT_RUNNING_TRANSMIT)
                {
                    if ((!GcodeHandler.GcodeFileDataFinished) && (currentTxState == TransmitStates.TX_IDLE))
                    {
                        textOut = GcodeHandler.GetNextGcodeBlock();
                        ComHandler.ConsoleWrite(textOut + '\t');

                        serialPort.Write(textOut + "\r");
                        currentTxState = TransmitStates.TX_PENDING;
                        toolStripProgressBar1.Value = GcodeHandler.GcodeFilePercent;
                    }
                    else if (GcodeHandler.GcodeFileDataFinished)
                    {
                        currentPortState            = PortStates.PORT_RUNNING_IDLE;
                        toolStripProgressBar1.Value = 100;
                    }
                }
            }
        }
 public void DetectChanges(object sender, PortStates state)
 {
     Console.WriteLine("Station: port[{0}] change state to '{1}'.\n",
                       (sender as IPort).PortId, state);
 }
Ejemplo n.º 17
0
        private void timerBkgrTasks_Tick(object sender, EventArgs e)
        {
            // enumerate for new ports and update the list
            if (!SerialPort.GetPortNames().SequenceEqual(portNames))
            {
                portNames = SerialPort.GetPortNames();
                comboBox1.Items.Clear();
                comboBox1.Items.AddRange(portNames);

                if (comboBox1.Items.Count > 0)
                {
                    comboBox1.SelectedIndex = 0;
                }
            }


            // state    -   PORT_OPENING
            // type     -   transitory to PORT_WAITING_GRBL_HEADER
            // performs -   opening COM connection and start of acquisition timer
            // error    -   return to PORT_CLOSED state
            if (currentPortState == PortStates.PORT_OPENING)
            {
                try
                {
                    serialPort.PortName = comboBox1.Text;
                    serialPort.Open();
                    serialPort.DiscardInBuffer();
                    timerComHandler.Enabled = true;
                    currentPortState        = PortStates.PORT_WAITING_GRBL_HEADER;


                    btnConnect.Text   = "Disconnect";
                    comboBox1.Enabled = false;
                    textInput.Enabled = true;
                }
                catch
                {
                    currentPortState = PortStates.PORT_CLOSING;
                }
            }


            // state    -   PORT_WAITING_GRBL_HEADER
            // type     -   transitory to PORT_RUNNING
            // performs -   opening COM connection and start of acquisition timer
            // error    -   return to PORT_CLOSED state
            if (currentPortState == PortStates.PORT_WAITING_GRBL_HEADER)
            {
                //currentPortState = PortStates.PORT_RUNNING_IDLE;
            }



            // state    -   PORT_RUNNING_IDLE
            // type     -   permanent state
            // performs -   updates different states in the system
            // error    -   none
            if (currentPortState == PortStates.PORT_RUNNING_IDLE)
            {
                if (GcodeHandler.GcodeLoaded)
                {
                    btnStart.Enabled = true;
                    btnStop.Enabled  = true;
                }
            }

            // state    -   PORT_RUNNING_TRANSMIT
            // type     -   permanent state
            // performs -   updates different states in the system
            // error    -   none
            // hadled   -   handled in timerComHandler, not here


            // state    -   PORT_CLOSING
            // type     -   transitory state to PORT_CLOSED
            // performs -   closes the port and stops the acquisition timer
            if (currentPortState == PortStates.PORT_CLOSING)
            {
                serialPort.DiscardInBuffer();
                try
                {
                    serialPort.Close();
                }
                catch
                {
                    // do nothing, port goes into state PORT_CLOSED anyway
                    //Console.WriteLine("Error at closing port");
                }

                currentPortState = PortStates.PORT_CLOSED;
                btnConnect.Text  = "Connect";

                textInput.Enabled = false;
                comboBox1.Enabled = true;

                // disable GCODE file processor buttons
                btnStart.Enabled = false;
                btnStop.Enabled  = false;
            }

            // update graphics interface
            GraphicsHandler.SetDrawingColor1();
            GcodeHandler.RedrawFullPicture();

            toolStripStatusLabel1.Text = currentPortState.ToString();

            glControl1.Invalidate();
        }
Ejemplo n.º 18
0
        private void ChangePortState(string portName, PortStates portState)
        {
            var pinConfiguration = _pinConfigurations.FirstOrDefault(p => p.PortName == portName);

            ChangePortState(pinConfiguration, portState);
        }
Ejemplo n.º 19
0
        public void ChangePortState(int pinId, PortStates portState)
        {
            var pinConfiguration = _pinConfigurations.FirstOrDefault(p => p.PinId == pinId);

            ChangePortState(pinConfiguration, portState);
        }