Exemple #1
0
        //突发上传
        public string AutoSend(APDUClass apdu)
        {
            ASDUClass asduNew = new ASDUClass(1);

            asduNew.Pack(ASDUClass.TransRes.AutoSend, ASDUClass.FunType.Single_point, 0x6001, (double)Convert.ToByte(SwitchStatus));

            APCIClassIFormat apciNew = new APCIClassIFormat(_sr++, _nr);

            APDUClass apduNew = new APDUClass(apciNew, asduNew); //apci的长度将在此处被设置

            byte[] bytes = apduNew.ToArray();
            return(log);
        }
Exemple #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            ASDUClass clockBuffer = new ASDUClass();

            //clockBuffer.Pack(ASDUClass.TransRes.File, ASDUClass.FunType.FileReady);
            clockBuffer.Pack(textBox3.Text);
            APDUClass apdu = new APDUClass(new APCIClassIFormat(++sr, nr), clockBuffer);


            byte[] byf      = new byte[] { 0x68, 0x04, 0x0B, 0x00, 0x00, 0x00 };
            byte[] bytetemp = new byte[] { 0x68, 0x18, 0x12, 0x00, 0x00, 0x00, 0x40, 0x01, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x56, 0x33, 0x03, 0x0e, 0x10, 0x09, 0x13 };
            byte[] bytet    = new byte[] { 0x68, 0x16, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x97, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x99 };
            Send(apdu.ToArray());
        }
Exemple #3
0
        //回复激活终止, 暂未实现
        public APDUClass StopActive(APDUClass apdu)
        {
            ASDUClass asduNew = new ASDUClass(1);

            //类型标识、根据命令确定可变结构限定词的值、设置数据
            asduNew.Pack(ASDUClass.TransRes.ActiveStop, ASDUClass.FunType.CalAll, 0, 0x14);

            APCIClassIFormat apciNew = new APCIClassIFormat(_sr++, _nr);

            APDUClass apduNew = new APDUClass(apciNew, asduNew); //apci的长度将在此处被设置

            //byte[] bytes = apduNew.ToArray();
            //log = string.Format("Client received data: {0} From: {1}.\n", apdu.ToString(), Client.ClientSession);
            log = string.Format("Stop Active \n Client sended data: {0} to: {1}.\n", apduNew.ToString(), Client.ClientSession);
            return(apduNew);
        }
Exemple #4
0
 //响应遥控
 public APDUClass OnTelecontrolling(APDUClass apdu)
 {
     return(null);
 }
Exemple #5
0
        //回复第三组召唤:实现
        public APDUClass OnRes003(APDUClass apdu, bool bSwitch)
        {
            ASDUClass asduNew = new ASDUClass(1);

            return(apduNew);
        }
Exemple #6
0
        //回复第二组召唤
        public APDUClass OnRes002(APDUClass apdu)
        {
            ASDUClass asduNew = new ASDUClass(1);

            return(apduNew);
        }
Exemple #7
0
 public APDUClass OnActive(APDUClass apdu)
 {
     return(apduNew);
 }
Exemple #8
0
        //回复激活确认:镜像报文
        public APDUClass Ack(APDUClass apdu)
        {
            //检查全站参数,如果没问题,则回复Active...

            return(apdu);
        }
Exemple #9
0
 //突发上传
 public string OnAutoSend(APDUClass apdu)
 {
     return(null);
 }
Exemple #10
0
 //接受第三组(遥信)
 public APDUClass OnRes003Confirm(APDUClass apdu)
 {
     return(null);
 }
Exemple #11
0
 //激活终止
 public APDUClass OnStopActive(APDUClass apdu)
 {
     return(null);
 }
Exemple #12
0
 //接受激活确认
 public APDUClass OnActiveConfirm(APDUClass apdu)
 {
     return(null);
 }
Exemple #13
0
 //收到镜像答复
 public string OnAck(APDUClass apdu)
 {
     return(null);
 }
