示例#1
0
 public void Write(byte[] arr)
 {
     if (IsOpen)
     {
         ComLogger.Log("tx", arr);
         cln.Send(arr);
     }
 }
示例#2
0
 public void Write(byte b)
 {
     if (IsOpen)
     {
         ComLogger.Log("tx", b);
         cln.Send(new string((char)b, 1));
     }
 }
示例#3
0
 public void Write(string text)
 {
     if (IsOpen)
     {
         ComLogger.Log("tx", text);
         cln.Send(text);
     }
 }
        public void Open()
        {
            if (!com.IsOpen)
            {
                try
                {
                    com.DataBits     = 8;
                    com.Parity       = System.IO.Ports.Parity.None;
                    com.StopBits     = System.IO.Ports.StopBits.One;
                    com.Handshake    = System.IO.Ports.Handshake.None;
                    com.PortName     = mPortName;
                    com.BaudRate     = mBaudRate;
                    com.NewLine      = "\n";
                    com.WriteTimeout = 1000;                     //se si blocca in write

                    com.DtrEnable = (bool)Settings.GetObject("HardReset Grbl On Connect", false);
                    com.RtsEnable = (bool)Settings.GetObject("HardReset Grbl On Connect", false);

                    if ((Firmware)Settings.GetObject("Firmware Type", Firmware.Grbl) == Firmware.Marlin)
                    {
                        com.DtrEnable = true;
                    }

                    ComLogger.Log("com", string.Format("Open {0} @ {1} baud {2}", com.PortName.ToUpper(), com.BaudRate, GetResetDiagnosticString()));
                    Logger.LogMessage("OpenCom", "Open {0} @ {1} baud {2}", com.PortName.ToUpper(), com.BaudRate, GetResetDiagnosticString());

                    com.Open();
                    com.DiscardOutBuffer();
                    com.DiscardInBuffer();
                }
                catch (System.IO.IOException ioex)
                {
                    if (char.IsDigit(mPortName[mPortName.Length - 1]) && char.IsDigit(mPortName[mPortName.Length - 2]))                     //two digits port like COM23
                    {
                        //FIX https://github.com/arkypita/PrintekLaserFoam/issues/31

                        try
                        {
                            com.PortName = mPortName.Substring(0, mPortName.Length - 1);                             //remove last digit and try again

                            ComLogger.Log("com", string.Format("Open {0} @ {1} baud {2}", com.PortName.ToUpper(), com.BaudRate, GetResetDiagnosticString()));
                            Logger.LogMessage("OpenCom", "Retry opening {0} as {1} (issue #31)", mPortName.ToUpper(), com.PortName.ToUpper());

                            com.Open();
                            com.DiscardOutBuffer();
                            com.DiscardInBuffer();
                        }
                        catch
                        {
                            throw ioex;                             //throw the original ex - not the new one!
                        }
                    }
                    else
                    {
                    }
                }
            }
        }
 public void Close(bool auto)
 {
     if (com.IsOpen)
     {
         ComLogger.Log("com", string.Format("Close {0} [{1}]", com.PortName.ToUpper(), auto ? "CORE" : "USER"));
         Logger.LogMessage("CloseCom", "Close {0} [{1}]", com.PortName.ToUpper(), auto ? "CORE" : "USER");
         try { com.DiscardOutBuffer(); } catch { }
         try { com.DiscardInBuffer(); } catch { }
         try { com.Close(); } catch { }
     }
 }
 public string ReadLineBlocking()
 {
     if (ComLogger.Enabled)
     {
         string rv = com.ReadLine();
         ComLogger.Log("rx", rv);
         return(rv);
     }
     else
     {
         return(com.ReadLine());
     }
 }         //la lettura della com è bloccante per natura
示例#7
0
        public string ReadLineBlocking()
        {
            string rv = null;

            while (IsOpen && rv == null)             //wait for disconnect or data
            {
                rv = sreader.ReadLine();

                if (rv == null)
                {
                    System.Threading.Thread.Sleep(1);
                }
            }

            ComLogger.Log("rx", rv);
            return(rv);
        }
示例#8
0
        public void Close(bool auto)
        {
            if (cln != null)
            {
                try
                {
                    ComLogger.Log("com", string.Format("Close {0} [{1}]", mAddress, auto ? "CORE" : "USER"));
                    Logger.LogMessage("CloseCom", "Close {0} [{1}]", mAddress, auto ? "CORE" : "USER");
                    cln.Close();
                }
                catch { }

                cln     = null;
                bwriter = null;
                sreader = null;
                swriter = null;
            }
        }
示例#9
0
        public void Close(bool auto)
        {
            if (cln != null)
            {
                try
                {
                    ComLogger.Log("com", string.Format("Close {0} [{1}]", mAddress, auto ? "CORE" : "USER"));
                    Logger.LogMessage("CloseCom", "Close {0} [{1}]", mAddress, auto ? "CORE" : "USER");
                    cln.OnMessage -= cln_OnMessage;

                    cln.Close();
                }
                catch { }

                buffer.Clear();
                cln = null;
            }
        }
示例#10
0
        public string ReadLineBlocking()
        {
            string rv = null;

            while (IsOpen && rv == null)             //wait for disconnect or data
            {
                if (buffer.Count > 0)
                {
                    rv = buffer.Dequeue();
                }
                else
                {
                    System.Threading.Thread.Sleep(1);
                }
            }

            ComLogger.Log("rx", rv);
            return(rv);
        }
示例#11
0
        public void Open()
        {
            if (cln != null)
            {
                Close(true);
            }


            if (string.IsNullOrEmpty(mAddress))
            {
                throw new MissingFieldException("Missing Address");
            }

            buffer.Clear();
            cln = new WebSocketSharp.WebSocket(mAddress);

            Logger.LogMessage("OpenCom", "Open {0}", mAddress);
            ComLogger.Log("com", string.Format("Open {0} {1}", mAddress, GetResetDiagnosticString()));

            cln.OnMessage += cln_OnMessage;
            cln.Connect();
        }
示例#12
0
        public void Open()
        {
            if (cln != null)
            {
                Close(true);
            }

            if (string.IsNullOrEmpty(mAddress))
            {
                throw new MissingFieldException("Missing HostName");
            }

            cln = new System.Net.Sockets.TcpClient();
            Logger.LogMessage("OpenCom", "Open {0}", mAddress);
            ComLogger.Log("com", string.Format("Open {0} {1}", mAddress, GetResetDiagnosticString()));

            cln.Connect(IPHelper.Parse(mAddress));

            Stream cst = cln.GetStream();

            bwriter = new BinaryWriter(cst);
            sreader = new StreamReader(cst, Encoding.ASCII);
            swriter = new StreamWriter(cst, Encoding.ASCII);
        }
示例#13
0
 public void Write(string text)
 {
     ComLogger.Log("tx", text);
     swriter.Write(text);
     swriter.Flush();
 }
示例#14
0
 public void Write(byte[] arr)
 {
     ComLogger.Log("tx", arr);
     com.Write(arr, 0, arr.Length);
 }
示例#15
0
 public void Write(byte b)
 {
     ComLogger.Log("tx", b);
     com.Write(new byte[] { b }, 0, 1);
 }
示例#16
0
 public void Write(byte b)
 {
     ComLogger.Log("tx", b);
     bwriter.Write(b);
     bwriter.Flush();
 }
示例#17
0
 public void Write(byte[] arr)
 {
     ComLogger.Log("tx", arr);
     bwriter.Write(arr);
     bwriter.Flush();
 }
示例#18
0
 public void Write(string text)
 {
     ComLogger.Log("tx", text);
     com.Write(text);
 }