using Mina.Core.Buffer; using Mina.Core.Session; using Mina.Filter.Codec; using Mina.Filter.Codec.Demux; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DM_Weight.Port { public class MyMinaEncoder : IMessageEncoder { private short accumulate = 0; public void Encode(IoSession session, MyBaseMessage message, IProtocolEncoderOutput output) { IoBuffer input = IoBuffer.Allocate(12); input.AutoExpand = true; input.PutInt16(accumulate); input.PutInt16(0); input.PutInt16(6); input.Put((byte)message.addr); // 功能码 input.Put((byte)message.functionCode); // 锁号 input.PutInt16(message.lockNo); // 开锁时间 input.PutInt16(message.delay); input.Flip(); accumulate += 1; session.Write(input); } public void Encode(IoSession session, object message, IProtocolEncoderOutput output) { IoBuffer input = IoBuffer.Allocate(12); input.AutoExpand = true; if (message is MyBaseMessage) { var m = message as MyBaseMessage; input.PutInt16(accumulate); input.PutInt16(0); input.PutInt16(6); input.Put((byte)m.addr); // 功能码 input.Put((byte)m.functionCode); // 锁号 input.PutInt16(m.lockNo); // 开锁时间 input.PutInt16(m.delay); input.Flip(); accumulate += 1; } session.Write(input); } } }