Exemple #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);
        }
Exemple #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);
        }
Exemple #3
0
        public bool BeginWrite(Channel ch, Device dv, Tag item, string value)
        {
            IODriverDataTypes iODriverDataTypes = (IODriverDataTypes)Enum.Parse(typeof(IODriverDataTypes), item?.DataType);
            string            address           = item.Address;

            switch (iODriverDataTypes)
            {
            case IODriverDataTypes.BitOnByte:
            {
                string text3 = item.Address.Substring(1, 1);
                item.Address.Substring(2, 1);
                string text4 = item.Address.Remove(0, 3);
                int    num3  = 0;
                int    num4  = 0;
                switch (text3)
                {
                case "I":
                case "Q":
                case "U":
                {
                    string[] array4 = text4.Split(new char[1]
                            {
                                '.'
                            }, 4);
                    address = "%" + text3 + "B" + array4[0] + "." + array4[1] + ".";
                    num3    = int.Parse(array4[2]);
                    num4    = int.Parse(array4[3]);
                    break;
                }

                default:
                {
                    string[] array3 = text4.Split(new char[1]
                            {
                                '.'
                            }, 2);
                    address = "%" + text3 + "B";
                    num3    = int.Parse(array3[0]);
                    num4    = int.Parse(array3[1]);
                    break;
                }
                }
                address = $"{address}{(num3 * 8 + num4) / 8}.{num4 % 8}";
                break;
            }

            case IODriverDataTypes.BitOnWord:
            {
                string text = item.Address.Substring(1, 1);
                item.Address.Substring(2, 1);
                string text2 = item.Address.Remove(0, 3);
                int    num   = 0;
                int    num2  = 0;
                switch (text)
                {
                case "I":
                case "Q":
                case "U":
                {
                    string[] array2 = text2.Split(new char[1]
                            {
                                '.'
                            }, 4);
                    address = "%" + text + "B" + array2[0] + "." + array2[1] + ".";
                    num     = int.Parse(array2[2]);
                    num2    = int.Parse(array2[3]);
                    break;
                }

                default:
                {
                    string[] array = text2.Split(new char[1]
                            {
                                '.'
                            }, 2);
                    address = "%" + text + "B";
                    num     = int.Parse(array[0]);
                    num2    = int.Parse(array[1]);
                    break;
                }
                }
                address = $"{address}{(num * 16 + num2) / 8}.{num2 % 8}";
                break;
            }
            }
            if (double.TryParse(value, out double result))
            {
                _SendTo(new LSRequestMessage(LSNetBase.GetRequestType(iODriverDataTypes), (byte)dv.SlaveId, new _PieceData(address, iODriverDataTypes, result)));
            }
            return(false);
        }