Exemple #14
0
        /// <summary>
        /// 后台线程提交数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            try
            {
                FileInfo file = new FileInfo(logfile);
                long size = file.Length;//文件大小。byte
                if (size > 1024000)
                {
                    StreamWriter sw1 = new StreamWriter(logfile);
                    string w = "";
                    sw1.Write(w);
                    sw1.Close();
                }
            }
            catch { }

            if (e.ProgressPercentage == -1)
            {
                APDUClass temp = new APDUClass(e.UserState as byte[]);
                APCIClass.UISFormat dataFormat = temp.GetApciType();
                if (temp != null)
                {
                    try
                    {
                        sw = File.AppendText(logfile);
                        sw.WriteLine(DateTime.Now.ToString() + " TX: " + "Type:" + temp.GetAsduType().ToString() + " Res:" + temp.Res.ToString()
                                        + " SR:" + temp.GetSR().ToString() + " NR:" + temp.GetNR().ToString()
                                        + "\r\n" + temp.ApciToString() + temp.AsduToString() + "\r\n");
                        sw.Close();
                    }
                    catch {}
                    Console.WriteLine(DateTime.Now.ToString() + " TX: " + "Type:" + temp.GetAsduType().ToString() + " Res:" + temp.Res.ToString()
                                             + " SR:" + temp.GetSR().ToString() + " NR:" + temp.GetNR().ToString()
                                             + "\n" + temp.ApciToString() + temp.AsduToString() + "\r\n");
                }
            }
            else if (e.ProgressPercentage > 0)
            {
                byte[] receive = new byte[e.ProgressPercentage];
                Array.Copy(e.UserState as byte[], receive, e.ProgressPercentage);
                if (receive[0] == 0x68)
                {
                    int i = 0;
                    while (i < receive.Length)
                    {
                        try
                        {
                            int recevlen = receive[i + 1];
                            byte[] receivetemp = new byte[recevlen +2];
                            Array.Copy(receive, i, receivetemp, 0, receivetemp.Length);
                            i = i + receivetemp.Length;

                            APDUClass temp = new APDUClass(receivetemp);
                            APCIClass.UISFormat dataFormat = temp.GetApciType();
                            //if (dataFormat == APCIClass.UISFormat.I && !(nr > temp.GetSR()))
                            if (dataFormat == APCIClass.UISFormat.I)
                            {
                                nr = (short)temp.GetSR();
                                if (nr > short.MaxValue)
                                {
                                    nr = 0;
                                }
                                nrflag = true;
                                if (((nr % m_config_104.m_AckNW) == m_config_104.m_AckNW - 1)||(sr == 0))
                                {
                                    SendList.Enqueue(new APDUClass(new APCIClassSFormat(nr), null));
                                    for (int id = 0; id < SendList.Count - 1; id++)
                                    {
                                        APDUClass tempsend = SendList.Dequeue();
                                        SendList.Enqueue(tempsend);
                                    }
                                    nrflag = false;
                                }
                                if ((temp.GetAsduType() == ASDUClass.FunType.CalAll) && (temp.Res == ASDUClass.TransRes.ActiveEnd))
                                {
                                    ASDUClass calymBuffer = new ASDUClass();
                                    calymBuffer.Pack(ASDUClass.TransRes.Active, ASDUClass.FunType.CalEnergyPulse, m_config_104.m_PublicAddress);
                                    SendList.Enqueue(new APDUClass(new APCIClassIFormat(sr++, nr), calymBuffer));
                                    ASDUClass readymBuffer = new ASDUClass();
                                    readymBuffer.SetData_QCC(0x05, m_config_104.m_PublicAddress);
                                    SendList.Enqueue(new APDUClass(new APCIClassIFormat(sr++, nr), readymBuffer));
                                }
                            }
                            if (dataFormat == APCIClass.UISFormat.U)
                            {
                                if ((APCIClassUFormat.UFormatType)temp.GetApci().GetControlByte() == APCIClassUFormat.UFormatType.StartSet)
                                    SendList.Enqueue(new APDUClass(new APCIClassUFormat(APCIClassUFormat.UFormatType.StartConfirm), null));
                                if ((APCIClassUFormat.UFormatType)temp.GetApci().GetControlByte() == APCIClassUFormat.UFormatType.TestSet)
                                    SendList.Enqueue(new APDUClass(new APCIClassUFormat(APCIClassUFormat.UFormatType.TestConfirm), null));
                                if ((APCIClassUFormat.UFormatType)temp.GetApci().GetControlByte() == APCIClassUFormat.UFormatType.StopSet)
                                    SendList.Enqueue(new APDUClass(new APCIClassUFormat(APCIClassUFormat.UFormatType.StopConfirm), null));
                                if ((APCIClassUFormat.UFormatType)temp.GetApci().GetControlByte() == APCIClassUFormat.UFormatType.StartConfirm)
                                {
                                    ASDUClass calBuffer = new ASDUClass();
                                    calBuffer.Pack(ASDUClass.TransRes.Active, ASDUClass.FunType.CalAll, m_config_104.m_PublicAddress);
                                    SendList.Enqueue(new APDUClass(new APCIClassIFormat(sr++, nr), calBuffer));
                                }
                            }
                            ////对方发来确认帧,在核实确认序号等于或小于本分的I帧发送序号,再次发送I帧
                            ////此部分在“实现发送控制命令”时,给以完成。
                            //else if (dataFormat == APCIClass.UISFormat.S)
                            //{
                            //    if (nr > short.MaxValue)
                            //    {
                            //        nr = 0;
                            //    }
                            //    Console.WriteLine(dataFormat.ToString());
                            //    SendList.Enqueue(new APDUClass(new APCIClassSFormat(nr++), null));
                            //}

                            if (temp != null)
                            {
                                try
                                {
                                    sw = File.AppendText(logfile);
                                    sw.WriteLine(DateTime.Now.ToString() + " RX: " + "Type:" + temp.GetAsduType().ToString() + " Res:" + temp.Res.ToString()
                                                        + " SR:" + temp.GetSR().ToString() + " NR:" + temp.GetNR().ToString()
                                                        + "\r\n" + BitConverter.ToString(receivetemp, 0).Replace("-", " "));
                                    sw.Close();
                                }
                                catch { }

                                Console.WriteLine(DateTime.Now.ToString() + " RX: " + "Type:" + temp.GetAsduType().ToString() + " Res:" + temp.Res.ToString()
                                                    + " SR:" + temp.GetSR().ToString() + " NR:" + temp.GetNR().ToString()
                                                    + "\n" + BitConverter.ToString(receivetemp, 0).Replace("-", " "));

                                var datas = temp.GetData();
                                foreach (var data in datas)
                                {
                                    if (data.Addr == 0) continue;
                                    try
                                    {
                                        sw = File.AppendText(logfile);
                                        sw.WriteLine("RX " + "addr:" + data.Addr.ToString() + " " +
                                                    "data:" + data.Data.ToString() + " " +
                                                    "time:" + data.Time.ToString());
                                        sw.Close();
                                    }
                                    catch { }

                                    //Console.WriteLine("RX " + "addr:" + data.Addr.ToString() + " " +
                                    //                "data:" + data.Data.ToString() + " " +
                                    //                "time:" + data.Time.ToString());

                                    numInf numtemp = new numInf();
                                    if (find.TryGetValue(data.Addr, out numtemp))
                                    {
                                        numtemp.val = Convert.ToSingle(data.Data);
                                        if (data.Time != null)
                                        {
                                            numtemp.dtm = Convert.ToDateTime(data.Time);
                                        }
                                        else numtemp.dtm = DateTime.Now;
                                        find.Remove(data.Addr);
                                        find.Add(data.Addr, numtemp);
                                    }
                                    else
                                    {
                                        numtemp.val = Convert.ToSingle(data.Data);
                                        if (data.Time != null)
                                        {
                                            numtemp.dtm = Convert.ToDateTime(data.Time);
                                        }
                                        else numtemp.dtm = DateTime.Now;
                                        find.Add(data.Addr, numtemp);
                                    }
                                }
                                try
                                {
                                    sw = File.AppendText(logfile);
                                    sw.WriteLine("\r\n");
                                    sw.Close();
                                }
                                catch { }
                                Console.WriteLine("\r\n");
                            }
                        }
                        catch (Exception ex)
                        {
                            System.Diagnostics.Debug.WriteLine(ex.ToString());
                        }
                    }
                }
            }
        }
