Ejemplo n.º 1
0
        internal ReaderSaverErrors ReadDeviceHeader(DeviceConfiguration configuration)
        {
            List<object> listOfConfigurationItems = new List<object>();
            DeviceHeader tempHeader = new DeviceHeader();
            DeviceConfigurationTime tempConfigurationTime = new DeviceConfigurationTime();
            listOfConfigurationItems.Add(tempHeader);
            listOfConfigurationItems.Add(tempConfigurationTime);

            ReaderSaverErrors retCode = PerformReading(ref listOfConfigurationItems);
            if (retCode != ReaderSaverErrors.CodeOk)
                return retCode;

            if (listOfConfigurationItems.Count < 1)
                return ReaderSaverErrors.CodeUnknownError;

            if (!tempHeader.IsValidHeader())
                    return ReaderSaverErrors.CodeInvalidDeviceHeader;

            configuration.HeaderFields.DeviceConsistenceRegister = tempHeader.DeviceConsistenceRegister;
            configuration.HeaderFields.DeviceHeaderCrc16 = tempHeader.DeviceHeaderCrc16;
            configuration.HeaderFields.DeviceUartChannelsCount = tempHeader.DeviceUartChannelsCount;
            configuration.HeaderFields.DeviceMaximumModbusMasterRequestsToSubDeviceCount = tempHeader.DeviceMaximumModbusMasterRequestsToSubDeviceCount;
            configuration.HeaderFields.DeviceUserRegistersCount = tempHeader.DeviceUserRegistersCount;
            configuration.HeaderFields.DeviceVersion = tempHeader.DeviceVersion;
            configuration.LastConfigurationTime = tempConfigurationTime;

            return ReaderSaverErrors.CodeOk;
        }
Ejemplo n.º 2
0
        internal ReaderSaverErrors CheckDeviceHeaderValidityAndInitConfiguration(DeviceConfiguration configuration, bool checkOnly = false)
        {
            List<object> listOfConfigurationItems = new List<object>();
            DeviceHeader tempHeader = new DeviceHeader();
            listOfConfigurationItems.Add(checkOnly ? tempHeader : configuration.HeaderFields);

            ReaderSaverErrors retCode = PerformReading(ref listOfConfigurationItems);
            if (retCode != ReaderSaverErrors.CodeOk)
                return retCode;

            if (listOfConfigurationItems.Count < 1)
                return ReaderSaverErrors.CodeUnknownError;

            if (!checkOnly)
            {
                object tempObj = configuration.HeaderFields;
                Utility.CloneObjectProperties(listOfConfigurationItems[0], ref tempObj);
                if (!configuration.HeaderFields.IsValidHeader())
                    return ReaderSaverErrors.CodeInvalidDeviceHeader;

                if (configuration.HeaderFields.ModuleRouter && configuration.RoutingHeader != null)
                {
                    //save previous reading  offset
                    UInt16 currentDeviceOffset = RegisterReadAddressOffset;
                    //calculate offset for reading router header
                    listOfConfigurationItems.Add(configuration.LastConfigurationTime);
                    listOfConfigurationItems.AddRange(configuration.UartPorts);
                    if (configuration.DIModuleConfiguration != null)
                        listOfConfigurationItems.Add(configuration.DIModuleConfiguration);
                    if (configuration.DOModuleConfiguration != null)
                        listOfConfigurationItems.Add(configuration.DOModuleConfiguration);

                    RegisterReadAddressOffset = (UInt16)(currentDeviceOffset + ((SizeofHelper.SizeOfPublicPropertiesWithModbusAttribute(listOfConfigurationItems) + 1) / 2));
                    listOfConfigurationItems.Clear();

                    //read header
                    listOfConfigurationItems.Add(configuration.RoutingHeader);
                    retCode = PerformReading(ref listOfConfigurationItems);
                    if (retCode != ReaderSaverErrors.CodeOk)
                        return retCode;
                    //restore previous reading  offset
                    RegisterReadAddressOffset = currentDeviceOffset;
                }
            }
            else
            {
                if (!tempHeader.IsValidHeader())
                    return ReaderSaverErrors.CodeInvalidDeviceHeader;

                if (configuration.HeaderFields.DeviceUartChannelsCount !=
                    tempHeader.DeviceUartChannelsCount)
                    return ReaderSaverErrors.CodeNotCompliantDevice;
            }
            return ReaderSaverErrors.CodeOk;
        }