/// <summary> /// 结构型消息 /// </summary> /// <param name="msgStruct"></param> public ProvideGoods(PLCStruct.ProvideGoods msgStruct) { byte[] msg = msgStruct.ToByteArray(); if (msg.Length != 0x0d) { CommandNo = 1; LineNo = 0; TableNo = 0; Index = 0; BlockNo = 0; } else { Span <byte> span = msg; CommandNo = msg[3]; LineNo = msg[4]; TableNo = msg[5]; var temp = span.Slice(6, 4); temp.Reverse(); Index = BitConverter.ToInt32(temp.ToArray(), 0); BlockNo = msg[11]; Msg = msg; } }
/// <summary> /// 发送消息 /// </summary> /// <param name="byteBuffer"></param> /// <returns></returns> public async Task SendMsg(PLCStruct.ProvideGoods provideGoods) { await client.WriteAndFlushAsync(provideGoods.ToByteBuffer()); }