Пример #1
0
 private static List<Data> toList(DataTable dt)
 {
     List<Data> result = new List<Data>();
     foreach (DataRow row in dt.Rows)
     {
         Data data = new Data();
         data.Low = Int32.Parse(row["low"].ToString());
         data.NodeID = Int32.Parse(row["nodeid"].ToString());
         data.RawData = row["rawdata"].ToString();
         data.LoggingOn = DateTime.Parse(row["loggingon"].ToString());
         result.Add(data);
     }
     return result;
 }
Пример #2
0
 private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
 {
     string data_all = port.ReadLine();
     if (data_all != null && data_all != "")
     {
         DateTime loggingOn = DateTime.Now;
         string[] data_unit = data_all.Trim().Split(' ');
         foreach (string item in data_unit)
         {
             string[] keyValuePair = item.Split(':');
             Data data = new Data();
             data.NodeID = Int32.Parse(new string(keyValuePair[0].Reverse<char>().ToArray<char>()));
             data.Low = Int32.Parse(new string(keyValuePair[1].Reverse<char>().ToArray<char>()));
             data.LoggingOn = loggingOn;
             data.RawData = item;
             data.Save();
         }
     }
 }