protected override void EncodeWrite(byte[] request, string uid, string address, string value) { //uid request[0] = Convert.ToByte(uid); //Body //function code ModuleConfig.ParseEntity(address, false, out ushort address_int16, out request[m_dataBodyOffset], out byte entity_type); //address byte[] address_byte = BitConverter.GetBytes(IPAddress.HostToNetworkOrder((Int16)(address_int16))); request[m_dataBodyOffset + 1] = address_byte[0]; request[m_dataBodyOffset + 2] = address_byte[1]; //value UInt16 value_int = (UInt16)Convert.ToInt32(value); if (entity_type == '0' && value_int == 1) { request[m_dataBodyOffset + 3] = 0xFF; request[m_dataBodyOffset + 4] = 0x00; } else { byte[] val_byte = BitConverter.GetBytes(IPAddress.HostToNetworkOrder((Int16)value_int)); request[m_dataBodyOffset + 3] = val_byte[0]; request[m_dataBodyOffset + 4] = val_byte[1]; } if (GetCRC(request, 6, out UInt16 crc)) { byte[] crc_byte = BitConverter.GetBytes(crc); request[m_dataBodyOffset + 5] = crc_byte[0]; request[m_dataBodyOffset + 6] = crc_byte[1]; } }
protected override void EncodeWrite(byte[] request, string uid, string address, string value) { //MBAP //transaction id 2 bytes request[0] = 0; request[1] = 0; //protocol id 2 bytes request[2] = 0; request[3] = 0; //length byte[] len_byte = BitConverter.GetBytes(IPAddress.HostToNetworkOrder((Int16)6)); request[4] = len_byte[0]; request[5] = len_byte[1]; //uid request[6] = Convert.ToByte(uid); //Body //function code ModuleConfig.ParseEntity(address, false, out ushort address_int16, out request[m_dataBodyOffset], out byte entity_type); //address byte[] address_byte = BitConverter.GetBytes(IPAddress.HostToNetworkOrder((Int16)(address_int16))); request[m_dataBodyOffset + 1] = address_byte[0]; request[m_dataBodyOffset + 2] = address_byte[1]; //value UInt16 value_int = (UInt16)Convert.ToInt32(value); if (entity_type == '0' && value_int == 1) { request[m_dataBodyOffset + 3] = 0xFF; request[m_dataBodyOffset + 4] = 0x00; } else { byte[] val_byte = BitConverter.GetBytes(IPAddress.HostToNetworkOrder((Int16)value_int)); request[m_dataBodyOffset + 3] = val_byte[0]; request[m_dataBodyOffset + 4] = val_byte[1]; } }