Пример #1
0
 private void btInit_Click(object sender, EventArgs e)
 {
     if (IsRuning == false)
     {
         if (!(cbCOM.Text == InitInfo[0] && cbBPS.Text == InitInfo[1] && tbIn.Text == InitInfo[2] && tbOut.Text == InitInfo[3]))
         {
             InitInfo[0] = cbCOM.Text;
             InitInfo[1] = cbBPS.Text;
             InitInfo[2] = tbIn.Text;
             InitInfo[3] = tbOut.Text;
             try
             {
                 ReInit();
             }
             catch (IOException ee)
             {
                 MessageBox.Show("指定端口不存在");
                 return;
             }
         }
         ZProtocolProcessObj.Start();
         ToRun();
     }
     else
     {
         ZProtocolProcessObj.Stop();
         if (SerialIOSwitchObj != null)
         {
             SerialIOSwitchObj.Close();
         }
         ToStop();
     }
 }
 private static void TestZProtocolProcess()
 {
     RS232 rs232 = new RS232("COM4", 115200);
     rs232.Open();
     ZProtocolProcess zProtocolProcess = new ZProtocolProcess(rs232);
     zProtocolProcess.Start();
     Console.WriteLine("Ready...");
     //while (true)
     //{
     //    Console.ReadLine();
     //    zProtocolProcess.WriteFrame(1, 2, 0);
     //    zProtocolProcess.AddPackage(0xc0, 0xff, new byte[12]);
     //    zProtocolProcess.Send();
     //    Console.WriteLine("Send");
     //}
     byte[] bs = new byte[12];
     for (int i = 0; i < 12; i++)
     {
         bs[i] = (byte)i;
     }
     Console.ReadLine();
     for (int i = 0; i < 100; i++)
     {
         zProtocolProcess.WriteFrame((byte)i, (byte)(i + 1), 0);
         zProtocolProcess.AddBlock((byte)(i + 100), 0xff, bs);
         zProtocolProcess.Send();
         Console.WriteLine("Send");
         Thread.Sleep(15);
     }
 }