Ejemplo n.º 1
0
        private void SettingForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (lockstate)
            {
                MyLog.Info("载入各项配置参数");

                mform.SetConfigValue("LocalIP1", textBox_LocalIP1.Text);
                mform.SetConfigValue("LocalPort1_ZK", textBox_LocalPort1_YK.Text);

                mform.SetConfigValue("LocalIP2", textBox_LocalIP2.Text);
                mform.SetConfigValue("LocalPort2_GT", textBox_LocalPort2_GT.Text);
                mform.SetConfigValue("LocalPort2_other", textBox_LocalPort2_other.Text);

                mform.SetConfigValue("ZK1IP", textBox_ZK1_IP.Text);
                mform.SetConfigValue("ZK2IP", textBox_ZK2_IP.Text);


                mform.SetConfigValue("Server_CRTa_Ip", textBox_CRTa_IP.Text);

                mform.SetConfigValue("Server_CRTa_Port", textBox_CRTa_Port.Text);
                mform.SetConfigValue("Server_CRTa_Port2", textBox_CRTa_Port2.Text);
            }
            else
            {
                DialogResult dr = MessageBox.Show("参数未保存,是否确定关闭此窗体?", "关闭提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (dr == DialogResult.No)
                {
                    e.Cancel = true;
                }
                else
                {
                    e.Cancel = false;
                }
            }
        }
Ejemplo n.º 2
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (textBox1.Text == "805H07_YKYC")
     {
         if (textBox2.Text == "123456")
         {
             MyLog.Info("用户名密码通过校验,解锁成功");
             mform.TagLock       = 0;
             mform.Logform_state = true;
             this.Close();
         }
         else
         {
             MyLog.Error("密码校验失败,解锁失败");
             this.label3.Text    = "密码错误";
             this.label3.Visible = true;
         }
     }
     else
     {
         MyLog.Error("用户名校验失败,解锁失败");
         this.label4.Text    = "用户名错误";
         this.label4.Visible = true;
     }
 }
Ejemplo n.º 3
0
        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            try
            {
                if (btn_ZK1_Close.Enabled)
                {
                    btn_ZK1_Close_Click(sender, e);
                }
                if (btn_ZK1_YC_Close.Enabled)
                {
                    btn_ZK1_YC_Close_Click(sender, e);
                }

                if (btn_CRTa_Open.Enabled == false)
                {
                    ClientAPP.Disconnect(ref ClientAPP.Server_CRTa);
                    ClientAPP.Disconnect(ref ClientAPP.Server_CRTa_Return);
                    btn_CRTa_Open.Enabled  = true;
                    btn_CRTa_Close.Enabled = false;
                    Data.DealCRTa.LedOff();
                    MyLog.Info("关闭连接--USB应答机A");
                }

                Thread.Sleep(100);
                mySaveFileThread.FileClose();
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 4
0
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            if (lockstate)
            {
                MyLog.Info("系统设置--解锁");
                lockstate = false;
                this.pictureBox1.Image = Properties.Resources.unlocked2;


                foreach (Control ctr in this.Controls)
                {
                    ctr.Enabled = true;
                }
            }
            else
            {
                MyLog.Info("系统设置--锁定");

                lockstate = true;
                this.pictureBox1.Image = Properties.Resources.locked;

                foreach (Control ctr in this.Controls)
                {
                    ctr.Enabled = false;
                }
                this.pictureBox1.Enabled = true;
            }
        }
Ejemplo n.º 5
0
 private void 系统设置ToolStripMenuItem_Click(object sender, EventArgs e)
 {
     MyLog.Info("进行系统设置");
     if (mySettingForm != null)
     {
         mySettingForm.Activate();
     }
     else
     {
         mySettingForm = new SettingForm(this);
     }
     mySettingForm.ShowDialog();
 }
