void SwapBytesOut(byte[] inp, out byte[] adr0, out byte[] adr1, ModbusConversionType con)
        {
            adr0 = new byte[2];
            adr1 = new byte[2];
            switch (con)
            {
            case ModbusConversionType.SwapBytes:
                adr1[1] = inp[0];
                adr1[0] = inp[1];
                adr0[1] = inp[2];
                adr0[0] = inp[3];
                break;

            case ModbusConversionType.SwapWords:
                adr0[0] = inp[0];
                adr0[1] = inp[1];
                adr1[0] = inp[2];
                adr1[1] = inp[3];
                break;

            case ModbusConversionType.SwapAll:
                adr0[1] = inp[0];
                adr0[0] = inp[1];
                adr1[1] = inp[2];
                adr1[0] = inp[3];
                break;

            default:
                adr1[0] = inp[0];
                adr1[1] = inp[1];
                adr0[0] = inp[2];
                adr0[1] = inp[3];
                break;
            }
        }
        byte[] SwapBytesIn(byte[] adr0, byte[] adr1, ModbusConversionType con)
        {
            byte[] res = new byte[4];
            switch (con)
            {
            case ModbusConversionType.SwapBytes:
                res[0] = adr1[1];
                res[1] = adr1[0];
                res[2] = adr0[1];
                res[3] = adr0[0];
                break;

            case ModbusConversionType.SwapWords:
                res[0] = adr0[0];
                res[1] = adr0[1];
                res[2] = adr1[0];
                res[3] = adr1[1];
                break;

            case ModbusConversionType.SwapAll:
                res[0] = adr0[1];
                res[1] = adr0[0];
                res[2] = adr1[1];
                res[3] = adr1[0];
                break;

            default:
                res[0] = adr1[0];
                res[1] = adr1[1];
                res[2] = adr0[0];
                res[3] = adr0[1];
                break;
            }
            return(res);
        }
示例#3
0
 public ModbusChannelImp(string name, ModbusChannelImp ch)
     : base(name, false, ch.plugin, ch.Type)
 {
     this.modbusStation      = ch.modbusStation;
     this.modbusDataAddress  = ch.modbusDataAddress;
     this.modbusDataType     = ch.modbusDataType;
     this.modbusInternalType = ch.modbusInternalType;
     this.slaveId            = ch.slaveId;
     this.deviceDataType     = ch.deviceDataType;
     this.deviceDataLen      = ch.deviceDataLen;
     this.conversionType     = ch.conversionType;
     this.modbusReadWrite    = ch.modbusReadWrite;
     if (modbusReadWrite == ModbusReadWrite.ReadOnly)
     {
         this.readOnly = true;
     }
     this.BitIndex = ch.BitIndex;
     this.K        = ch.K;
     this.D        = ch.D;
 }
示例#4
0
 public ModbusChannelImp(string name, Plugin plugin, Type type, string modbusStation, ModbusDataTypeEx modbusType, ushort modbusAddress,
                         byte slaveId, ModbusDeviceDataType deviceDataType, ushort deviceDataLen, ModbusConversionType conversionType, ModbusReadWrite modbusReadWrite)
     : base(name, false, plugin, type)
 {
     this.modbusStation     = modbusStation;
     this.modbusDataAddress = modbusAddress;
     this.modbusDataType    = modbusType;
     if (type == typeof(int))
     {
         modbusInternalType = ModbusFs2InternalType.Int32;
     }
     else if (type == typeof(uint))
     {
         modbusInternalType = ModbusFs2InternalType.UInt32;
     }
     else if (type == typeof(double))
     {
         modbusInternalType = ModbusFs2InternalType.Double;
     }
     else if (type == typeof(bool))
     {
         modbusInternalType = ModbusFs2InternalType.Boolean;
     }
     else if (type == typeof(string))
     {
         modbusInternalType = ModbusFs2InternalType.String;
     }
     this.slaveId         = slaveId;
     this.deviceDataType  = deviceDataType;
     this.deviceDataLen   = deviceDataLen;
     this.conversionType  = conversionType;
     this.modbusReadWrite = modbusReadWrite;
     if (modbusReadWrite == ModbusReadWrite.ReadOnly)
     {
         this.readOnly = true;
     }
     this.BitIndex = 0;
     this.K        = 1.0;
     this.D        = 0.0;
 }
 public static IChannel CreateChannel(string name, Plugin plugin, Type type, string modbusStation, ModbusDataTypeEx modbusType, ushort modbusAddress,
                                      byte slaveId, ModbusDeviceDataType deviceDataType, ushort deviceDataLen, ModbusConversionType conversionType, ModbusReadWrite modbusReadWrite)
 {
     return(new ModbusChannelImp(name, plugin, type, modbusStation, modbusType, modbusAddress, slaveId, deviceDataType, deviceDataLen, conversionType, modbusReadWrite));
 }