Example #1
0
 /// <summary>
 /// Default ctor
 /// </summary>
 public DeviceConfiguration()
 {
     var thisDevice = this;
     HeaderFields = new DeviceHeader(ref thisDevice);
     LastConfigurationTime = new DeviceConfigurationTime();
     //minimum 1 UART presentin device
     UartPorts = new List<DeviceUARTPortConfiguration>(3) { new DeviceUARTPortConfiguration(ref thisDevice) };
     DIModuleConfiguration = null;
     DOModuleConfiguration = null;
     RoutingHeader = null;
     RoutingTable = null;
     AIModuleConfiguration = null;
     ModbusMasterQueriesOnUartPorts = new ObservableCollection<ObservableCollection<DeviceModbusMasterQuery>>(){new ObservableCollection<DeviceModbusMasterQuery>()};
 }
Example #2
0
        public bool FromList(List<object> listOfConfigurationItems)
        {
            if (listOfConfigurationItems.Count < 3)
                return false;
            int listIndex = 0;
            //Header
            object tempObj = HeaderFields;
            Utility.CloneObjectProperties(listOfConfigurationItems[listIndex++], ref tempObj);
            HeaderFields = tempObj as DeviceHeader;
            //Configuration Time
            LastConfigurationTime = listOfConfigurationItems[listIndex++] as DeviceConfigurationTime;//Utility.CloneObject(listOfConfigurationItems[listIndex++]) as DeviceConfigurationTime;
            //UART ports
            for (int port = 0; port < HeaderFields.DeviceUartChannelsCount && listIndex < listOfConfigurationItems.Count; port++)
            {
                UartPorts[port] = listOfConfigurationItems[listIndex++] as DeviceUARTPortConfiguration;
            }

            if (DIModuleConfiguration != null && HeaderFields.ModuleDI && listIndex < listOfConfigurationItems.Count)
                DIModuleConfiguration = listOfConfigurationItems[listIndex++] as DeviceModuleDIConfiguration;

            if (DOModuleConfiguration != null && HeaderFields.ModuleDO && listIndex < listOfConfigurationItems.Count)
                DOModuleConfiguration = listOfConfigurationItems[listIndex++] as DeviceModuleDOConfiguration;

            if (RoutingHeader != null && HeaderFields.ModuleRouter && listIndex < listOfConfigurationItems.Count)
            {
                tempObj = RoutingHeader;
                Utility.CloneObjectProperties(listOfConfigurationItems[listIndex++], ref tempObj);
                RoutingHeader = tempObj as DeviceRoutingHeader;
            }

            if (HeaderFields.ModuleRouter && RoutingTable != null)
            {
                for (int route = 0; route < HeaderFields.DeviceUserRegistersCount && listIndex < listOfConfigurationItems.Count; route++)
                {
                    RoutingTable[route] = listOfConfigurationItems[listIndex++] as DeviceRoutingTableElement;
                }
            }

            if (AIModuleConfiguration != null && HeaderFields.ModuleAI && listIndex < listOfConfigurationItems.Count)
                AIModuleConfiguration = listOfConfigurationItems[listIndex++] as DeviceModuleAIConfiguration;

            if (HeaderFields.ModuleModbusMaster)
            {
                foreach (ObservableCollection<DeviceModbusMasterQuery> portQueriesList in ModbusMasterQueriesOnUartPorts)
                {
                    for (int query = 0; query < portQueriesList.Count && listIndex < listOfConfigurationItems.Count; query++)
                    {
                        portQueriesList[query] = listOfConfigurationItems[listIndex++] as DeviceModbusMasterQuery;
                    }
                }
            }

            return true;
        }
Example #3
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;
        }