Ejemplo n.º 6
0
        private void button1_Click(object sender, EventArgs e)
        {
            byte[] VCDU = new byte[1018];

            byte b1 = byte.Parse((string)Data.dtVCDU.Rows[0]["版本号"], System.Globalization.NumberStyles.HexNumber);
            byte b2 = byte.Parse((string)Data.dtVCDU.Rows[0]["SCID"], System.Globalization.NumberStyles.HexNumber);
            byte b3 = byte.Parse((string)Data.dtVCDU.Rows[0]["VCID"], System.Globalization.NumberStyles.HexNumber);

            VCDU[0] = (byte)((byte)(b1 << 6) + (byte)(b2 >> 2));
            VCDU[1] = (byte)((byte)(b2 << 6) + b3);
            string temp = ((string)Data.dtVCDU.Rows[0]["虚拟信道帧计数"]).PadLeft(6, '0');

            VCDU[2] = byte.Parse(temp.Substring(0, 2), System.Globalization.NumberStyles.HexNumber);
            VCDU[3] = byte.Parse(temp.Substring(2, 2), System.Globalization.NumberStyles.HexNumber);
            VCDU[4] = byte.Parse(temp.Substring(4, 2), System.Globalization.NumberStyles.HexNumber);
            byte b4 = byte.Parse((string)Data.dtVCDU.Rows[0]["回放"], System.Globalization.NumberStyles.HexNumber);
            byte b5 = byte.Parse((string)Data.dtVCDU.Rows[0]["保留"], System.Globalization.NumberStyles.HexNumber);

            VCDU[5] = (byte)((byte)(b4 << 7) + b5);

            byte[] time_login = new byte[6];
            time_login = Function.Get_Time();
            time_login.CopyTo(VCDU, 6);//时间

            Data.dtVCDU.Rows[0]["插入域"] = time_login[0].ToString("x2") + time_login[1].ToString("x2")
                                         + time_login[2].ToString("x2") + time_login[3].ToString("x2")
                                         + time_login[4].ToString("x2") + time_login[5].ToString("x2");

            for (int i = 12; i < 1018; i++)
            {
                VCDU[i] = 0xff;
            }


            byte[] temp2 = Function.StrToHexByte(textBox2.Text);
            Array.Copy(temp2, 0, VCDU, 12, temp2.Length);


            byte[] Return_Send = Function.Make_tozk_YC_frame(Data.Data_Flag_Real, Data.InfoFlag_DMTC, VCDU);
            if (myServer.ServerOn_YC)
            {
                Data.DataQueue_GT.Enqueue(Return_Send);
                MyLog.Info("手动发送一次遥测数据--成功");
            }
            else
            {
                Data.dtYC.Rows[4]["数量"] = (int)Data.dtYC.Rows[4]["数量"] + 1;
                MyLog.Error("手动发送一次遥测数据--失败");
            }
        }
Ejemplo n.º 7
0
        private void buttonCRT_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;

            switch (btn.Name)
            {
            case "btn_CRTa_Open":
                MyLog.Info("尝试连接--USB应答机A...");
                ClientAPP.Server_CRTa.ServerIP   = ConfigurationManager.AppSettings["Server_CRTa_Ip"];
                ClientAPP.Server_CRTa.ServerPORT = ConfigurationManager.AppSettings["Server_CRTa_Port"];
                ClientAPP.Connect(ref ClientAPP.Server_CRTa);
                if (ClientAPP.Server_CRTa.IsConnected)
                {
                    DealCRT_On(ref Data.DealCRTa);
                    MyLog.Info("连接成功--" + Data.DealCRTa.CRTName + "--遥控端口");
                    new Thread(() => { Fun_Transfer2CRT(ref Data.DealCRTa, ref ClientAPP.Server_CRTa, ref SaveFile.DataQueue_out2); }).Start();
                    new Thread(() => { Fun_RecvFromCRT(ref Data.DealCRTa, ref ClientAPP.Server_CRTa); }).Start();
                }
                else
                {
                    DealCRT_Off(ref Data.DealCRTa);
                    return;
                }
                btn_CRTa_Open.Enabled  = false;
                btn_CRTa_Close.Enabled = true;

                ClientAPP.Server_CRTa_Return.ServerIP   = ConfigurationManager.AppSettings["Server_CRTa_Ip"];
                ClientAPP.Server_CRTa_Return.ServerPORT = "3070";
                ClientAPP.Connect(ref ClientAPP.Server_CRTa_Return);
                if (ClientAPP.Server_CRTa_Return.IsConnected)
                {
                    MyLog.Info("连接成功--" + Data.DealCRTa.CRTName + "--遥测端口");
                    new Thread(() => { Fun_RecvFromCRT_Return(ref Data.DealCRTa, ref ClientAPP.Server_CRTa_Return); }).Start();
                }

                break;

            case "btn_CRTa_Close":
                ClientAPP.Disconnect(ref ClientAPP.Server_CRTa);
                ClientAPP.Disconnect(ref ClientAPP.Server_CRTa_Return);
                btn_CRTa_Open.Enabled  = true;
                btn_CRTa_Close.Enabled = false;
                Data.DealCRTa.LedOff();
                MyLog.Info("关闭连接--USB应答机A");
                break;

            default:
                break;
            }
        }
