Ejemplo n.º 1
0
        void ConnectSerial()
        {
            //string s = (string)ErrorIcon.ToolTip;
            if (this.SerialConnected && !sp.IsOpen)
            {
                foreach (string ComPort in System.IO.Ports.SerialPort.GetPortNames())
                {
                    if (!sp.IsOpen && SerialConnected)
                    {
                        sp = new System.IO.Ports.SerialPort(ComPort, 19200);
                        try
                        {
                            sp.Open();

                            if (sp.BytesToRead < 10)
                            {
                                sp.Close();
                            }
                            else
                            {
                                sr = new SerialRemote(ref sp);
                            }
                        }
                        catch
                        {
                            SerialConnected = false;
                        }
                    }
                }
                if (!sp.IsOpen)
                {
                    // ErrorIcon.Visibility = Visibility.Visible;
                    //  if (!s.Contains("Error connecting to analog controls")) ErrorIcon.ToolTip = ErrorIcon.ToolTip + "Error connecting to analog controls. Click to troubleshoot.\r";
                    SerialConnected = false;
                }
                else
                {
                    sr.start(); SerialConnected = true;
                }
            }
        }