示例#1
0
        public SerialComms(string PortParams)
        {
            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;
            this.SerialPort.FlowReplace   = 0x80;
            this.SerialPort.CharEvent     = 10;
            this.SerialPort.InBufferSize  = RXBUFFERSIZE;
            this.SerialPort.OutBufferSize = TXBUFFERSIZE;
            this.SerialPort.BlockMode     = false;

            this.SerialPort.OnRxFlag += new SPortLib._ISPortAxEvents_OnRxFlagEventHandler(this.SerialRead);

            this.SerialPort.Open(PortParams.Substring(0, PortParams.IndexOf(":")));

            if (this.SerialPort.IsOpened)
            {
                this.SerialPort.PurgeQueue();
                this.SerialPort.OnRxFlag += new SPortLib._ISPortAxEvents_OnRxFlagEventHandler(this.SerialRead);
            }
        }
示例#2
0
 public void Close()
 {
     if (!IsClosing && IsOpen)
     {
         IsClosing = true;
         try
         {
             //serialPort.DataReceived -= SerialPort_DataReceived;
             //serialPort.DtrEnable = false;
             //serialPort.RtsEnable = false;
             //serialPort.DiscardInBuffer();
             //serialPort.DiscardOutBuffer();
             System.Threading.Thread.Sleep(100);
             serialPort.Close();
             serialPort = null;
         }
         catch { }
         IsClosing = false;
     }
 }
示例#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);
            }
        }
