public void WriteTest()
        {
            byte[] buffer             = Encoding.ASCII.GetBytes("Hello");
            byte[] receivedBytes      = new byte[1024];
            int    receivedBytesCount = 0;

            tcpClientComPort.Write(buffer, 0, buffer.Length);

            Assert.IsTrue(tcpClient.Client.Available == buffer.Length);

            receivedBytesCount = tcpClient.GetStream().Read(receivedBytes, 0, receivedBytes.Length);

            Assert.IsTrue(receivedBytesCount == buffer.Length);
            Assert.AreEqual("Hello", Encoding.ASCII.GetString(receivedBytes, 0, receivedBytesCount));
        }
Example #2
0
 /// <summary>
 /// 启动监视
 /// </summary>
 /// <param name="connectionStateChanged">连接状态改变事件事件委托</param>
 /// <param name="comPort">通讯端口</param>
 public void StartMonitor(EventHandler <ConnectionStateChangedEventArgs> connectionStateChanged, IComPort comPort)
 {
     StartMonitor(() => comPort?.Write(new byte[] { }, 0, 0), comPort, connectionStateChanged);
 }