コード例 #1
0
        private void listenThreadFunction()
        {
            byte   currentByte;
            string v_currentLine;

            string[]            v_splitedString;
            TemperatureRegister v_currentRegister;

            char[] delimiters = new char[] { ';', ' ', ':' };
            while (working)
            {
                try
                {
                    v_currentLine = serialPort.ReadLine();
                    Console.WriteLine("CURRENT LINE: " + v_currentLine);
                    v_splitedString = v_currentLine.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
                    if (v_splitedString.Length <= 3)
                    {
                        continue;
                    }
                    else
                    {
                        v_currentRegister = new TemperatureRegister(int.Parse(v_splitedString[1]), int.Parse(v_splitedString[3]), DateTimeOffset.UtcNow, v_splitedString[5]);
                        this.m_registerBuffer.Enqueue(v_currentRegister);
                    }
                    currentByte = (byte)serialPort.ReadByte();
                    Console.WriteLine("CURRENT BYTE" + currentByte);
                }
                catch (Exception ex)
                {
                    //The specified port is not open.
                    if (ex is InvalidOperationException)
                    {
                        Console.WriteLine("", "Serial exception: " + ex.Message);
                        Reconnect();
                    }
                    //No byte was read.
                    else if (ex is TimeoutException)
                    {
                        unsucessfullConnections = 0;
                    }
                }
            }
        }
コード例 #2
0
 public TemperatureRegister getLast()
 {
     try
     {
         string result = m_client.DownloadString(m_baseURL + "/webapi/temperature/getLast");
         if (result != null)
         {
             TemperatureRegister b = JsonConvert.DeserializeObject <TemperatureRegister>(result);
             return(b);
         }
         else
         {
             return(null);
         }
     }
     catch (WebException ex)
     {
         if (ex.Status == WebExceptionStatus.ConnectFailure)
         {
             System.Threading.Thread.Sleep(1500);
         }
         return(null);
     }
 }