示例#4
0
        public UserUI(string[] args)
        {
            InitializeComponent();
            this.FormClosed               += new FormClosedEventHandler(OnExit);
            this.btnStart.Click           += new EventHandler(btnStart_Click);
            this.btnCancel.Click          += new EventHandler(btnCancel_Click);
            this.btnMotors.Click          += new EventHandler(btnMotors_Click);
            this.DragEnter                += new DragEventHandler(UserUI_DragEnter);
            this.DragDrop                 += new DragEventHandler(UserUI_DragDrop);
            this.zFocus.Scroll            += new EventHandler(zFocus_Scrolled);
            this.zFocus.MouseDown         += new MouseEventHandler(zFocus_MouseDown);
            this.zFocus.MouseUp           += new MouseEventHandler(zFocus_MouseUp);
            this.zPower.Scroll            += new EventHandler(zPower_Scrolled);
            this.zPower.MouseDown         += new MouseEventHandler(zPower_MouseDown);
            this.zPower.MouseUp           += new MouseEventHandler(zPower_MouseUp);
            this.zOn.Click                += new EventHandler(zOn_Click);
            this.btnHome.Click            += new EventHandler(btnHome_Click);
            this.chkMirror.CheckedChanged += new EventHandler(chkMirror_CheckedChanged);
            this.aboutMenuItem.Click      += new EventHandler(aboutMenuItem_Click);
            this.exitMenuItem.Click       += new EventHandler(exitMenuItem_Click);

            // default to KiCad v5 file name endings
            this.fileEnding.topCopper    = "F_Cu";
            this.fileEnding.bottomCopper = "B_Cu";
            this.fileEnding.topMask      = "F_Mask";
            this.fileEnding.bottomMask   = "B_Mask";

            int    p       = 0;
            string ininame = "PCBLaser.config";

            while (p < args.GetLength(0))
            {
                switch (args[p++])
                {
                case "-inifile":
                    ininame = GetArg(args, p++);
                    break;
                }
            }

            try
            {
                XmlDocument config = new XmlDocument();

                config.Load(Application.StartupPath + "\\" + ininame);

                foreach (XmlNode N in config.SelectNodes("PCBConfig/*"))
                {
                    switch (N.Name)
                    {
                    case "PortParams":
                        this.PortParams = N.InnerText;
                        break;

                    case "DefaultPower":
                        this.zPower.Value = int.Parse(N.InnerText);
                        break;

                    case "XOffset":
                        this.Xoffset = int.Parse(N.InnerText);
                        break;

                    case "YOffset":
                        this.Yoffset = int.Parse(N.InnerText);
                        break;

                    case "EtchMaskEmulsion":
                        this.emulsionEtchMask = this.parseEmulsionType(N.InnerText);
                        break;

                    case "SolderMaskEmulsion":
                        this.emulsionSolderMask = this.parseEmulsionType(N.InnerText);
                        break;

                    case "BacklashCompensation":
                        this.XBacklashComp = int.Parse(N.InnerText);
                        break;
                    }
                }

                foreach (XmlNode N in config.SelectNodes("PCBConfig/FileNameEnding/*"))
                {
                    switch (N.Name)
                    {
                    case "TopCopper":
                        this.fileEnding.topCopper = N.InnerText;
                        break;

                    case "BottomCopper":
                        this.fileEnding.bottomCopper = N.InnerText;
                        break;

                    case "TopMask":
                        this.fileEnding.topMask = N.InnerText;
                        break;

                    case "BottomMask":
                        this.fileEnding.bottomMask = N.InnerText;
                        break;
                    }
                }
            }
            catch
            {
                MessageBox.Show("Config file not found or invalid.", ininame);
                System.Environment.Exit(1);
            }

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

            this.SerialPort.InitString(PortParams.Substring(PortParams.IndexOf(":") + 1));
            this.SerialPort.HandShake   = 0x08;
            this.SerialPort.FlowReplace = 0x80;
            this.SerialPort.CharEvent   = 10;
            this.SerialPort.BlockMode   = false;
            this.SerialPort.OnRxFlag   += new SPortLib._ISPortAxEvents_OnRxFlagEventHandler(this.SerialRead);

            this.SerialPort.Open(PortParams.Substring(0, PortParams.IndexOf(":")));
#else
            string[] parameter = PortParams.Substring(PortParams.IndexOf(":") + 1).Split(',');

            if (parameter.Count() < 4)
            {
                this.disableUI();
                MessageBox.Show("Unable to open printer: " + PortParams, this.Text);
                System.Environment.Exit(2);
            }

            this.SerialPort          = new SerialPort();
            this.SerialPort.PortName = PortParams.Substring(0, PortParams.IndexOf(":"));
            this.SerialPort.BaudRate = int.Parse(parameter[0]);
            this.SerialPort.Parity   = ParseParity(parameter[1]);
            this.SerialPort.DataBits = int.Parse(parameter[2]);
            this.SerialPort.StopBits = int.Parse(parameter[3]) == 1 ? StopBits.One : StopBits.Two;
            if (parameter.Count() > 4)
            {
                this.SerialPort.Handshake = parameter[4] == "X" ? Handshake.XOnXOff : Handshake.RequestToSend;
            }
            this.SerialPort.ReceivedBytesThreshold = 1;
            this.SerialPort.NewLine         = "\r\n";
            this.SerialPort.WriteBufferSize = TXBUFFERSIZE;
            this.SerialPort.DataReceived   += new SerialDataReceivedEventHandler(SerialPort_DataReceived);
            try
            {
                this.SerialPort.Open();
            }
            catch
            {
            }
#endif

            if (this.SerialOpen)
            {
                this.SerialOut("?");

                this.pollTimer                     = new System.Timers.Timer();
                this.pollTimer.Interval            = this.PollInterval;
                this.pollTimer.Elapsed            += new System.Timers.ElapsedEventHandler(RenderRow);
                this.pollTimer.SynchronizingObject = this;

                this.motorTimer                     = new System.Timers.Timer();
                this.motorTimer.Interval            = 60 * 1000; // 1 minute
                this.motorTimer.Elapsed            += new System.Timers.ElapsedEventHandler(MotorOff);
                this.motorTimer.SynchronizingObject = this;

                this.SerialOut("XHome:" + this.Xoffset.ToString());
                this.SerialOut("YHome:" + this.Yoffset.ToString());
                this.setLaserPower(false);
            }
            else
            {
                this.disableUI();
                MessageBox.Show("Unable to open printer: " + PortParams, this.Text);
                System.Environment.Exit(2);
            }

            this.enableUI();

            this.zFocus.Value = this.z;
            this.cbxEtchEmulsion.SelectedIndex   = (int)this.emulsionEtchMask;
            this.cbxSolderEmulsion.SelectedIndex = (int)this.emulsionSolderMask;
            this.chkInvert.Checked = solderMask ? this.emulsionSolderMask == EmulsionType.Negative : this.emulsionEtchMask == EmulsionType.Positive;

            this.cbxEtchEmulsion.SelectedIndexChanged   += new EventHandler(cbxEtchEmulsion_SelectedIndexChanged);
            this.cbxSolderEmulsion.SelectedIndexChanged += new EventHandler(cbxSolderEmulsion_SelectedIndexChanged);

            this.Visible = true;
        }
示例#5
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
            }
        }