Esempio n. 1
0
        private static void CalcCountPipe(Service.InputSerial input)
        {
            foreach (PipeCounterHelper pipeCounterHelper in PipeCounterHelpers)
            {
                try {
                    if (pipeCounterHelper.IsInitCounterPipe == false)
                    {
                        SQLiteCommand sqlCmd = new SQLiteCommand(dbConn);
                        sqlCmd.CommandText = "select count(*) from sqlite_master where name='" +
                                             input.ListDataParams[pipeCounterHelper.IndexCounter].Title +
                                             "|" +
                                             input.ListDataParams[pipeCounterHelper.IndexCounter].ParamUnit.Title + "';";
                        if (Convert.ToInt32(sqlCmd.ExecuteScalar()) == 0)
                        {
                            return;
                        }
                        sqlCmd.CommandText =
                            "SELECT * FROM '" +
                            input.ListDataParams[pipeCounterHelper.IndexCounter].Title +
                            "|" +
                            input.ListDataParams[pipeCounterHelper.IndexCounter].ParamUnit.Title +
                            "' ORDER BY ID DESC LIMIT 1";
                        SQLiteDataReader dataReader = sqlCmd.ExecuteReader();
                        DataTable        dt         = new DataTable();
                        dt.Load(dataReader);
                        input.ListDataParams[pipeCounterHelper.IndexCounter].Value = Convert.ToSingle(dt.Rows[0][1]);
                        pipeCounterHelper.CountPipe           = input.ListDataParams[pipeCounterHelper.IndexCounter].Value;
                        pipeCounterHelper.DateTimeCounterPipe = Convert.ToDateTime(dt.Rows[0][2]);
                        double subTime = DateTime.Now.Subtract(pipeCounterHelper.DateTimeCounterPipe).TotalSeconds;
                        if (subTime > 1800)
                        {
                            pipeCounterHelper.Reset();
                            input.ListDataParams[pipeCounterHelper.IndexCounter].Value = 0;
                        }
                        pipeCounterHelper.IsInitCounterPipe = true;
                        //pipeCounterHelper.CalcPipe(input.ListDataParams[pipeCounterHelper.IndexCounter - 1].Value);
                    }
                    else
                    {
                        pipeCounterHelper.CalcPipe(input.ListDataParams[pipeCounterHelper.IndexCounter - 1].Value);
                        input.ListDataParams[pipeCounterHelper.IndexCounter].Value = pipeCounterHelper.CountPipe;
                    }
                } catch (Exception ex) {
                    Service.Log.LogWrite(EnvPath, ex.Message, ex.ToString());
                }
            }

            return;
        }
Esempio n. 2
0
 public static void UpdateInputs(string[] data, string titleDB)
 {
     StopPorts();
     dbFileName = EnvPath + titleDB + ".sqlite";
     if (!File.Exists(dbFileName))
     {
         SQLiteConnection.CreateFile(dbFileName);
     }
     try {
         dbConn = new SQLiteConnection("Data Source=" + dbFileName + ";Version=3;");
         dbConn.Open();
         //sqlCmd.Connection = dbConn;
         SQLiteCommand sqlCmd = new SQLiteCommand(dbConn);
         sqlCmd.CommandText = "select numwork from 'works' where id = (select count(*) from works);";
         NumWork            = Convert.ToInt32(sqlCmd.ExecuteScalar());
     } catch (Exception e) {
         Service.Log.LogWrite(EnvPath, "Ошибка подключения к базе данных", e.ToString());
     }
     Inputs = new ObservableCollection <InputM>();
     for (int i = 0; i < data.Length; i++)
     {
         JObject json = JObject.Parse(data[i]);
         if (json.Property("PortName") != null)
         {
             Service.InputSerial input = JsonConvert.DeserializeObject <Service.InputSerial>(data[i]);
             for (int j = 0; j < input.ListDataParams.Count; j++)
             {
                 if ((input.ListDataParams[j].ParamType.Title == "Длина трубы") && (j + 1 < input.ListDataParams.Count) && (input.ListDataParams[j + 1].ParamType.Title == "Кол-во труб"))
                 {
                     PipeCounterHelpers.Add(new PipeCounterHelper {
                         IndexCounter = j + 1
                     });
                     j++;
                 }
             }
             Inputs.Add(new InputM {
                 Input = input
             });
         }
         else
         {
             Service.InputEthernet input = JsonConvert.DeserializeObject <Service.InputEthernet>(data[i]);
             Inputs.Add(new InputM {
                 Input = input
             });
         }
     }
     StartPorts();
 }
Esempio n. 3
0
        private static void Port_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            SerialPort sp   = (SerialPort)sender;
            string     data = "";

            try {
                if (!sp.IsOpen)
                {
                    return;
                }
                data = sp.ReadLine();
            } catch {
                if (!sp.IsOpen)
                {
                    return;
                }
                data  = sp.ReadExisting();
                data += "\n";
            }
            try {
                Service.InputSerial input        = GetInputByCOMPort(sp.PortName);
                string[]            splittedData = data.Split(new string[] { input.SymbolSplitter }, StringSplitOptions.None);
                if (splittedData.Length < 2)
                {
                    return;
                }

                int      startIndexData = 0;
                DateTime dateTime;
                if (DateTime.TryParse(splittedData[0], out dateTime))
                {
                    startIndexData = 1;
                }

                int startIndexInput = 0;
                if (input.ListDataParams[0].ParamType.Title == "Время")
                {
                    startIndexInput = 1;
                }

                for (; startIndexData < splittedData.Length; startIndexData++)
                {
                    if (startIndexInput >= input.ListDataParams.Count)
                    {
                        break;
                    }
                    input.ListDataParams[startIndexInput].Value = Convert.ToSingle(splittedData[startIndexData].Replace('.', ','));
                    startIndexInput++;
                    if (startIndexInput >= input.ListDataParams.Count)
                    {
                        break;
                    }
                    if (input.ListDataParams[startIndexInput].ParamType.Title == "Кол-во труб")
                    {
                        startIndexInput++;
                    }
                }
                CalcCountPipe(input);
                WriteToBD(input);
                WCFSendValues(input);
                Status = 2;
            } catch (Exception ex) {
                Service.Log.LogWrite(EnvPath, ex.Message, ex.ToString());
            }
        }