public void CommandFormatter_Common() { var command = new PrintStringCommand("123"); var formatter = new CommandFormatter(command); var result = formatter.CreatePackage(); }
public void CommandFormatter_CreatePackage() { var command = new PrintStringCommand("123"); var commandPwd = new CommandPasswordWrapper(command, new byte[] { 0x00, 0x00 }); var bufferCommand = new AddBufferCommand(commandPwd, 0xFA, 0x03); var formatter = new CommandFormatter(bufferCommand); var result = formatter.CreatePackage(); }
public async Task <ActionResult> Get(int id) { var command = new RequestStatusCommand(); var commandPwd = new CommandPasswordWrapper(command, new byte[] { 0x00, 0x00 }); var bufferCommand = new AddBufferCommand(commandPwd, 0x01, 0x01); var formatter = new CommandFormatter(bufferCommand); var buffer = formatter.CreatePackage(); await _transceiver.SendPackage(buffer); return(Ok()); }
public void CommandFormatter_CRC() { //var buffer = new byte[] { 0x2b, 0xc1, 0x00, 0x15, 0x00,0x00, 0x4c, 0x31, 0x32, 0x33 }; var buffer = new byte[] { 0x1b, 0xc1, 0x00, 0x0d, 0x00, 0x00, 0x4c, 0x31, 0x32, 0x33 }; var result = CommandFormatter.CalculateCRC8(buffer); Assert.AreEqual(0x4C, result); buffer = new byte[] { 0x2d, 0xc1, 0x01, 0x16, 0x00, 0x00, 0x3f }; result = CommandFormatter.CalculateCRC8(buffer); Assert.AreEqual(0x4A, result); }
/// <summary> /// Gets the command model. /// </summary> /// <param name="state">The state.</param> /// <returns></returns> internal TCommandModel GetCommandModel(StateObjectModel <Socket> state) { var commandModel = default(TCommandModel); try { commandModel = IgnoreFormatter ? state.Buffer as TCommandModel : CommandFormatter.Deserialize(Compressor.Decompress(state.Buffer)); } catch (Exception e) { Logger?.Log(new LogModel { Time = DateTime.Now, Message = $"反序列化失敗囉, 物件名稱 : {ToString( )}, 例外訊息 : {e.Message}" }); } return(commandModel); }
/// <summary> /// Sends the commandModel with specified handler. /// </summary> /// <param name="handler">The handler.</param> /// <param name="commandModel">The command model.</param> protected virtual void Send(Socket handler, TCommandModel commandModel) { try { var bytestoSend = IgnoreFormatter ? commandModel as byte[] : CommandFormatter.Serialize(commandModel); var compressedbytes = Compressor.Compress(bytestoSend); var bytesToSendWithSize = CreateBytesToSendWithSize(compressedbytes); handler.BeginSend(bytesToSendWithSize, 0, bytesToSendWithSize.Length, 0, SendCallback, handler); } catch (Exception e) { Logger?.Log(new LogModel { Time = DateTime.Now, Message = $"傳送資料失敗, 物件名稱 : {ToString( )}, 例外訊息 : {e.Message}" }); throw; } }