Example #1
0
        static void GetParametersFromDB(CommonDatabase commonDatabase)
        {
            LoadingService.Show("Запрос параметров", commonDatabase.BinaryObjects.Count);

            foreach (var binaryObject in commonDatabase.BinaryObjects)
            {
                var rootDevice = commonDatabase.RootDevice;
                var no = binaryObject.GetNo();
                LoadingService.DoStep("Запрос параметров объекта " + no);
                var sendResult = SendManager.Send(rootDevice, 2, 9, ushort.MaxValue, BytesHelper.ShortToBytes(no));

                if (sendResult.HasError == false)
                {
                    for (int i = 0; i < sendResult.Bytes.Count / 4; i++)
                    {
                        byte paramNo = sendResult.Bytes[i * 4];
                        ushort paramValue = BytesHelper.SubstructShort(sendResult.Bytes, i * 4 + 1);

                        if (binaryObject.Device != null)
                        {
                            var driverProperty = binaryObject.Device.Driver.Properties.FirstOrDefault(x => x.No == paramNo);
                            if (driverProperty != null)
                            {
                                var property = binaryObject.Device.Properties.FirstOrDefault(x => x.Name == driverProperty.Name);
                                if (property != null)
                                {
                                    if (property.Value != paramValue)
                                        property.Value = paramValue;
                                }
                                else
                                    MessageBoxService.Show("Не найдено свойство устройства");
                            }
                        }
                    }
                }
                //if (hasChangedProperties)
                {
                    var deviceViewModel = DevicesViewModel.Current.Devices.FirstOrDefault(x => x.Device.UID == binaryObject.Device.UID);
                    if (deviceViewModel != null)
                    {
                        deviceViewModel.UpdateProperties();
                    }
                }
            }
            LoadingService.Close();
        }
Example #2
0
 static void WriteEndDescriptor(CommonDatabase commonDatabase)
 {
     LoadingService.DoStep(commonDatabase.RootDevice.PresentationDriverAndAddress + " Запись завершающего дескриптора");
     var endBytes = BinConfigurationWriter.CreateEndDescriptor((ushort)(commonDatabase.BinaryObjects.Count + 1));
     SendManager.Send(commonDatabase.RootDevice, 5, 17, 0, endBytes, true);
 }
Example #3
0
 static void WriteConfigToDevice(CommonDatabase commonDatabase)
 {
     foreach (var binaryObject in commonDatabase.BinaryObjects)
     {
         var progressStage = commonDatabase.RootDevice.PresentationDriverAndAddress + ": запись дескриптора " +
             binaryObject.GetNo().ToString() + " из " + commonDatabase.BinaryObjects.Count.ToString();
         LoadingService.DoStep(progressStage);
         var packs = BinConfigurationWriter.CreateDescriptors(binaryObject);
         foreach (var pack in packs)
         {
             var packBytesCount = pack.Count;
             var sendResult = SendManager.Send(commonDatabase.RootDevice, (ushort)(packBytesCount), 17, 0, pack, true);
             if (sendResult.HasError)
             {
                 MessageBoxService.Show(sendResult.Error);
                 //LoadingService.Close();
                 //break;
             }
         }
     }
     WriteEndDescriptor(commonDatabase);
 }
Example #4
0
        static void SaveToFile(CommonDatabase commonDatabase, string fileName)
        {
            var fileBytes = new List<byte>();
            fileBytes.Add(0x25);
            fileBytes.Add(0x08);
            fileBytes.Add(0x19);
            fileBytes.Add(0x65);
            fileBytes.AddRange(BytesHelper.ShortToBytes((ushort)(commonDatabase.BinaryObjects.Count + 1)));
            fileBytes.AddRange(BytesHelper.ShortToBytes((ushort)0));
            fileBytes.AddRange(BytesHelper.ShortToBytes((ushort)0));
            fileBytes.AddRange(BytesHelper.ShortToBytes((ushort)0));
            fileBytes.AddRange(BytesHelper.ShortToBytes((ushort)0));

            foreach (var binaryObject in commonDatabase.BinaryObjects)
            {
                fileBytes.AddRange(CreateDescriptor(binaryObject));
            }
            fileBytes.AddRange(CreateEndDescriptor((ushort)commonDatabase.BinaryObjects.Count));

            using (var fileStream = new FileStream(fileName, FileMode.Create))
            {
                fileStream.Write(fileBytes.ToArray(), 0, fileBytes.Count);
            }
        }
Example #5
0
        static void SetParametersToDB(CommonDatabase commonDatabase)
        {
            LoadingService.Show("Запись параметров", commonDatabase.BinaryObjects.Count);

            foreach (var binaryObject in commonDatabase.BinaryObjects)
            {
                if (binaryObject.Device != null)
                {
                    if (binaryObject.Parameters.Count > 0)
                    {
                        var rootDevice = commonDatabase.RootDevice;
                        var no = binaryObject.GetNo();
                        var bytes = new List<byte>();
                        bytes.AddRange(BytesHelper.ShortToBytes(no));
                        bytes.AddRange(binaryObject.Parameters);
                        LoadingService.DoStep("Запись параметров объекта " + no);
                        SendManager.Send(rootDevice, (ushort)bytes.Count, 10, 0, bytes);
                    }
                }
            }

            LoadingService.Close();
        }