Ejemplo n.º 1
0
        protected bool?SendParam(CommandTuple cmdTuple, CommandParam cmdParam, bool ack = true)
        {
            // ReSharper disable once InconsistentNaming
            string ACK = ack ? "SEND_WITH_ACK" : "SEND_NO_ACK";
            // ReSharper disable once InconsistentNaming
            string DataACK = ack ? "DATA_WITH_ACK" : "DATA_NO_ACK";
            // ReSharper disable once StringLiteralTypo
            string fmt = "<BBBIBBH" + cmdParam.Format();

            SequenceCounter[ACK] = (SequenceCounter[ACK] + 1) % 256;

            Command cmd = new Command();

            cmd.InsertData((byte)DataTypesByName[DataACK]);
            cmd.InsertData((byte)BufferIds[ACK]);
            cmd.InsertData((byte)SequenceCounter[ACK]);
            cmd.InsertData((uint)StructConverter.PacketSize(fmt));

            cmd.InsertTuple(cmdTuple);
            cmd.InsertParam(cmdParam);

            if (ack)
            {
                return(SendCommandAck(cmd.Export(fmt), SequenceCounter["SEND_WITH_ACK"]));
            }

            SendCommandNoAck(cmd.Export(fmt));
            return(null);
        }
Ejemplo n.º 2
0
        // ReSharper disable once IdentifierTypo
        protected bool SendSinglePcmd(CommandTuple cmdTuple, CommandParam cmdParam)
        {
            SequenceCounter["SEND_NO_ACK"] = (SequenceCounter["SEND_NO_ACK"] + 1) % 256;
            // ReSharper disable once StringLiteralTypo
            string fmt = "<BBBIBBH" + cmdParam.Format();

            Command cmd = new Command();

            cmd.InsertData((byte)DataTypesByName["DATA_NO_ACK"]);
            cmd.InsertData((byte)BufferIds["SEND_NO_ACK"]);
            cmd.InsertData((byte)SequenceCounter["SEND_NO_ACK"]);
            cmd.InsertData((uint)StructConverter.PacketSize(fmt));

            cmd.InsertTuple(cmdTuple);
            cmd.InsertParam(cmdParam);

            return(SafeSend(cmd.Export(fmt)));
        }