Esempio n. 1
0
        protected byte[] _PollingTo(Channel ch, Device dv, DataBlock db)
        {
            IODriverDataTypes dataType     = (IODriverDataTypes)Enum.Parse(typeof(IODriverDataTypes), db.DataType);
            LSDomainTypes     lsDomainType = (LSDomainTypes)Enum.Parse(typeof(LSDomainTypes), db.MemoryType);
            int baseAddress = db.StartAddress;

            switch (dataType)
            {
            case IODriverDataTypes.BitOnByte:
                baseAddress = ((db.StartAddress >= 2) ? (db.StartAddress / 2) : 0) * 2;
                break;

            case IODriverDataTypes.BitOnWord:
                baseAddress = db.StartAddress * 2;
                break;

            case IODriverDataTypes.Bit:
                baseAddress = ((db.StartAddress >= 16) ? (db.StartAddress / 16) : 0) * 2;
                break;

            case IODriverDataTypes.Byte:
                baseAddress = db.StartAddress;
                break;

            case IODriverDataTypes.Short:
            case IODriverDataTypes.UShort:
                baseAddress = db.StartAddress * 2;
                break;

            case IODriverDataTypes.Int:
            case IODriverDataTypes.UInt:
                baseAddress = db.StartAddress * 4;
                break;

            case IODriverDataTypes.Long:
            case IODriverDataTypes.ULong:
                baseAddress = db.StartAddress * 8;
                break;

            case IODriverDataTypes.Float:
                baseAddress = db.StartAddress * 4;
                break;

            case IODriverDataTypes.Double:
                baseAddress = db.StartAddress * 8;
                break;
            }
            string originAddress  = "%" + LSNetBase.GetDomainType(lsDomainType) + LSNetBase.GetAddress(dataType, lsDomainType, ch.Rack, ch.Slot, db.StartAddress);
            string requestAddress = "%" + LSNetBase.GetDomainType(lsDomainType) + LSNetBase.GetAddress(IODriverDataTypes.Byte, lsDomainType, ch.Rack, ch.Slot, baseAddress);
            ushort count          = LSNetBase.GetCount(dataType, db.StartAddress, db.Length);
            var    FullPacket     = _WriteTo(new LSRequestMessage(Guid.NewGuid(), LSRequestTyes.Consecutive, dataType, originAddress, (byte)dv.SlaveId, requestAddress, count));

            return(FullPacket);
        }
Esempio n. 2
0
        protected byte[] _PollingTo(Channel ch, Device dv, DataBlock db)
        {
            IODriverDataTypes dataType     = (IODriverDataTypes)Enum.Parse(typeof(IODriverDataTypes), db.DataType);
            LSDomainTypes     lsDomainType = (LSDomainTypes)Enum.Parse(typeof(LSDomainTypes), db.MemoryType);

            int baseAddress = db.StartAddress;

            switch (dataType)
            {
            case IODriverDataTypes.BitOnByte:
                baseAddress = ((db.StartAddress >= 2) ? (db.StartAddress / 2) : 0) * 2;
                break;

            case IODriverDataTypes.BitOnWord:
                baseAddress = db.StartAddress * 2;
                break;

            case IODriverDataTypes.Bit:
                baseAddress = ((db.StartAddress >= 16) ? (db.StartAddress / 16) : 0) * 2;
                break;

            default:
                baseAddress = db.StartAddress;
                break;
            }
            string originAddress = "%" + LSNetBase.GetDomainType(lsDomainType) + LSNetBase.GetAddress(dataType, lsDomainType, ch.Rack, ch.Slot, db.StartAddress);
            string str           = "%" + LSNetBase.GetDomainType(lsDomainType);
            ushort requestCount  = db.Length;

            if (dataType == IODriverDataTypes.Bit || dataType - 177 <= (IODriverDataTypes)1)
            {
                str         += LSNetBase.GetAddress(IODriverDataTypes.Byte, lsDomainType, ch.Rack, ch.Slot, baseAddress);
                requestCount = LSNetBase.GetCount(dataType, db.StartAddress, db.Length);
            }
            else
            {
                str += LSNetBase.GetAddress(dataType, lsDomainType, ch.Rack, ch.Slot, baseAddress);
            }
            byte[] frame = _GetBytes(new LSRequestMessage(Guid.NewGuid(), LSRequestTyes.Consecutive, dataType, originAddress, (byte)dv.SlaveId, str, requestCount));

            return(frame);
        }