Пример #1
0
 private void ViaComm_Click(object sender, EventArgs e)
 {
     if (DestNodeName.Text != "")
     {
         byte[] cmd = Pack();
         if (cmd.Length == 0)
         {
             return;
         }
         byte[] Serialcmd = SourceDataClass.CommPackage(171, cmd);
         if (MainForm.pMainForm.mapdoc.WriteMSPCommand(Serialcmd))
         {
             BackText.Clear();
             Commparelabel.Text = "---";
             MainForm.pMainForm.mapdoc.MSPCmdFile.OpenFile(MainForm.pMainForm.SerialCmdPathInfo);
             MainForm.pMainForm.mapdoc.MSPCmdFile.BinaryWrite(Serialcmd);
             MainForm.pMainForm.mapdoc.MSPCmdFile.close();
             MessageBox.Show("命令已发送!");
         }
     }
     else
     {
         MessageBox.Show("请选择一个正确的目的地址!");
     }
 }
Пример #2
0
 private void ViaSerial_Click(object sender, EventArgs e)
 {
     if (CmdList.Items.Count > 0)
     {
         if (SourceNodeBox.Text != "")
         {
             byte[] cmd = pack();
             if (cmd.Length > 1024)
             {
                 MessageBox.Show("命令过长,请删除部分命令!");
                 return;
             }
             byte[] Serialcmd = SourceDataClass.CommPackage(171, cmd);
             if (MainForm.pMainForm.mapdoc.WriteMSPCommand(Serialcmd))
             {
                 MainForm.pMainForm.mapdoc.MSPCmdFile.OpenFile(MainForm.pMainForm.SerialCmdPathInfo);
                 MainForm.pMainForm.mapdoc.MSPCmdFile.BinaryWrite(Serialcmd);
                 MainForm.pMainForm.mapdoc.MSPCmdFile.close();
                 //Clear();
                 RefreshList();
                 MessageBox.Show("命令已发送!");
             }
         }
         else
         {
             MessageBox.Show("请选择一个正确的源地址!");
         }
     }
 }
Пример #3
0
        private void TranslateWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            List <FileInfo>  lf     = (List <FileInfo>)e.Argument;
            BackgroundWorker worker = sender as BackgroundWorker;

            for (int i = 0; i < lf.Count; i++)
            {
                using (BinaryReader br = new BinaryReader(lf[i].OpenRead()))
                {
                    byte[] b = br.ReadBytes((int)lf[i].Length);

                    try
                    {
                        byte[] outcmd     = SourceDataClass.CommPackage(170, b);
                        string timestring = lf[i].Name.Replace("NetRecvData", "");
                        timestring = timestring.TrimEnd('.', 'd', 'a', 't');
                        string filename = ADPathInfo.FullName + "\\MSPPackageData" + timestring + ".dat";
                        using (BinaryWriter bw = new BinaryWriter(File.Open(filename, FileMode.OpenOrCreate)))
                        {
                            bw.Write(outcmd);
                        }
                        worker.ReportProgress(i * 100 / (lf.Count - 1));
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                        worker.ReportProgress(i * 100 / (lf.Count - 1));
                        continue;
                    }
                }
            }
        }
Пример #4
0
        private void SendMsg()
        {
            try
            {
                int[] b        = new int[1];
                int   blocklen = 34 + 6 + 20;//
                SourceDataClass.InitForPack(blocklen);

                b[0] = 1;
                SourceDataClass.OutPutIntBit(b, 6);
                BitArray blockba = new BitArray(blocklen);
                b[0] = ComListForm.PackageIndex;
                ComListForm.PackageIndex++;
                SourceDataClass.OutPutIntBit(b, 10);
                b[0] = blocklen - 6;//仅包括块头定义,块长度不包括块数长度
                SourceDataClass.OutPutIntBit(b, 12);
                b[0] = linkid;
                SourceDataClass.OutPutIntBit(b, 6);
                currentid = int.Parse(testid[idindex]);
                idindex++;
                if (idindex == testid.Length)
                {
                    idindex = 0;
                }
                b[0] = currentid;
                SourceDataClass.OutPutIntBit(b, 6);


                if (command == "获取节点信息")
                {
                    b[0] = 103;
                    SourceDataClass.OutPutIntBit(b, 8);
                    b[0] = 20;
                    SourceDataClass.OutPutIntBit(b, 12);
                }
                else if (command == "获取路由信息")
                {
                    b[0] = 113;
                    SourceDataClass.OutPutIntBit(b, 8);
                    b[0] = 20;
                    SourceDataClass.OutPutIntBit(b, 12);
                }
                else if (command == "获取设备数据")
                {
                    b[0] = 115;
                    SourceDataClass.OutPutIntBit(b, 8);
                    b[0] = 28;
                    SourceDataClass.OutPutIntBit(b, 12);
                    b[0] = 2;
                    SourceDataClass.OutPutIntBit(b, 8);
                    blocklen += 8;
                }
                else if (command == "获取邻节点信息")
                {
                    b[0] = 111;
                    SourceDataClass.OutPutIntBit(b, 8);
                    b[0] = 20;
                    SourceDataClass.OutPutIntBit(b, 12);
                }
                else if (command == "获取网络简表")
                {
                    b[0] = 109;
                    SourceDataClass.OutPutIntBit(b, 8);
                    b[0] = 20;
                    SourceDataClass.OutPutIntBit(b, 12);
                }
                else if (command == "获取节点信息表")
                {
                    b[0] = 105;
                    SourceDataClass.OutPutIntBit(b, 8);
                    b[0] = 20;
                    SourceDataClass.OutPutIntBit(b, 12);
                }
                else if (command == "获取网络表")
                {
                    b[0] = 107;
                    SourceDataClass.OutPutIntBit(b, 8);
                    b[0] = 20;
                    SourceDataClass.OutPutIntBit(b, 12);
                }
                else if (command == "回环测试")
                {
                    b[0] = 101;
                    SourceDataClass.OutPutIntBit(b, 8);
                    b[0] = 20;
                    SourceDataClass.OutPutIntBit(b, 12);
                }
                else if (command == "获取节点状态")
                {
                    b[0] = 119;
                    SourceDataClass.OutPutIntBit(b, 8);
                    b[0] = 20;
                    SourceDataClass.OutPutIntBit(b, 12);
                }
                byte[] cmd = new byte[(int)Math.Ceiling(((double)blocklen) / 8)];
                SourceDataClass.packdata.CopyTo(cmd, 0);
                byte[] Serialcmd = SourceDataClass.CommPackage(171, cmd);
                //BinaryWriter bw = new BinaryWriter(new FileStream("ping.dat", FileMode.Create));
                //bw.Write(cmd);
                //bw.Close();
                if (MainForm.pMainForm.mapdoc.WriteMSPCommand(Serialcmd))
                {
                    MainForm.pMainForm.mapdoc.MSPCmdFile.OpenFile(MainForm.pMainForm.SerialCmdPathInfo);
                    MainForm.pMainForm.mapdoc.MSPCmdFile.BinaryWrite(Serialcmd);
                    MainForm.pMainForm.mapdoc.MSPCmdFile.close();
                    writelog("向节点" + currentid.ToString() + "发送串口命令:" + command);
                    times++;
                    Thread wait = new Thread(waitforans);
                    wait.Start();
                    testwait.Enabled = false;
                }
            }
            catch (Exception ex)
            {
                writelog(ex.Message);
                testwait.Enabled = true;
            }
        }