/// <summary> /// Read input status Rely /// Function:0x02 /// </summary> /// <param name="address">10001~19999</param> /// <param name="count"></param> /// <returns></returns> private byte[] readInStatusRely(int address, int count) { bool[] boolDate = new bool[count]; byte[] dataBuffer; byte[] relyBuffer; //addtion SlaveId,Function. for (int i = 0; i < count; i++) { var addressString = string.Format("{0:D5}", address + i + 1 + 10000); if (_mapping.Find(addressString)) { boolDate[i] = _mapping.GetValue(addressString)[0]; } else { return(errorRely(FunctionCode.ReadInputStatus, ErrorCode.LllegalDataAddress)); }; } dataBuffer = NetConvert.BoolstoBytes(boolDate); relyBuffer = new byte[dataBuffer.Length + 3]; relyBuffer[0] = (byte)_salveId; relyBuffer[1] = (byte)FunctionCode.ReadInputStatus; relyBuffer[2] = (byte)dataBuffer.Length; Array.Copy(dataBuffer, 0, relyBuffer, 3, dataBuffer.Length); return(relyBuffer); }
protected override byte[] getWriteMulCoilHeader(byte slaveID, ushort startAddress, bool[] value) { byte[] datas = NetConvert.BoolstoBytes(value); byte[] sendBytes = new byte[13 + datas.Length]; sendBytes[5] = (byte)(7 + datas.Length); //后续报文字节数 sendBytes[6] = slaveID; sendBytes[7] = (byte)FunctionCode.ForceMulCoil; byte[] addressBytes = BitConverter.GetBytes(startAddress - 1); sendBytes[8] = addressBytes[1]; //高位在前 sendBytes[9] = addressBytes[0]; //低位在后 byte[] CountBytes = BitConverter.GetBytes((ushort)value.Length); sendBytes[10] = CountBytes[1]; sendBytes[11] = CountBytes[0]; sendBytes[12] = (byte)datas.Length; Array.Copy(datas, 0, sendBytes, 13, datas.Length); return(sendBytes); }
protected override byte[] getWriteMulCoilHeader(byte slaveID, ushort startAddress, bool[] value) { byte[] datas = NetConvert.BoolstoBytes(value); byte[] sendBytes = new byte[9 + datas.Length]; sendBytes[0] = slaveID; sendBytes[1] = (byte)FunctionCode.ForceMulCoil; byte[] addressBytes = BitConverter.GetBytes(startAddress - 1); sendBytes[2] = addressBytes[1]; //高位在前 sendBytes[3] = addressBytes[0]; //低位在后 byte[] CountBytes = BitConverter.GetBytes((ushort)value.Length); sendBytes[4] = CountBytes[1]; sendBytes[5] = CountBytes[0]; sendBytes[6] = (byte)datas.Length; Array.Copy(datas, 0, sendBytes, 7, datas.Length); byte[] CRCBytes = Utility.CalculateCrc(sendBytes, sendBytes.Length - 2); Array.Copy(CRCBytes, 0, sendBytes, sendBytes.Length - 3, 2); return(sendBytes); }