[Timeout(10000)] // 10s public void TestReceiver() { DtuClient c = new DtuClient("127.0.0.1", 6066); TranDataReceiver r = new TranDataReceiver(new GprsDtuServer(6066)); r.Start(); c.Connect(20120049, "18900000000", "192.168.1.222"); c.OnReceived = (buff, len) => { Thread.Sleep(500); var msg = @"FA 2A 0C 00 01 74 01 FF 00 00 02 63 00 39 30 38 56 7A 28 65 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 63 00 39 30 38 56 7A 28 65 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 63 00 39 30 B8 70 80 28 65 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 63 00 39 30 B8 70 80 28 65 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 63 00 39 30 60 BA 01 29 65 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 63 00 39 30 60 BA 01 29 65 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 63 00 39 30 00 28 1C 29 65 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 63 00 39 30 00 28 1C 29 65 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 63 00 39 30 30 13 B0 29 65 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 63 00 39 30 30 13 B0 29 65 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 63 00 39 30 C0 E3 30 2A 65 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 63 00 39 30 C0 E3 30 2A 65 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 16 AF"; log.DebugFormat("[Client] Sending data..."); c.Send(ValueHelper.StrToToHexByte(msg)); }; // heartbeat, 激励 c.Send(new HeartBeatTranMsg(20120049, 0).Marshall()); int receivedCnt = 0; r.OnTranMsgReceived += (TranMsgType type, TranMsg msg) => { TranMsg m2 = msg; log.DebugFormat("[Server] Msg Received: id={3}, type={0},len={1}, pkg={2}", type, msg.LoadSize, msg.PackageCount, msg.ID); if (msg.ID == 0) { Assert.AreEqual(TranMsgType.HeartBeat, type); } else { Assert.AreEqual(TranMsgType.Dac, type); } receivedCnt++; }; while (receivedCnt <= 5) { Thread.Sleep(10); } c.Close(); log.DebugFormat("Test Done."); Assert.IsTrue(true); }
public void TestAtCommandExecutor() { GprsDtuServer _server = new GprsDtuServer(5055); _server.Start(); string dtu = "12345678"; Thread.Sleep(500); if (client.Connect(12345678, "22222222", "127.0.0.2")) { Console.WriteLine("Connected"); } else { Console.WriteLine("ERROR"); } client.OnReceived = (msg, len) => client.Send("OK"); Thread.Sleep(500); GprsDtuConnection conn = (GprsDtuConnection)_server.GetConnection(new DtuNode { DtuCode = dtu }); ATCommand cmd = new EnterConfig(); CommandExecutor ce = new CommandExecutor(); Assert.IsNotNull(conn); if (conn != null && conn.IsAvaliable()) { ATCommandResult r = ce.Execute(conn, cmd); Assert.IsTrue(r.IsOK); } if (conn != null && conn.IsAvaliable()) { cmd = new SetPort("{'port':5008}"); ATCommandResult r = ce.Execute(conn, cmd); Assert.IsTrue(r.IsOK); } if (conn != null && conn.IsAvaliable()) { cmd = new SetPort("{'port':5009"); ATCommandResult r = ce.Execute(conn, cmd); Assert.IsTrue(r.IsOK); } }
public static void OnMsg(byte[] buff, int len) { Console.WriteLine("< {0}", ValueHelper.BytesToHexStr(buff, 0, len)); Console.WriteLine("> {0}", AutoReply); client.Send(AutoReply); }