Exemplo n.º 1
0
        private void OnDataReceived(IAsyncResult asyn)
        {
            SocketPacket socketPacket = (SocketPacket)asyn.AsyncState;
            //int byteCount = socketPacket.thisSocket.EndReceive(asyn);
            var byteArray = socketPacket.dataBuffer.Where(x => x != 0x00).ToArray();

            if (_stage == 1)
            {
                var assert = new byte[] { 0x05 };
                Assert.AreEqual(assert[0], byteArray[0]);
                const string str             = "<STX>000000  td3W0       <FS>9V00000000     <FS>60<FS>VA5.00.03WV02.70.10 V04.00.19 0  0T  00 000     00000002K0111000100005K000002220060000000000000000000000000000000<FS><FS><ETX>";
                byte[]       rawMessageBytes = _baseMessageHelper.BuildMessageBytes(str); // Bulid byte

                _clientSocket.Send(rawMessageBytes);
                _stage = 2;
            }
            else if (_stage == 2)
            {
                var assert = new byte[] { 0x02 };
                Assert.AreEqual(assert, byteArray[0]);
                _clientSocket.Send(new byte[] { 0x06 });
                _stage = 3;
            }
            else if (_stage == 3)
            {
                var assert = new byte[] { 0x04 };
                Assert.AreEqual(assert, byteArray[0]);
                _clientSocket.Send(new byte[] { 0x04 });
                _stage = 4;
            }
        }
Exemplo n.º 2
0
 public void TestSendConfigMessage()
 {
     try
     {
         if (_pfnCallBack == null)
         {
             _pfnCallBack = OnDataReceived;
         }
         _clientSocket = Connection();
         SocketPacket socketPacket = new SocketPacket();
         socketPacket.thisSocket = Connection();
         _clientSocket.BeginReceive(socketPacket.dataBuffer, 0, socketPacket.dataBuffer.Length, SocketFlags.None, _pfnCallBack, socketPacket);
         _stage = 1;
     }
     catch (SocketException ex)
     {
     }
 }