Exemple #15
0
        public static void UnPackString(string str)
        {
            //numInf[] numinf;
            string stemp = str.ToLower().Replace(" ", "");
            byte[] bytetemp = new byte[stemp.Length / 2];
            for (int i = 0; i < stemp.Length / 2; i++)
            {
                string ss = stemp.Substring(2 * i, 2);

                bytetemp[i] = Convert.ToByte(ss, 16);
            }
            try
            {
                APDUClass temp = new APDUClass(bytetemp);
                if (temp != null)
                {
                    //sw = File.AppendText(logfile);
                    //sw.WriteLine("RX: " + DateTime.Now.ToString() + " Type:" + temp.GetAsduType().ToString() + " Res:" + temp.Res.ToString()
                    //                    + " SR:" + temp.GetSR().ToString() + " NR:" + temp.GetNR().ToString()
                    //                    + "\r\n" + temp.ApciToString() + temp.AsduToString() + "\r\n");
                    //sw.Close();
                    //Console.WriteLine("RX: " + DateTime.Now.ToString() + " Type:" + temp.GetAsduType().ToString() + " Res:" + temp.Res.ToString()
                    //                        + " SR:" + temp.GetSR().ToString() + " NR:" + temp.GetNR().ToString()
                    //                        + "\n" + temp.ApciToString() + temp.AsduToString() + "\r\n");

                    Console.WriteLine("RX: " + "Type:" + temp.GetAsduType().ToString() + " Res:" + temp.Res.ToString()
                                     + " SR:" + temp.GetSR().ToString() + " NR:" + temp.GetNR().ToString());
                    var datas = temp.GetData();
                    //numinf = new numInf[datas.Count];
                    //int i = 0;
                    foreach (var data in datas)
                    {
                        //try { sw = File.AppendText(filestr); }
                        //catch { Thread.Sleep(50); sw = File.AppendText(filestr); }
                        //sw.WriteLine("RX " + "addr:" + data.Addr.ToString() + " " +
                        //            "data:" + data.Data.ToString() + " " +
                        //            "time:" + data.Time.ToString());
                        //sw.Close();
                        if (data.Addr == 0) continue;
                        Console.WriteLine("RX: " + "addr:" + data.Addr.ToString() + " " +
                                            "data:" + data.Data.ToString() + " " +
                                            "time:" + data.Time.ToString());

                        //numInf numtemp = new numInf() ;
                        //numinf[i].sn = Convert.ToInt16( data.Addr);
                        //numinf[i].val = Convert.ToSingle( data.Data);
                        //numinf[i].dtm = Convert.ToDateTime(data.Time);
                        //i++;

                    }

                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
            }
            //return numinf;
        }