예제 #1
0
        public static TeMonitorSocketInfo FromTelnetString(string text)
        {
            string cleanedText = Regex.Replace(text, @"\s+", " ");

            string[] par = text.Split(new[] { " ", "\t", "\r\n", "\r", "\n" },
                                      StringSplitOptions.RemoveEmptyEntries);

            if (par.Length <= 5)
            {
                return(null);
            }

            TeMonitorSocketInfo result = new TeMonitorSocketInfo();

            result.SocketId    = par[1];
            result.SensorIndex = par[2];
            result.SensorId    = par[3];
            result.Temperature = par[4];
            result.Unit        = par[5];

            return(result);
        }
예제 #2
0
        private void GetTemp()
        {
            try
            {
                if (String.IsNullOrEmpty(Properties.Settings.Default.TelnetAddress))
                {
                    return;
                }

                telnetConnection.Connect(Properties.Settings.Default.TelnetAddress, Properties.Settings.Default.TelnetPort);

                Thread.Sleep(100);

                String result = telnetConnection.Read();
                telnetConnection.Close();

                TeMonitorSocketInfo info = TeMonitorSocketInfo.FromTelnetString(result);
                if (info == null)
                {
                    return;
                }
                //logger.Info("TELNET: " + result);

                logger.Info("Temperature: " + info.Temperature);

                if (String.IsNullOrEmpty(Properties.Settings.Default.HostAddress))
                {
                    return;
                }

                Functions.PostRequest(Properties.Settings.Default.HostAddress, String.Format("weather={0} C", info.Temperature));
            }
            catch (Exception e)
            {
                logger.Error(e);
            }
        }