Ejemplo n.º 8
0
        public void FileClose()
        {
            MyLog.Info("关闭所有存盘线程");
            SaveOn = false;
            Trace.WriteLine("Start FileClose!\n");
            Thread.Sleep(500);

            foreach (var item in myFileList_dat)
            {
                item.Close();
            }

            foreach (var item in myFileList_txt)
            {
                item.Close();
            }
        }
Ejemplo n.º 9
0
        private void onCall_GT(IAsyncResult ar)
        {
            Trace.WriteLine("onCall----遥测服务器");
            Socket serverSoc = (Socket)ar.AsyncState;

            if (ServerOn_YC)
            {
                try
                {
                    Socket ClientSocket = serverSoc.EndAccept(ar);
                    if (serverSoc != null)
                    {
                        serverSoc.BeginAccept(new AsyncCallback(onCall_GT), serverSoc);
                        IPEndPoint tmppoint    = (IPEndPoint)ClientSocket.RemoteEndPoint;
                        String     RemoteIpStr = tmppoint.Address.ToString();
                        Console.WriteLine(RemoteIpStr);
                        if (RemoteIpStr == ClientAPP.ClientZK1_YC.ClientIP)
                        {
                            //----------发送登陆信息-----------
                            ClientSocket.Send(Function.Make_login_frame(Data.Data_Flag_Real, Data.ZK_S1));

                            MyLog.Info("遥测前端服务器---->向总控(主)发送登陆信息");

                            ClientAPP.ClientZK1_YC.IsConnected = true;
                            Data.ServerConnectEvent2.Set();

                            new Thread(() => { RecvFromClientGT(ClientSocket); }).Start();
                            new Thread(() => { SendToClientGT(ClientSocket); }).Start();

                            ClientSocketList2.Add(ClientSocket);
                        }
                    }
                }
                catch (SocketException ex)
                {
                    Trace.WriteLine(ex.Message);
                }
            }
            else
            {
                Console.WriteLine("Server already off!!!");
            }
        }
