Ejemplo n.º 1
0
        private void openPort()
        {
            try
            {
                Logger.Info("openPort {0} {1}", cbPort.Text, cbBaud.Text);
                serialPort.PortName  = cbPort.Text;
                serialPort.DataBits  = 8;
                serialPort.BaudRate  = Convert.ToInt32(cbBaud.Text);
                serialPort.Parity    = System.IO.Ports.Parity.None;
                serialPort.StopBits  = System.IO.Ports.StopBits.One;
                serialPort.Handshake = System.IO.Ports.Handshake.None;
                serialPort.DtrEnable = false;
                rtbLog.Clear();
                if (refreshPorts())
                {
                    if (Properties.Settings.Default.ctrlUseSerialPortFixer)
                    {
                        try
                        { SerialPortFixer.Execute(cbPort.Text); }
                        catch (Exception err)
                        { Logger.Error(err, " -SerialPortFixer-"); }
                    }
                    serialPort.Open();
                    serialPort.DiscardOutBuffer();
                    serialPort.DiscardInBuffer();

                    addToLog("* Open " + cbPort.Text + "\r\n");
                    btnOpenPort.Text = Localization.getString("serialClose");  // "Close";

                    if (Properties.Settings.Default.serialMinimize)
                    {
                        countMinimizeForm = (int)(3000 / timerSerial.Interval); // minimize window after 3 sec.
                    }
                    timerSerial.Interval = timerReload;                         // timerReload;
                }
                else
                {
                    addToLog("* " + cbPort.Text + " not available\r\n");
                    Logger.Warn("Port {1} not available", cbPort.Text);
                }
                serialPortOpen = serialPort.IsOpen;
                updateControls();
            }
            catch (Exception err)
            {
                Logger.Error(err, " -openPort-");
                countMinimizeForm = 0;
                logError("! Opening port", err);
                serialPortOpen = false;
                updateControls();
            }
        }
Ejemplo n.º 2
0
 private bool openPort()
 {
     try
     {
         Logger.Info("closePort {0}", serialPort.PortName);
         serialPort.PortName = cbPort.Text;
         serialPort.BaudRate = Convert.ToInt32(cbBaud.Text);
         serialPort.Encoding = Encoding.GetEncoding(28591);
         SerialPortFixer.Execute(cbPort.Text);
         serialPort.Open();
         rtbLog.Clear();
         rtbLog.AppendText("Open " + cbPort.Text + "\r\n");
         btnOpenPort.Text = "Close";
         return(true);
     }
     catch (Exception err)
     {
         Logger.Error(err, "-closePort-");
         logError("Opening port", err);
         return(false);
     }
 }
Ejemplo n.º 3
0
        private void openPort()
        {
            rxErrorCount = 0;
            try
            { Logger.Info("Ser:{0}, openPort {1} {2}", iamSerial, cbPort.Text, cbBaud.Text);
              serialPort.PortName  = actualPort = cbPort.Text;
              serialPort.DataBits  = 8;
              serialPort.BaudRate  = Convert.ToInt32(cbBaud.Text);
              serialPort.Parity    = System.IO.Ports.Parity.None;
              serialPort.StopBits  = System.IO.Ports.StopBits.One;
              serialPort.Handshake = System.IO.Ports.Handshake.None;
              serialPort.DtrEnable = false;
              rtbLog.Clear();
              if (refreshPorts())
              {
                  if (Properties.Settings.Default.ctrlUseSerialPortFixer)
                  {
                      try
                      { SerialPortFixer.Execute(cbPort.Text); }
                      catch (Exception err)
                      { Logger.Error(err, "Ser:{0} -SerialPortFixer-", iamSerial); }
                  }
                  serialPort.Open();
                  serialPort.DiscardOutBuffer();
                  serialPort.DiscardInBuffer();

                  addToLog("* Open " + cbPort.Text + "\r\n");
                  if (iamSerial == 1)
                  {
                      grbl.lastMessage = "Open COM Port: " + cbPort.Text;
                  }
                  btnOpenPort.Text = Localization.getString("serialClose");    // "Close";
                  isDataProcessing = true;
                  if (iamSerial == 1)
                  {
                      grbl.Clear();
                  }

                  if (Properties.Settings.Default.serialMinimize)
                  {
                      countMinimizeForm = (int)(3000 / timerSerial.Interval);   // minimize window after 5 sec.
                  }
                  timerSerial.Interval     = grbl.pollInterval;                 // timerReload;
                  countMissingStatusReport = (int)(2000 / timerSerial.Interval);

                  countPreventOutput = 0; countPreventEvent = 0;
                  isHeightProbing    = false;
                  if (grbl.grblSimulate)
                  {
                      grbl.grblSimulate = false;
                      addToLog("* Stop simulation\r\n");
                  }
                  grblReset(false);

                  OnRaisePosEvent(new PosEventArgs(posWork, posMachine, grblState.unknown, machineState, mParserState, ""));  // lastCmd));
              }
              else
              {
                  addToLog("* " + cbPort.Text + " not available\r\n");
                  Logger.Warn("Ser:{0}, Port {1} not available", iamSerial, cbPort.Text);
                  if (iamSerial == 1)
                  {
                      grbl.lastMessage = "Open COM Port: " + cbPort.Text + " failed";
                  }
              }
              serialPortOpen = serialPort.IsOpen;
              updateControls(); }
            catch (Exception err)
            {
                Logger.Error(err, "Ser:{0} -openPort-", iamSerial);
                countMinimizeForm = 0;
                logError("! Opening port", err);
                serialPortOpen = false;
                updateControls();
            }
        }