示例#1
0
 public SensorsTemp ReadData(SensorsTemp sensorsTemp)
 {
     try
     {
         using (var client = new SshClient(connectionInfo))
         {
             {
                 client.Connect();
                 if (client.IsConnected)
                 {
                     var request    = "cat /sys/devices/w1_bus_master1/" + sensorsTemp.Id + "/w1_slave";
                     var tempString = client.RunCommand(request);
                     if (tempString.Result == "")
                     {
                         sensorsTemp.SetToBad("No sensor");
                         return(sensorsTemp);
                     }
                     else
                     {
                         var resultTempString = tempString.Result.AsSpan();
                         var crc = resultTempString
                                   .Slice(29, 10)
                                   .ToString()
                                   .Split(" ");
                         var temp = resultTempString
                                    .Slice(67, 7)
                                    .ToString()
                                    .Split("=");
                         var test = crc[1] == "YES" ? true : false;
                         sensorsTemp.Update(Int32.Parse(temp[1]), crc[1] == "YES" ? true : false);
                         return(sensorsTemp);
                         //new Logger().Log(new SensorsTemp[] { sensor });
                     }
                 }
                 else
                 {
                     sensorsTemp.SetToBad("SSH not connect");
                     return(sensorsTemp);
                     //new Logger().LogMessage("SSH connection NOTactive");
                 }
             }
         }
     }
     catch
     {
         sensorsTemp.SetToBad("Request error");
         return(sensorsTemp);
         //new Logger().LogMessage("Error " + exception.Message);
     }
 }
示例#2
0
        public Sensors1Wire(TextWriter textWriter, ISQLWriter sqlWriter, IRequester requester)
        {
            this.TextWriter = textWriter;
            this.SQLWriter  = sqlWriter;
            this.Requester  = requester;

            Dict = new Dictionary <string, int>();
            var index = File.ReadAllLines(@"Resources\indexofallsensors.txt");

            Sensors = new SensorsTemp[index.Length];
            for (var i = 0; i < index.Length; i++)
            {
                var tempString = index[i].Split("\t");
                var sensorsId  = int.Parse(tempString[0]) - 1;
                Sensors[sensorsId] = new SensorsTemp(i + 1, tempString[1], tempString[2]);
                Dict.Add(tempString[1], sensorsId);
            }
        }