public void close()
 {
     if (serial == null)
     {
         return;
     }
     connected = false;
     lock (nextlineLock)
     {
         try
         {
             serial.Close();
             serial.Dispose();
         }
         catch (Exception) { }
         serial = null;
     }
     job.KillJob();
     history.Clear();
     injectCommands.Clear();
     resendNode = null;
     if (eventConnectionChange != null)
     {
         try
         {
             Main.main.Invoke(eventConnectionChange, "Disconnected");
         }
         catch { } // Closing the app can cause an exception, if event comes after Main handle is destroyed
     }
     firePrinterAction("Idle");
     Main.main.Invoke(Main.main.UpdateJobButtons);
 }
 public void open()
 {
     try {
         serial                = new ProtectedSerialPort();
         serial.PortName       = port;
         serial.BaudRate       = baud;
         serial.Parity         = parity;
         serial.DataBits       = databits;
         serial.StopBits       = stopbits;
         serial.DataReceived  += received;
         serial.ErrorReceived += error;
         serial.Open();
         connected = true;
         if (transferProtocol < 2)
         {
             binaryVersion = 0;
         }
         else
         {
             binaryVersion = transferProtocol - 1;
         }
         readyForNextSend = true;
         nackLines.Clear();
         ignoreNextOk = false;
         linesSend    = errorsReceived = bytesSend = 0;
         GetInjectLock();
         injectManualCommand("N0 M110"); // Make sure we tal about the same linenumbers
         injectManualCommand("M115");    // Check firmware
         injectManualCommand("M105");    // Read temperature
         ReturnInjectLock();
         if (eventConnectionChange != null)
         {
             eventConnectionChange("Connected");
         }
         Main.main.Invoke(Main.main.UpdateJobButtons);
     }
     catch (IOException ex) {
         serial = null;
         log(ex.Message, true, 2);
         if (eventConnectionChange != null)
         {
             eventConnectionChange("Conn. error");
         }
     }
 }
 public void open()
 {
     try {
         serial = new ProtectedSerialPort();
         serial.PortName = port;
         serial.BaudRate = baud;
         serial.Parity = parity;
         serial.DataBits = databits;
         serial.StopBits = stopbits;
         serial.DataReceived += received;
         serial.ErrorReceived += error;
         serial.Open();
         connected = true;
         if (transferProtocol < 2)
             binaryVersion = 0;
         else binaryVersion = transferProtocol - 1;
         readyForNextSend = true;
         nackLines.Clear();
         ignoreNextOk = false;
         linesSend = errorsReceived = bytesSend = 0;
         GetInjectLock();
         injectManualCommand("N0 M110"); // Make sure we tal about the same linenumbers
         injectManualCommand("M115"); // Check firmware
         injectManualCommand("M105"); // Read temperature
         ReturnInjectLock();
         if (eventConnectionChange != null)
             eventConnectionChange("Connected");
         Main.main.Invoke(Main.main.UpdateJobButtons);
     }
     catch(IOException ex) {
         serial = null;
         log(ex.Message, true, 2);
         if(eventConnectionChange!=null)
             eventConnectionChange("Conn. error");
     }
 }
 public void close()
 {
     if(serial == null) return;
     connected = false;
     lock (nextlineLock)
     {
         try
         {
             serial.Close();
             serial.Dispose();
         }
         catch (Exception) { }
         serial = null;
     }
     job.KillJob();
     history.Clear();
     injectCommands.Clear();
     resendNode = null;
     if(eventConnectionChange!=null)
         try
         {
             Main.main.Invoke(eventConnectionChange, "Disconnected");
         }
         catch { } // Closing the app can cause an exception, if event comes after Main handle is destroyed
     firePrinterAction("Idle");
     Main.main.Invoke(Main.main.UpdateJobButtons);
 }