Ejemplo n.º 10
0
        //在主页面初始化时,调用FileInit()和FileSaveStart(),分别初始化文件夹和开始存储

        /// <summary>
        /// 存储线程初始化
        /// </summary>
        public void FileInit()
        {
            MyLog.Info("初始化运行日志存盘路径");
            Trace.WriteLine("Start FileInit!\n");

            //   FileCreateTxt(Program.GetStartupPath() + @"接收\总控设备(遥控)\", out file_in1);
            //FileCreateTxt(Program.GetStartupPath() + @"接收\总控设备(遥测)\", out file_in2);
            //  FileCreateTxt(Program.GetStartupPath() + @"接收\瑞信丰\", out file_in3);

            DataQueue_inList.Add(DataQueue_in1);
            DataQueue_inList.Add(DataQueue_in2);
            DataQueue_inList.Add(DataQueue_in3);

            myLockforTxt.Add(Lock_Txt1);
            myLockforTxt.Add(Lock_Txt2);
            myLockforTxt.Add(Lock_Txt3);


            FileCreateDat(Program.GetStartupPath() + @"接收\总控设备(遥控)\", out file_out1);
            FileCreateDat(Program.GetStartupPath() + @"发送\瑞信丰\", out file_out2);
            FileCreateDat(Program.GetStartupPath() + @"接收\瑞信丰\原始数据\", out file_out3);
            FileCreateDat(Program.GetStartupPath() + @"接收\瑞信丰\遥测数据\", out file_out4);
            FileCreateDat(Program.GetStartupPath() + @"发送\总控设备(遥测)\", out file_out5);
            FileCreateDat(Program.GetStartupPath() + @"生成数据\", out file_out6);
            //FileCreateDat(Program.GetStartupPath() + @"发送\其它舱(总控)\", out file_out7);

            DataQueue_outList.Add(DataQueue_out1);
            DataQueue_outList.Add(DataQueue_out2);
            DataQueue_outList.Add(DataQueue_out3);
            DataQueue_outList.Add(DataQueue_out4);
            DataQueue_outList.Add(DataQueue_out5);
            DataQueue_outList.Add(DataQueue_out6);
            DataQueue_outList.Add(DataQueue_out7);

            myLockforDat.Add(Lock_Dat1);
            myLockforDat.Add(Lock_Dat2);
            myLockforDat.Add(Lock_Dat3);
            myLockforDat.Add(Lock_Dat4);
            myLockforDat.Add(Lock_Dat5);
            myLockforDat.Add(Lock_Dat6);
            myLockforDat.Add(Lock_Dat7);
        }
Ejemplo n.º 11
0
        private void RecvFromClientZK1(object ClientSocket)
        {
            Trace.WriteLine("RecvFromClientZK1!!");
            Socket myClientSocket = (Socket)ClientSocket;

            while (ServerOn && myClientSocket.Connected)
            {
                try
                {
                    byte[] RecvBufZK1 = new byte[4096];

                    int RecvNum = myClientSocket.Receive(RecvBufZK1);

                    if (RecvNum > 0)
                    {
                        Data.dtYK.Rows[0]["数量"] = (int)Data.dtYK.Rows[0]["数量"] + 1;

                        String tempstr       = "";
                        byte[] RecvBufToFile = new byte[RecvNum];
                        for (int i = 0; i < RecvNum; i++)
                        {
                            RecvBufToFile[i] = RecvBufZK1[i];
                            tempstr         += RecvBufZK1[i].ToString("x2");
                        }
                        Trace.WriteLine(tempstr);

                        //        SaveFile.DataQueue_in1.Enqueue(tempstr);

                        SaveFile.DataQueue_out1.Enqueue(RecvBufToFile);

                        if (RecvNum >= 45 && RecvNum < 300)
                        {
                            MyLog.Info("收到遥测数据量:" + RecvNum.ToString());
                            Data.dtYK.Rows[1]["数量"] = (int)Data.dtYK.Rows[1]["数量"] + 1;
                            deal_zk_data(RecvBufZK1, RecvNum);
                        }
                        else
                        {
                            Data.dtYK.Rows[2]["数量"] = (int)Data.dtYK.Rows[2]["数量"] + 1;
                        }
                    }
                    else
                    {
                        Trace.WriteLine("收到数据少于等于0!");
                        break;
                    }
                }
                catch (Exception e)
                {
                    Trace.WriteLine("RecvFromClientZK1 Exception:" + e.Message);
                    if (myClientSocket.Connected)
                    {
                        myClientSocket.Shutdown(SocketShutdown.Both);
                        myClientSocket.Close();
                    }
                    ClientAPP.ClientZK1.IsConnected = false;
                    break;
                }
            }

            if (myClientSocket.Connected)
            {
                Trace.WriteLine("服务器主动关闭socket!");
                myClientSocket.Shutdown(SocketShutdown.Both);
                myClientSocket.Close();
            }

            ClientAPP.ClientZK1.IsConnected = false;
            Trace.WriteLine("leave RecvFromClientZK1!!");
            Data.ServerConnectEvent.Set();
        }
Ejemplo n.º 12
0
        private void RecvFromClientGT(object ClientSocket)
        {
            Trace.WriteLine("RecvFromClientZK1_YC!!");
            Socket myClientSocket = (Socket)ClientSocket;

            while (ServerOn_YC && myClientSocket.Connected)
            {
                try
                {
                    byte[] RecvBufZK1 = new byte[2048];
                    int    RecvNum    = myClientSocket.Receive(RecvBufZK1);
                    if (RecvNum > 0)
                    {
                        String tempstr       = "";
                        byte[] RecvBufToFile = new byte[RecvNum];
                        for (int i = 0; i < RecvNum; i++)
                        {
                            RecvBufToFile[i] = RecvBufZK1[i];
                            tempstr         += RecvBufZK1[i].ToString("x2");
                        }
                        Trace.WriteLine(tempstr);

                        //存储总控发来的
                        //  SaveFile.DataQueue_1.Enqueue(RecvBufZK1);

                        if (RecvNum > 29)
                        {
                            MyLog.Info("收到遥测数据量:" + RecvNum.ToString());
                            //Trace.WriteLine("网络收到数据量" + RecvNum.ToString());
                            deal_zk_data(RecvBufZK1, RecvNum);
                        }
                    }
                    else
                    {
                        Trace.WriteLine("收到数据少于等于0!");
                        break;
                    }
                }
                catch (Exception e)
                {
                    Trace.WriteLine("RecvFromClientZK_YC Exception:" + e.Message);

                    if (myClientSocket.Connected)
                    {
                        myClientSocket.Shutdown(SocketShutdown.Both);
                        myClientSocket.Close();
                    }
                    ClientAPP.ClientZK1_YC.IsConnected = false;

                    break;
                }
            }

            if (myClientSocket.Connected)
            {
                Trace.WriteLine("服务器主动关闭socket!");
                myClientSocket.Shutdown(SocketShutdown.Both);
                myClientSocket.Close();
            }

            ClientAPP.ClientZK1_YC.IsConnected = false;
            Trace.WriteLine("leave Server YC!!");
            Data.ServerConnectEvent2.Set();
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 收到总控发来的网络数据包,解析并推入对应的队列中
        /// </summary>
        /// <param name="data"></param>
        public void deal_zk_data(byte[] data, int RecvNum)
        {
            byte[] DealData = new byte[RecvNum];//收到的实际数组,data后面可能包含0?
            Trace.WriteLine("收到数据量" + RecvNum.ToString());

            Array.Copy(data, DealData, RecvNum);

            string printstr = null;

            for (int i = 0; i < RecvNum; i++)
            {
                printstr += DealData[i].ToString("x2");
            }
            Trace.WriteLine("1111-------" + printstr);

            byte[] infoflag = new byte[4];
            infoflag[0] = byte.Parse(DealData[18].ToString());
            infoflag[1] = byte.Parse(DealData[19].ToString());
            infoflag[2] = byte.Parse(DealData[20].ToString());
            infoflag[3] = byte.Parse(DealData[21].ToString());
            string type_str = Encoding.ASCII.GetString(infoflag);

            Trace.WriteLine("type_str is :" + type_str);

            MyLog.Info("收到总控--:" + type_str + "数据量:" + RecvNum.ToString() + "内容:" + printstr);

            switch (type_str)
            {
            case "UCLK":    //校时信息
                //settime
                //########
                byte[] timedata = new byte[23];
                Array.Copy(data, 29, timedata, 0, 23);
                Function.Set_Time(timedata);
                break;

            case "MASG":    //主备当班
                            // Encoding.ASCII.GetString(RecvBufZK2, 0, RecvNum)
                            //解析判断
                MyLog.Info(Encoding.ASCII.GetString(DealData, 29, RecvNum - 29));
                Console.WriteLine("接受客户端{0}", Encoding.ASCII.GetString(DealData, 29, RecvNum - 29));
                //返回应答信息码
                //service.send(data)
                break;

            case "CCUK":
            case "CCUA":    //总控-->遥控-->USB应答机a(遥控K令及密钥/算法注入)
                DealWithZK2CRT_K(DealData, ref Data.DealCRTa);
                break;

            case "DCUA":    //总控-->遥控-->USB应答机a(遥控注数)
                DealWithZK2CRT_PB(DealData, ref Data.DealCRTa);
                break;

            case "DCUZ":
            case "CCUG":
                //收到对地测控上行遥控数据
                int len = DealData.Length - 45;

                byte[] MsgHead = new byte[16];
                byte[] MsgBody = new byte[len];
                Array.Copy(DealData, 29, MsgHead, 0, 16);
                Array.Copy(DealData, 45, MsgBody, 0, len);

                //遥控注数应答
                byte[] Return_data = new byte[len + 17];    //16head+len(Body),+1Byte retrun code
                MsgHead.CopyTo(Return_data, 0);
                MsgBody.CopyTo(Return_data, 16);
                Return_data[len + 16] = 0x30;

                byte[] CmdType = new byte[4];
                CmdType[0] = byte.Parse(MsgBody[0].ToString());
                CmdType[1] = byte.Parse(MsgBody[1].ToString());
                CmdType[2] = byte.Parse(MsgBody[2].ToString());
                CmdType[3] = byte.Parse(MsgBody[3].ToString());
                string tempCmdTypeStr = Encoding.ASCII.GetString(CmdType);
                if (tempCmdTypeStr != "0003")
                {
                    Return_data[len + 16] = 0x31;
                }
                byte[] Return_Send = Function.Make_tozk_frame(Data.Data_Flag_Real, Data.InfoFlag_KACK, Return_data);
                Data.DataQueue_ZK_ACK.Enqueue(Return_Send);

                break;

            default:

                break;
            }
        }
Ejemplo n.º 14
0
 void DealCRT_Off(ref Data.CRT_STRUCT myCRT)
 {
     myCRT.LedOff();
     MyLog.Info("无法连接--" + myCRT.CRTName);
 }
Ejemplo n.º 15
0
 void DealCRT_On(ref Data.CRT_STRUCT myCRT)
 {
     myCRT.LedOn();
     MyLog.Info("连接成功--" + myCRT.CRTName);
 }