public string ShowDialog(string orgport)
        {
            if (!string.IsNullOrEmpty(orgport))
            {
                string portname = orgport.Substring(0, orgport.IndexOf(':'));
                if (PortAvailable(portname))
                {
                    ((SerialPorts)DataContext).SelectedPort = portname;
                    string[] values = orgport.Split(':')[1].Split(',');
                    if (values.Length > 5)
                    {
                        Comms.ResetMode mode = Comms.ResetMode.None;
                        Enum.TryParse(values[5], true, out mode);
                        if (mode != Comms.ResetMode.None)
                        {
                            foreach (ConnectMode m in ((SerialPorts)DataContext).ConnectModes)
                            {
                                if (m.Mode == mode)
                                {
                                    ((SerialPorts)DataContext).SelectedMode = m;
                                }
                            }
                        }
                    }
                }
            }

            ShowDialog();

            return(port);
        }
Example #2
0
        public string ShowDialog(string orgport)
        {
            if (!string.IsNullOrEmpty(orgport))
            {
                if ((prop.IsWebSocket = orgport.ToLower().StartsWith("ws://")))
                {
                    parsenet(orgport.Substring(5));
                }
                else if (char.IsDigit(orgport[0])) // We have an IP address
                {
                    parsenet(orgport);
                }
                else
                {
                    string portname = orgport.Substring(0, orgport.IndexOf(':'));
                    if (PortAvailable(portname))
                    {
                        prop.Com.SelectedPort = portname;
                        string[] values = orgport.Split(':')[1].Split(',');
                        if (values.Length > 5)
                        {
                            Comms.ResetMode mode = Comms.ResetMode.None;
                            Enum.TryParse(values[5], true, out mode);
                            if (mode != Comms.ResetMode.None)
                            {
                                foreach (ConnectMode m in prop.Com.ConnectModes)
                                {
                                    if (m.Mode == mode)
                                    {
                                        prop.Com.SelectedMode = m;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            ShowDialog();

            return(port);
        }
Example #3
0
        public SerialComms(string PortParams, Comms.ResetMode ResetMode)
        {
            Comms.com  = this;
            this.Reply = "";

            try
            {
                this.SerialPort = new SPortLib.SPortAx();
            }
            catch
            {
                MessageBox.Show("Failed to load serial port driver.", "GCode Sender");
                System.Environment.Exit(1);
            }

            this.SerialPort.InitString(PortParams.Substring(PortParams.IndexOf(":") + 1));
            //           this.SerialPort.HandShake = 0x08; // Cannot be used with ESP32
            this.SerialPort.FlowReplace   = 0x80;
            this.SerialPort.CharEvent     = 10;
            this.SerialPort.InBufferSize  = Comms.RXBUFFERSIZE;
            this.SerialPort.OutBufferSize = Comms.TXBUFFERSIZE;
            this.SerialPort.BlockMode     = false;


            this.SerialPort.Open(PortParams.Substring(0, PortParams.IndexOf(":")));
            this.SerialPort.OnRxFlag += new SPortLib._ISPortAxEvents_OnRxFlagEventHandler(this.SerialRead);

            System.Threading.Thread.Sleep(500);

            if (this.SerialPort.IsOpened)
            {
                /* For resetting ESP32, use DTR for Arduino
                 * this.SerialPort.RtsEnable = true;
                 * this.SerialPort.RtsEnable = false;
                 * System.Threading.Thread.Sleep(300);
                 */
                this.SerialPort.PurgeQueue();
                this.SerialPort.OnRxFlag += new SPortLib._ISPortAxEvents_OnRxFlagEventHandler(this.SerialRead);
            }
        }
Example #4
0
        public EltimaStream(string PortParams, int ResetDelay, Dispatcher dispatcher)
        {
            Comms.com  = this;
            Dispatcher = dispatcher;
            Reply      = string.Empty;

            if (PortParams.IndexOf(":") < 0)
            {
                PortParams += ":115200,N,8,1";
            }

            string[] parameter = PortParams.Substring(PortParams.IndexOf(":") + 1).Split(',');

            if (parameter.Count() < 4)
            {
                MessageBox.Show("Unable to open serial port: " + PortParams, "GCode Sender");
                System.Environment.Exit(2);
            }

            try
            {
                this.serialPort = new SPortLib.SPortAx();
            }
            catch
            {
                MessageBox.Show("Failed to load serial port driver.", "GCode Sender");
                System.Environment.Exit(1);
            }

            this.serialPort.InitString(PortParams.Substring(PortParams.IndexOf(":") + 1));
            //           this.SerialPort.HandShake = 0x08; // Cannot be used with ESP32
            this.serialPort.FlowReplace   = 0x80;
            this.serialPort.CharEvent     = 10;
            this.serialPort.InBufferSize  = Comms.RXBUFFERSIZE;
            this.serialPort.OutBufferSize = Comms.TXBUFFERSIZE;
            this.serialPort.BlockMode     = false;


            try
            {
                serialPort.Open(PortParams.Substring(0, PortParams.IndexOf(":")));
            }
            catch
            {
            }

            if (serialPort.IsOpened)
            {
                serialPort.DTR = true;

                Comms.ResetMode ResetMode = Comms.ResetMode.None;

                PurgeQueue();
                this.serialPort.OnRxFlag += new SPortLib._ISPortAxEvents_OnRxFlagEventHandler(SerialPort_DataReceived);

                if (parameter.Count() > 5)
                {
                    Enum.TryParse(parameter[5], true, out ResetMode);
                }

                switch (ResetMode)
                {
                case Comms.ResetMode.RTS:
                    /* For resetting ESP32 */
                    serialPort.RTS = true;
                    System.Threading.Thread.Sleep(5);
                    serialPort.RTS = false;
                    if (ResetDelay > 0)
                    {
                        System.Threading.Thread.Sleep(ResetDelay);
                    }
                    break;

                case Comms.ResetMode.DTR:
                    /* For resetting Arduino */
                    serialPort.DTR = false;
                    System.Threading.Thread.Sleep(5);
                    serialPort.DTR = true;
                    if (ResetDelay > 0)
                    {
                        System.Threading.Thread.Sleep(ResetDelay);
                    }
                    break;
                }

#if RESPONSELOG
                if (Resources.DebugFile != string.Empty)
                {
                    try
                    {
                        log = new StreamWriter(Resources.DebugFile);
                    } catch
                    {
                        MessageBox.Show("Unable to open log file: " + Resources.DebugFile, "GCode Sender");
                    }
                }
#endif
            }
        }
Example #5
0
        public SerialStream(string PortParams, int ResetDelay, Dispatcher dispatcher)
        {
            Comms.com  = this;
            Dispatcher = dispatcher;
            Reply      = "";

            if (PortParams.IndexOf(":") < 0)
            {
                PortParams += ":115200,N,8,1";
            }

            string[] parameter = PortParams.Substring(PortParams.IndexOf(":") + 1).Split(',');

            if (parameter.Count() < 4)
            {
                MessageBox.Show("Unable to open serial port: " + PortParams, "GCode Sender");
                System.Environment.Exit(2);
            }

            serialPort          = new SerialPort();
            serialPort.PortName = PortParams.Substring(0, PortParams.IndexOf(":"));
            serialPort.BaudRate = int.Parse(parameter[0]);
            serialPort.Parity   = ParseParity(parameter[1]);
            serialPort.DataBits = int.Parse(parameter[2]);
            serialPort.StopBits = int.Parse(parameter[3]) == 1 ? StopBits.One : StopBits.Two;
            serialPort.ReceivedBytesThreshold = 1;
            serialPort.ReadTimeout            = 5000;
            serialPort.NewLine         = "\r\n";
            serialPort.ReadBufferSize  = Comms.RXBUFFERSIZE;
            serialPort.WriteBufferSize = Comms.TXBUFFERSIZE;

            if (parameter.Count() > 4)
            {
                switch (parameter[4])
                {
                case "P":     // Cannot be used With ESP32!
                    serialPort.Handshake = Handshake.RequestToSend;
                    break;

                case "X":
                    serialPort.Handshake = Handshake.XOnXOff;
                    break;
                }
            }

            try
            {
                serialPort.Open();
            }
            catch
            {
            }

            if (serialPort.IsOpen)
            {
                serialPort.DtrEnable = true;

                Comms.ResetMode ResetMode = Comms.ResetMode.None;

                PurgeQueue();
                serialPort.DataReceived += new SerialDataReceivedEventHandler(SerialPort_DataReceived);

                if (parameter.Count() > 5)
                {
                    Enum.TryParse(parameter[5], true, out ResetMode);
                }

                switch (ResetMode)
                {
                case Comms.ResetMode.RTS:
                    /* For resetting ESP32 */
                    serialPort.RtsEnable = true;
                    System.Threading.Thread.Sleep(5);
                    serialPort.RtsEnable = false;
                    if (ResetDelay > 0)
                    {
                        System.Threading.Thread.Sleep(ResetDelay);
                    }
                    break;

                case Comms.ResetMode.DTR:
                    /* For resetting Arduino */
                    serialPort.DtrEnable = false;
                    System.Threading.Thread.Sleep(5);
                    serialPort.DtrEnable = true;
                    if (ResetDelay > 0)
                    {
                        System.Threading.Thread.Sleep(ResetDelay);
                    }
                    break;
                }

#if RESPONSELOG
                log = new StreamWriter(@"D:\grbl.txt");
#endif
            }
        }
Example #6
0
 public ConnectMode(Comms.ResetMode mode, string name)
 {
     Mode = mode;
     Name = name;
 }