示例#1
0
        public int ParseLine(string line)
        {
            /*if (line.IndexOf('>') > 0)
            {
                line = line.Remove(0, line.IndexOf('>'));
            }*/
            if (line.Length < 4)
                return 0;
            CRC crc = new CRC();
            string crcStr = line.Substring(line.Length-3,2);
            string calcCrc = line.Remove(line.Length - 3, 3);
            calcCrc = crc.GetCRC(calcCrc);
            calcCrc = calcCrc.Substring(calcCrc.Length-3,2);
            if (crcStr != calcCrc)
            {
                return 0;
            }
            int countParam=0;
            int ch1 = 0;
            int ch2 = 0;
            int countChar=0;
            bool flagCh = false;
            char[] charLine = new char[line.Length];
            line=line.Remove(line.Length-3,3);
            charLine = line.ToCharArray();
            while (countChar != line.Length)
            {
                if ((charLine[countChar] == '+') || (charLine[countChar] == '-'))
                    {
                        if (flagCh == false)
                            {
                            ch1 = countChar;
                            flagCh = true;

                            ch2 = countChar;
                            if ((line.IndexOf('+', ch2 + 1) < 0) && (line.IndexOf('-', ch2 + 1) < 0))
                            {
                                string catStr;
                                catStr = line.Substring(ch2, line.Length - ch2);
                                catStr = catStr.Replace('.', ',');
                                //catStr = catStr.Remove(0, 1);
                                param[countParam] = Convert.ToDouble(catStr);
                                countParam++;
                            }
                            }
                        else
                            {
                                ch2 = countChar;
                                string catStr = line.Substring(ch1, ch2 - ch1);
                                catStr=catStr.Replace('.', ',');
                                param[countParam] = Convert.ToDouble(catStr);
                                flagCh = false;
                                countParam++;
                                countChar--;
                                if ((line.IndexOf('+', ch2+1) < 0) && (line.IndexOf('-', ch2+1) < 0))
                                {
                                    catStr = line.Substring(ch2, line.Length-ch2);
                                    catStr = catStr.Replace('.', ',');
                                    param[countParam] = Convert.ToDouble(catStr);
                                    countParam++;
                                }
                                ch1 = 0;
                                ch2 = 0;
                            }
                    }
                countChar++;
            }

            return countParam;
        }
