Esempio n. 1
0
        public static void Copy(File modbusDevice, DeviceBase canDevice)
        {
            Record rec;
            UInt16 index;
            UInt32 var32;

            if (canDevice.DeviceType != DeviceType.KIP_BATTERY_POWER_v1)
            {
                throw new InvalidCastException("Требуется устройство CAN типа КИП-9811");
            }
            if (modbusDevice.Records[KIP9811Address.VisitingCard.DeviceType].Value !=
                (UInt16)DeviceType.KIP_BATTERY_POWER_v1)
            {
                throw new InvalidCastException("Требуется устройство modbus типа КИП-9811");
            }

            // Адреса, которые обрабатываются по особому
            UInt16[] exclusions = new ushort[] { 0x000A, 0x000B, 0x000C, 0x000E, 0x0014,
                0x0019, 0x0020, 0x0024, 0x0025, 0x0026, 0x0036, 0x0037 };
            // Адреса, которые исключаются из обработки
            UInt16[] nothandled = new ushort[] { 0x0000, 0x0006, 0x0007, 0x0008, 0x0009, 
                0x000D, 0x000E };
            // Копируем данные
            foreach (UInt16 modbusAddress in _TableAddress.Keys)
            {
                // Исключаем из обработки адреса
                if (Exist(nothandled, modbusAddress))
                {
                    continue;
                }

                // Адреса для обработки особым способом,
                // так же пропускаем, их обработаем ниже
                if (Exist(exclusions, modbusAddress))
                { 
                    continue; 
                } 

                // Получаем индекс объекта CAN-устройства
                index = _TableAddress[modbusAddress];
                // Копируем значение объекта в запись modbus 
                modbusDevice.Records[modbusAddress].Value = 
                    (UInt16)canDevice.ObjectDictionary[index].Value; 
            }

            // Теперь обрабатываем сложные параметры
            // 0x0007
            //modbusDevice.Records[0x0007].Value = 0; //TODO Код производителя, всега неопределён
            // 0x000A 
            modbusDevice.Records[0x000A].Value = Convert.ToUInt16(canDevice.NodeId);
            // 0x000B
            if (canDevice.Status == DeviceStatus.CommunicationError)
            { modbusDevice.Records[0x000B].Value = 0; }
            else
            { modbusDevice.Records[0x000B].Value = 1; }
            // 0x000C
            //modbusDevice.Records[0x000C].Value = 0; //TODO
            // 0x000E
            switch (canDevice.Status)
            {
                case DeviceStatus.CommunicationError:
                case DeviceStatus.ConfigurationError:
                case DeviceStatus.Stopped:
                    {
                        modbusDevice.Records[0x000E].Value =
                            (UInt16)DeviceStatus.Stopped; // Stopped
                        break;
                    }
                case DeviceStatus.Operational:
                    {
                        modbusDevice.Records[0x000E].Value =
                            (UInt16)DeviceStatus.Operational;
                        break;
                    }
                case DeviceStatus.Preoperational:
                    {
                        modbusDevice.Records[0x000E].Value =
                            (UInt16)DeviceStatus.Preoperational;
                        break;
                    }
                default: { throw new NotSupportedException(); }
            }
            //0x0014 TODO
            //0x0019 TODO
            //0x0020 TODO
            //0x0024
            modbusDevice.Records[0x0024].Value = canDevice.ElectrodeArea;
            //0x0025, 0x0026
            var32 = (UInt32)canDevice.GetObject(_TableAddress[0x0025]);
            modbusDevice.Records[0x0025].Value = (UInt16)(var32 >> 16);
            var32 = (UInt32)canDevice.GetObject(_TableAddress[0x0026]);
            modbusDevice.Records[0x0026].Value = (UInt16)var32;
            //0x0036, 0x0037
            var32 = Unix.ToUnixTime((DateTime)canDevice.GetObject(_TableAddress[0x0036]));
            modbusDevice.Records[0x0036].Value = (UInt16)(var32 >> 16);
            var32 = Unix.ToUnixTime((DateTime)canDevice.GetObject(_TableAddress[0x0037]));
            unchecked
            {
                modbusDevice.Records[0x0037].Value = (UInt16)var32;
            }
            return;
        }
Esempio n. 2
0
        /// <summary>
        /// Обновляет данные из указанного устройства
        /// </summary>
        /// <param name="device">Сетевое устройство</param>
        private void UpdateDivice(DeviceBase device)
        {
            Boolean result;
            UInt16 index;
            DataRow row;

            row = null;

            if (device == null)
            {
                return;
            }

            // Ищем строку с указанным устройством
            foreach (DataRow item in this._PivotTable.Rows)
            {
                if (device.NodeId == System.Convert.ToByte(item["NodeId"]))
                {
                    // Строка с нужным устройством найдена
                    row = item;
                    break;
                }
            }

            index = 0x2008;
            row["PolarisationPotential_2008"] = device.GetObject(index);
            index = 0x2009;
            row["ProtectionPotential_2009"] = device.GetObject(index);
            index = 0x200B;
            row["ProtectionCurrent_200B"] = device.GetObject(index);
            index = 0x200C;
            row["PolarisationCurrent_200С"] = device.GetObject(index);
            index = 0x200F;
            row["Corrosion_depth_200F"] = device.GetObject(index);
            index = 0x2010;
            row["Corrosion_speed_2010"] = device.GetObject(index);
            index = 0x2015;
            row["Tamper_2015"] = device.GetObject(index);
        }