Exemple #1
0
        private void GetBool(byte[] data, int byteNum, ModbusVariable <bool> variable)
        {
            int bitNum = variable.Address.BitNum > 7 ? variable.Address.BitNum - 8 : variable.Address.BitNum;

            if (byteNum % 2 == 0)
            {
                ++byteNum;
            }
            else
            {
                --byteNum;
            }
            bool value = (data[byteNum] & (1 << bitNum)) != 0;

            if (value)
            {
                if (!variable.Value)
                {
                    data[byteNum] &= (byte)~(1 << bitNum);
                }
            }
            else
            {
                if (variable.Value)
                {
                    data[byteNum] |= (byte)(1 << bitNum);
                }
            }
        }
Exemple #2
0
        private void SetBool(byte[] data, int byteNum, ModbusVariable <bool> variable)
        {
            int bitNum = variable.Address.BitNum > 7 ? variable.Address.BitNum - 8 : variable.Address.BitNum;

            if (byteNum % 2 == 0)
            {
                ++byteNum;
            }
            else
            {
                --byteNum;
            }
            bool value = (data[byteNum] & (1 << bitNum)) != 0;

            variable.SetValue(value);
        }
Exemple #3
0
 private void SetString(byte[] data, int byteNum, ModbusVariable <string> variable)
 {
     variable.SetValue(Encoding.ASCII.GetString(data.GetRange(byteNum, variable.Size)));
 }
Exemple #4
0
 private void SetDouble(byte[] data, int byteNum, ModbusVariable <double> variable)
 {
     variable.SetValue(BitConverter.ToDouble(data.GetRange(byteNum, variable.Size), 0));
 }
Exemple #5
0
 private void SetFloat(byte[] data, int byteNum, ModbusVariable <float> variable)
 {
     variable.SetValue(BitConverter.ToSingle(data.GetRange(byteNum, variable.Size), 0));
 }
Exemple #6
0
 private void SetULong(byte[] data, int byteNum, ModbusVariable <ulong> variable)
 {
     variable.SetValue(BitConverter.ToUInt64(data.GetRange(byteNum, variable.Size), 0));
 }
Exemple #7
0
 private void SetInt(byte[] data, int byteNum, ModbusVariable <int> variable)
 {
     variable.SetValue(BitConverter.ToInt32(data.GetRange(byteNum, variable.Size), 0));
 }
Exemple #8
0
 private void SetUShort(byte[] data, int byteNum, ModbusVariable <ushort> variable)
 {
     variable.SetValue(BitConverter.ToUInt16(data.GetRange(byteNum, variable.Size), 0));
 }
Exemple #9
0
 private void SetByte(byte[] data, int byteNum, ModbusVariable <byte> variable)
 {
     variable.SetValue(data[byteNum]);
 }
Exemple #10
0
 private void GetString(byte[] data, int byteNum, ModbusVariable <string> variable)
 {
     byte[] temp = ReverseData(Encoding.ASCII.GetBytes(variable.Value));
     Array.Copy(temp, 0, data, byteNum, temp.Length);
 }
Exemple #11
0
 private void GetDouble(byte[] data, int byteNum, ModbusVariable <double> variable)
 {
     byte[] temp = ReverseData(BitConverter.GetBytes(variable.Value));
     Array.Copy(temp, 0, data, byteNum, temp.Length);
 }
Exemple #12
0
 private void GetByte(byte[] data, int byteNum, ModbusVariable <byte> variable)
 {
     data[byteNum] = variable.Value;
 }