示例#2
0
        static void func()
        {
            CallBackMy.callbackEventHandlerPozReostat = new CallBackMy.callbackEventPozReostat(ReloadPoz);
            CallBackMy.callbackEventHandlerPozKM = new CallBackMy.callbackEventPozKM(ReloadPozKM);
            CallBackMy.callbackEventHandlerTypeLoc = new CallBackMy.callbackEventTypeLoc(ReloadTypeLoc);
            CallBackMy.callbackEventHandlerNumberLoc = new CallBackMy.callbackEventNumberLoc(ReloadNumberLoc);
            CallBackMy.callbackEventHandlerExtPoint = new CallBackMy.callbackEventExtPoint(ReloadExtPoint);
            CallBackMy.callbackEventHandlerNew = new CallBackMy.callbackEventNew(ReloadData);

            int pozTeplovozPrev = 0;
            int pozTeplovoz = 0;
            pozReostat = 0;
            dataClass = new myclass[11];
            int i=0;
            while (i != 11)
            {
                dataClass[i] = new myclass();
                i++;
            }

            CRC crc = new CRC();
            DefPoz def = new DefPoz();
            PowerData[] powerData = new PowerData[9];
            i = 0;
            while (i != 9)
            {
                powerData[i] = new PowerData();
                i++;
            }

            web = new webserver();
            IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName());
            IPAddress ipAddress = ipHostInfo.AddressList[0];
            web.start(ipAddress, 80, 5, @".\");

            Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            IPAddress ip = IPAddress.Any;
            IPEndPoint ipe = new IPEndPoint(ip, 128);
            s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, true);
            s.Bind(ipe);
            byte[] buffer = new byte[1024];
            IPAddress ipRem = IPAddress.Any;
            int portRem = 128;
            IPEndPoint Rem = new IPEndPoint(ipRem, portRem);
            EndPoint EndRem = (EndPoint)Rem;
            XmlDocument parserXml = new XmlDocument();
            string error;
            Thread.Sleep(200);

            for (; ; )
            {
                Thread.Sleep(200);

                if (s.Available > 0)
                {
                    s.ReceiveFrom(buffer, ref EndRem);
                    data = Encoding.ASCII.GetString(buffer);
                    data.IndexOf("<EOF>");
                    data = data.Remove(data.IndexOf("<EOF>"), 5);
                    try
                    {
                        parserXml.LoadXml(data);
                    }
                    catch (Exception e)
                    {
                        error = e.ToString();
                    }
                    XmlNodeList xml;

                    xml = parserXml.GetElementsByTagName("owtemp");
                    if (xml.Count > 0)
                        owtemp = Convert.ToInt32(xml[0].InnerText);
                    xml = parserXml.GetElementsByTagName("current");
                    if(xml.Count>0)
                        dataClass[10].Current = (int)(Math.Abs(Convert.ToInt32(xml[0].InnerText) * 1500 / 4095));
                    xml = parserXml.GetElementsByTagName("voltage");
                    if (xml.Count > 0)
                    dataClass[10].Voltage = (int)(Math.Abs(Convert.ToInt32(xml[0].InnerText) * 1000 / 4095));
                    xml = parserXml.GetElementsByTagName("voltagebort");
                    if (xml.Count > 0)
                    dataClass[10].VoltageBort = (int)(Convert.ToInt32(xml[0].InnerText));
                    xml = parserXml.GetElementsByTagName("tempbort");
                    if (xml.Count > 0)
                    dataClass[10].TempBort = Convert.ToInt32(xml[0].InnerText);
                    xml = parserXml.GetElementsByTagName("tempgas1");
                    if (xml.Count > 0)
                    dataClass[10].TempCil1 = Convert.ToInt32(xml[0].InnerText);
                    xml = parserXml.GetElementsByTagName("tempgas2");
                    if (xml.Count > 0)
                    dataClass[10].TempCil2 = Convert.ToInt32(xml[0].InnerText);
                    xml = parserXml.GetElementsByTagName("tempgas3");
                    if (xml.Count > 0)
                    dataClass[10].TempCil3 = Convert.ToInt32(xml[0].InnerText);
                    xml = parserXml.GetElementsByTagName("tempgas4");
                    if (xml.Count > 0)
                    dataClass[10].TempCil4 = Convert.ToInt32(xml[0].InnerText);
                    xml = parserXml.GetElementsByTagName("tempgas5");
                    if (xml.Count > 0)
                    dataClass[10].TempCil5 = Convert.ToInt32(xml[0].InnerText);
                    xml = parserXml.GetElementsByTagName("tempgas6");
                    if (xml.Count > 0)
                    dataClass[10].TempCil6 = Convert.ToInt32(xml[0].InnerText);
                    xml = parserXml.GetElementsByTagName("rpm");
                    if (xml.Count > 0)
                    dataClass[10].RpmDGU = Convert.ToInt32(xml[0].InnerText);
                    xml = parserXml.GetElementsByTagName("tempwater");
                    if (xml.Count > 0)
                    dataClass[10].TempWater = Convert.ToInt32(xml[0].InnerText);
                    xml = parserXml.GetElementsByTagName("tempoil");
                    if (xml.Count > 0)
                    dataClass[10].TempOil = Convert.ToInt32(xml[0].InnerText);
                    xml = parserXml.GetElementsByTagName("pressoil");
                    if (xml.Count > 0)
                        dataClass[10].PressGas = Convert.ToInt32(xml[0].InnerText) / 100.0 ;
                    xml = parserXml.GetElementsByTagName("pressgas");
                    if (xml.Count > 0)
                        dataClass[10].PressOil = Convert.ToInt32(xml[0].InnerText) / 100.0;

                    xml = parserXml.GetElementsByTagName("pozteplovoz");
                    if (xml.Count > 0)
                    {
                        def.DefinitionPoz(xml[0].InnerText, typeLoc);
                        if (flagExt == false)
                            dataClass[10].PozDGU = def.PozDGU;//рабочее
                        else
                            dataClass[10].PozDGU = pozExt;
                        pozTeplovoz = dataClass[10].PozDGU;
                        dataClass[10].StateVSH1 = def.StateVSH1;
                        dataClass[10].StateVSH2 = def.StateVSH2;
                    }
                }

                if (flagExt == true)
                {
                    dataClass[10].PozDGU = pozExt;
                    pozTeplovoz = dataClass[10].PozDGU;
                }

                if (pozTeplovoz != pozTeplovozPrev)
                    {
                        pozTeplovozPrev = pozTeplovoz;
                        checkTimer = false;
                        countTimer = 0;
                        dataClass[10].FlagValid = false;
                    }
                if ((pozTeplovoz == 8) && (dataClass[10].Current > 300))
                    dataClass[10].Power = (int)(((dataClass[10].Current * dataClass[10].Voltage) / 1000) + (dataClass[10].TempBort - 20));
                else
                    dataClass[10].Power = (dataClass[10].Current * dataClass[10].Voltage) / 1000;
                dataClass[10].TypeLoc = typeLoc;
                dataClass[10].NumberLoc = numberLoc;
                dataClass[10].PozReostat = pozReostat;

                if ((checkTimer == true) && (checkSecund == true))
                {
                    checkSecund = false;
                    string htmTeg;
                    string text = System.IO.File.ReadAllText(@".\index.html");
                    htmTeg = "<!--current-->";
                    text = text.Insert(text.IndexOf(htmTeg) + htmTeg.Length, dataClass[10].Current.ToString());
                    htmTeg = "<!--voltage-->";
                    text = text.Insert(text.IndexOf(htmTeg) + htmTeg.Length, dataClass[10].Voltage.ToString());
                    htmTeg = "<!--voltagebort-->";
                    text = text.Insert(text.IndexOf(htmTeg) + htmTeg.Length, dataClass[10].VoltageBort.ToString());
                    htmTeg = "<!--power-->";
                    text = text.Insert(text.IndexOf(htmTeg) + htmTeg.Length, dataClass[10].Power.ToString());
                    htmTeg = "<!--rpmdgu-->";
                    text = text.Insert(text.IndexOf(htmTeg) + htmTeg.Length, dataClass[10].RpmDGU.ToString());
                    htmTeg = "<!--tempwater-->";
                    text = text.Insert(text.IndexOf(htmTeg) + htmTeg.Length, dataClass[10].TempWater.ToString());
                    htmTeg = "<!--tempoil-->";
                    text = text.Insert(text.IndexOf(htmTeg) + htmTeg.Length, dataClass[10].TempOil.ToString());
                    htmTeg = "<!--pressoil-->";
                    text = text.Insert(text.IndexOf(htmTeg) + htmTeg.Length, dataClass[10].PressOil.ToString());
                    htmTeg = "<!--tempgas1-->";
                    text = text.Insert(text.IndexOf(htmTeg) + htmTeg.Length, dataClass[10].TempCil1.ToString());
                    htmTeg = "<!--tempgas2-->";
                    text = text.Insert(text.IndexOf(htmTeg) + htmTeg.Length, dataClass[10].TempCil2.ToString());
                    htmTeg = "<!--tempgas3-->";
                    text = text.Insert(text.IndexOf(htmTeg) + htmTeg.Length, dataClass[10].TempCil3.ToString());
                    htmTeg = "<!--tempgas4-->";
                    text = text.Insert(text.IndexOf(htmTeg) + htmTeg.Length, dataClass[10].TempCil4.ToString());
                    htmTeg = "<!--tempgas5-->";
                    text = text.Insert(text.IndexOf(htmTeg) + htmTeg.Length, dataClass[10].TempCil5.ToString());
                    htmTeg = "<!--tempgas6-->";
                    text = text.Insert(text.IndexOf(htmTeg) + htmTeg.Length, dataClass[10].TempCil6.ToString());
                    htmTeg = "<!--tempbort-->";
                    text = text.Insert(text.IndexOf(htmTeg) + htmTeg.Length, dataClass[10].TempBort.ToString());
                    htmTeg = "<!--pozteplovoz-->";
                    text = text.Insert(text.IndexOf(htmTeg) + htmTeg.Length, dataClass[10].PozDGU.ToString());
                    htmTeg = "<!--pozreostat-->";
                    text = text.Insert(text.IndexOf(htmTeg) + htmTeg.Length, dataClass[10].PozReostat.ToString());
                    htmTeg = "<!--owtemp-->";
                    text = text.Insert(text.IndexOf(htmTeg) + htmTeg.Length, owtemp.ToString());
                    web.stringHtml(text);

                    if ((dataClass[10].Current > 20) && (dataClass[10].Voltage > 20)&&(pozTeplovoz > 0))
                    {
                        dataClass[pozTeplovoz].Current = dataClass[10].Current;
                        dataClass[pozTeplovoz].Voltage = dataClass[10].Voltage;
                        dataClass[pozTeplovoz].TempOil = dataClass[10].TempOil;
                        dataClass[pozTeplovoz].TempWater = dataClass[10].TempWater;
                        dataClass[pozTeplovoz].TempCil1 = dataClass[10].TempCil1;
                        dataClass[pozTeplovoz].TempCil2 = dataClass[10].TempCil2;
                        dataClass[pozTeplovoz].TempCil3 = dataClass[10].TempCil3;
                        dataClass[pozTeplovoz].TempCil4 = dataClass[10].TempCil4;
                        dataClass[pozTeplovoz].TempCil5 = dataClass[10].TempCil5;
                        dataClass[pozTeplovoz].TempCil6 = dataClass[10].TempCil6;
                        dataClass[pozTeplovoz].Power = dataClass[10].Power;
                        dataClass[pozTeplovoz].PozDGU = pozTeplovoz;
                        dataClass[pozTeplovoz].PressGas = dataClass[10].PressGas;
                        dataClass[pozTeplovoz].PressOil = dataClass[10].PressOil;
                        dataClass[pozTeplovoz].RpmDGU = dataClass[10].RpmDGU;
                        dataClass[pozTeplovoz].Time++;
                        dataClass[pozTeplovoz].VoltageBort = dataClass[10].VoltageBort;

                        if (pozTeplovoz<9)
                            if (powerData[pozTeplovoz].pushData(dataClass[10].Power) == true)
                                {
                                dataClass[pozTeplovoz].PowerDGU = powerData[pozTeplovoz].ResultPower();
                                }
                    }
                    else
                    {
                        if (pozTeplovoz == 0)
                        {
                            dataClass[pozTeplovoz].Current = dataClass[10].Current;
                            dataClass[pozTeplovoz].Voltage = dataClass[10].Voltage;
                            dataClass[pozTeplovoz].TempOil = dataClass[10].TempOil;
                            dataClass[pozTeplovoz].TempWater = dataClass[10].TempWater;
                            dataClass[pozTeplovoz].TempCil1 = dataClass[10].TempCil1;
                            dataClass[pozTeplovoz].TempCil2 = dataClass[10].TempCil2;
                            dataClass[pozTeplovoz].TempCil3 = dataClass[10].TempCil3;
                            dataClass[pozTeplovoz].TempCil4 = dataClass[10].TempCil4;
                            dataClass[pozTeplovoz].TempCil5 = dataClass[10].TempCil5;
                            dataClass[pozTeplovoz].TempCil6 = dataClass[10].TempCil6;
                            dataClass[pozTeplovoz].Power = 0;
                            dataClass[pozTeplovoz].PozDGU = 0;
                            dataClass[pozTeplovoz].PressGas = dataClass[10].PressGas;
                            dataClass[pozTeplovoz].PressOil = dataClass[10].PressOil;
                            dataClass[pozTeplovoz].RpmDGU = dataClass[10].RpmDGU;
                            dataClass[pozTeplovoz].Time++;
                            dataClass[pozTeplovoz].VoltageBort = dataClass[10].VoltageBort;

                        }
                    }

                    dataClass[10].Time++;
                    dataClass[10].ExtDataPoint = extData;
                }

                if (dataClass[10].StateVSH1 != preStateRP1)
                {
                    if (dataClass[10].StateVSH1 == true)
                    {
                        if (dataClass[10].SwitchRelePoint.RP1_ON_current == 0)
                        {
                            dataClass[10].SwitchRelePoint.RP1_ON_current = dataClass[10].Current;
                            dataClass[10].SwitchRelePoint.RP1_ON_voltage = dataClass[10].Voltage;
                        }
                        else
                        {
                            dataClass[10].SwitchRelePoint.RP1_ON_current = dataClass[10].Current;
                            dataClass[10].SwitchRelePoint.RP1_ON_voltage = dataClass[10].Voltage;
                        }
                    }
                    else
                    {
                        if (dataClass[10].SwitchRelePoint.RP1_OFF_current == 0)
                        {
                            dataClass[10].SwitchRelePoint.RP1_OFF_current = dataClass[10].Current;
                            dataClass[10].SwitchRelePoint.RP1_OFF_voltage = dataClass[10].Voltage;
                        }
                        else
                        {
                            dataClass[10].SwitchRelePoint.RP1_OFF_current = dataClass[10].Current;
                            dataClass[10].SwitchRelePoint.RP1_OFF_voltage = dataClass[10].Voltage;
                        }
                    }
                }

                if (dataClass[10].StateVSH2 != preStateRP2)
                {
                    if (dataClass[10].StateVSH2 == true)
                    {
                        if (dataClass[10].SwitchRelePoint.RP2_ON_current == 0)
                        {
                            dataClass[10].SwitchRelePoint.RP2_ON_current = dataClass[10].Current;
                            dataClass[10].SwitchRelePoint.RP2_ON_voltage = dataClass[10].Voltage;
                        }
                        else
                        {
                            dataClass[10].SwitchRelePoint.RP2_ON_current = dataClass[10].Current;
                            dataClass[10].SwitchRelePoint.RP2_ON_voltage = dataClass[10].Voltage;
                        }
                    }
                    else
                    {
                        if (dataClass[10].SwitchRelePoint.RP2_OFF_current == 0)
                        {
                            dataClass[10].SwitchRelePoint.RP2_OFF_current = dataClass[10].Current;
                            dataClass[10].SwitchRelePoint.RP2_OFF_voltage = dataClass[10].Voltage;
                        }
                        else
                        {
                            dataClass[10].SwitchRelePoint.RP2_OFF_current = dataClass[10].Current;
                            dataClass[10].SwitchRelePoint.RP2_OFF_voltage = dataClass[10].Voltage;
                        }
                    }
                }

                preStateRP1 = dataClass[10].StateVSH1;
                preStateRP2 = dataClass[10].StateVSH2;

                if (pozReostat != 0)
                    {
                        dataClass[10].FlagWork = true;
                    }

                CallBackMy.callbackEventHandler(dataClass);

                /*temp***************************************/
                /*dataClass[10].Current = 1256;
                dataClass[10].Voltage = 356;
                dataClass[10].TempOil = 78;
                dataClass[10].TempWater = 67;
                dataClass[10].TempCil1 = 567;
                dataClass[10].TempCil2 = 456;
                dataClass[10].TempCil3 = 45;
                dataClass[10].TempCil4 = 567;
                dataClass[10].TempCil5 = 656;
                dataClass[10].TempCil6 = 34;
                dataClass[10].PozDGU = 3;
                dataClass[10].PressGas = 0.53;
                dataClass[10].PressOil = 2.56;
                dataClass[10].RpmDGU = 430;
                dataClass[10].VoltageBort = 75;*/
                /****************************************/
            }
        }
示例#3
0
        public int ParseRele(string line)
        {
            if (line.Length < 4)
                return 0;
            CRC crc = new CRC();
            string crcStr = line.Substring(line.Length - 3, 2);
            string calcCrc = line.Remove(line.Length - 3, 3);
            calcCrc = crc.GetCRC(calcCrc);
            calcCrc = calcCrc.Substring(calcCrc.Length - 3, 2);
            if (crcStr != calcCrc)
            {
                return 0;
            }
            int countParam = 0;

            return countParam;
        }