Esempio n. 1
0
        public static byte[] ToBinary(CommandPacket packet)
        {
            string dataText = packet.Pack;
            byte[] dataBin = TextEncoding.GetBytes(dataText);

            StringBuilder binPacket = new StringBuilder();
            binPacket.Append(PacketBinConverter.Prefix);
            binPacket.Append(dataText);
            binPacket.Append(PacketBinConverter.Suffix);
            binPacket.Append(Checksum.Calculate(dataBin).ToString("x2"));

            return TextEncoding.GetBytes(binPacket.ToString());
        }
Esempio n. 2
0
        public void SendCommandAsync(CommandPacket commandPacket, CallBack callBack)
        {
            lock (sync)
            {
                commandPackets.Enqueue(commandPacket);

                if (callBack != null)
                {
                    callBacks.Add(commandPacket, callBack);
                }
            }

            // send now if possible
            SendPacket();
        }
Esempio n. 3
0
        private void SendPacketData(CommandPacket commandPacket)
        {
            var data = PacketBinConverter.ToBinary(commandPacket);

            currentCommandPacket = commandPacket;

            stream.Write(data, 0, data.Length);
        }