Exemple #1
0
        private async Task <ushort[]> ReadAllPicon2()
        {
            List <ushort> ushorts = new List <ushort>();

            ushorts.AddRange(await RTUConnectionGlobal.GetDataByAddress(1, (ushort)(0x000E), 20));
            return(ushorts.ToArray());
        }
Exemple #2
0
        public async Task Update()
        {
            //if (_semaphoreSlim.CurrentCount == 0) return;
            //await _semaphoreSlim.WaitAsync();

            if (DeviceSelection.SelectedDevice == (int)DeviceSelectionEnum.DEVICE_PICON2)
            {
                ushort[] value = await RTUConnectionGlobal.GetDataByAddress(1, 0x0004, 1);

                Application.Current.Dispatcher.Invoke(() =>
                {
                    SetAllFlagsPicon2(value[0]);
                });
            }
            else
            {
                ushort[] value = await RTUConnectionGlobal.GetDataByAddress(1, 0x0304, 1);

                Application.Current.Dispatcher.Invoke(() =>
                {
                    SetAllFlags(value[0]);
                });
            }
            //if (_semaphoreSlim.CurrentCount == 0)
            //{
            //    _semaphoreSlim.Release();
            //}
        }
Exemple #3
0
        /// <summary>
        /// Зажигает индикаторы ошибок модулей
        /// </summary>
        /// <param name="val"></param>
        public async void SetModuleErrors()
        {
            try
            {
                ushort[] value = await RTUConnectionGlobal.GetDataByAddress(1, 0x1102, 1);

                BitArray array = Converter.GetBitsFromWord(value[0]);
                if (IsToggleCrate918Checked)
                {
                    //костыли по причине того, что всякие люди не могут договориться между собой иделают все по-своему
                    ModuleErrors[0] = false;
                    for (int i = 0; i < 16; i++)
                    {
                        ModuleErrors[i + 1] = array[i];
                    }
                }
                else
                {
                    for (int i = 0; i < 10; i++)
                    {
                        ModuleErrors[i] = array[i];
                    }
                }
            }
            catch (Exception ex)
            {
                ShowMessage("Ошибка чтения состояния модулей", "Ошибка", MessageBoxImage.Error);
            }
        }
Exemple #4
0
        /// <summary>
        /// Чтение конфигурации модуля связи из устройства
        /// </summary>
        private async void OnReadRequestCommand()
        {
            ushort[] result = null;
            if (IsUpper)
            {
                try
                {
                    result = await RTUConnectionGlobal.GetDataByAddress(1, UPPER_ADDRESS, PACKAGE_LENGTH);

                    ShowMessage("Чтение прошло успешно!", "Информация", MessageBoxImage.Information);
                    AnalyzeConfigFromDevice(result);
                }
                catch (Exception ex)
                {
                    ShowMessage("При чтении конфигурации произошла ошибка!", "Внимание", MessageBoxImage.Warning);
                }
            }
            else
            {
                try
                {
                    result = await RTUConnectionGlobal.GetDataByAddress(1, LOWER_ADDRESS, PACKAGE_LENGTH);

                    ShowMessage("Чтение прошло успешно!", "Информация", MessageBoxImage.Information);
                    AnalyzeConfigFromDevice(result);
                }
                catch (Exception ex)
                {
                    ShowMessage("При чтении конфигурации произошла ошибка!", "Внимание", MessageBoxImage.Warning);
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// Чтение запросов из устройства
        /// </summary>
        private async void OnReadFromDeviceCommand()
        {
            //херня, знаю, но смысл один и тот же. надо просто сделать недоступными кнопки на вермя чтения, а обращаться через имя я не хочу
            IsAutonomus = true;
            try
            {
                this.RequestsFromDevice.Clear();
                this.ModuleRequestsForUIList.Clear();
                // число запросов к модулям хранится по адресу 0х300Е, читаем 1 слово(2 байта)
                ushort[] RC = await RTUConnectionGlobal.GetDataByAddress(1, REQUEST_COUNT_ADDRESS, 1);

                RequestCountFromDevice = RC[0];
                // начальный адрес
                ushort currentAddress = MODULE_REQUEST_START_ADDRESS;
                for (byte i = 0; i < RC[0]; i++)
                {
                    RequestsFromDevice.Add(new ModuleRequest(await RTUConnectionGlobal.GetDataByAddress(1, currentAddress, 4)));
                    ModuleRequestsForUIList.Add(RequestsFromDevice[i].UIRequest);
                    currentAddress += 4;
                }
                ShowMessage("Чтение запросов прошло успешно!", "Информация", MessageBoxImage.Information);
                AnalyzeModulesFromDevice();
            }
            catch (Exception ex)
            {
                ShowMessage("При чтении запросов произошла ошибка.", "Внимание", MessageBoxImage.Warning);
            }
            IsAutonomus = false;
        }
Exemple #6
0
        public async Task Update()
        {
            //if (_semaphoreSlim.CurrentCount == 0) return;
            //await _semaphoreSlim.WaitAsync();
            try
            {
                ushort[] value = await RTUConnectionGlobal.GetDataByAddress(1, 0x1100, 1);

                if (value == null)
                {
                    return;
                }
                BitArray d = new BitArray(new int[] { value[0] });
                Application.Current.Dispatcher.Invoke(() =>
                {
                    SetIndicators(d);
                });
            }
            catch (Exception ex)
            {
            }
            //if (_semaphoreSlim.CurrentCount == 0)
            //{
            //    _semaphoreSlim.Release();
            //}
        }
Exemple #7
0
        public async Task Update()
        {
            //if (_semaphoreSlim.CurrentCount == 0) return;
            //await _semaphoreSlim.WaitAsync();

            if (DeviceSelection.SelectedDevice == (byte)DeviceSelectionEnum.DEVICE_PICON2)
            {
                ushort[] value = await RTUConnectionGlobal.GetDataByAddress(1, 0x0000, 5);

                //var res = DataTransfer.ReadWords(Querer);
                //Dispatcher.BeginInvoke(new ReadComplete(RunWorkerCompleted), DispatcherPriority.SystemIdle, res);
                Application.Current.Dispatcher.Invoke(() =>
                {
                    SetChannelsValue(value);
                });
            }
            else
            {
                ushort[] value = await RTUConnectionGlobal.GetDataByAddress(1, 0x0000, 5);

                //var res = DataTransfer.ReadWords(Querer);
                //Dispatcher.BeginInvoke(new ReadComplete(RunWorkerCompleted), DispatcherPriority.SystemIdle, res);
                Application.Current.Dispatcher.Invoke(() =>
                {
                    SetChannelsValue(value);
                });
            }

            //if (_semaphoreSlim.CurrentCount == 0)
            //{
            //    _semaphoreSlim.Release();
            //}
        }
Exemple #8
0
        public async Task Update()
        {
            ushort[] value = await RTUConnectionGlobal.GetDataByAddress(1, 0x0200, 5);

            Application.Current.Dispatcher.Invoke(() =>
            {
                SetValue(value);
            });
        }
Exemple #9
0
        //TODO: make updateState for picon2
        public async Task UpdateState()
        {
            ushort[] value;
            {
                value = await RTUConnectionGlobal.GetDataByAddress(1, 0x8200, 61);
            }

            //ImportComplete(value);
        }
Exemple #10
0
        public async Task Update()
        {
            //ошибки модулей
            ushort[] value = await RTUConnectionGlobal.GetDataByAddress(1, 0x1102, 1);

            Application.Current.Dispatcher.Invoke(() =>
            {
                SetAllFlags(value[0]);
            });
        }
Exemple #11
0
        public async Task UpdateState()
        {
            uiExport.IsEnabled = uiImport.IsEnabled = false;

            ushort[] value = await RTUConnectionGlobal.GetDataByAddress(1, 0x9108, 2);


            ImportComplete(value);

            uiExport.IsEnabled = uiImport.IsEnabled = true;
        }
Exemple #12
0
        private async Task <ushort[]> ReadAll()
        {
            List <ushort> ushorts = new List <ushort>();

            for (ushort i = 0; i < 200; i += 100)
            {
                ushorts.AddRange(await RTUConnectionGlobal.GetDataByAddress(1, (ushort)(0x0208 + i), 100));
            }
            ushorts.AddRange(await RTUConnectionGlobal.GetDataByAddress(1, 0x0208 + 200, 86));

            return(ushorts.ToArray());
        }
Exemple #13
0
        private async Task ReadScheduleData(ushort startAddress)
        {
            var ushorts = new List <ushort>();

            for (ushort i = 0; i < 700; i += 100)
            {
                ushorts.AddRange(await RTUConnectionGlobal.GetDataByAddress(1, (ushort)(startAddress + i), 100));
            }

            ushorts.AddRange(await RTUConnectionGlobal.GetDataByAddress(1, (ushort)(startAddress + 700), 70));


            this.ImportComplete(ushorts.ToArray());
        }
Exemple #14
0
        private async void GetSignature()
        {
            uiSignature.IsEnabled = false;
            try
            {
                ushort[] res = await RTUConnectionGlobal.GetDataByAddress(1, (ushort)(0x0400), 52);

                ReadSignatureComplete(res);
            }
            catch (Exception exception)
            {
            }
            uiSignature.IsEnabled = true;
        }
Exemple #15
0
        public async Task UpdateState()
        {
            uiLogicConfigOpen.IsEnabled     =
                uiLogicConfigSave.IsEnabled = uiLogicExport.IsEnabled = uiLogicImport.IsEnabled = false;
            ushort[] value;
            {
                value = await RTUConnectionGlobal.GetDataByAddress(1, 0x8200, 61);
            }

            ImportComplete(value);

            uiLogicConfigOpen.IsEnabled     =
                uiLogicConfigSave.IsEnabled = uiLogicExport.IsEnabled = uiLogicImport.IsEnabled = true;
        }
Exemple #16
0
        public async Task ReadJournalPicon2()
        {
            Picon2EventsCollection.Clear();
            ushort[] Picon2JournalReportCountUshort = new ushort[1];
            Picon2JournalReportCountUshort = await RTUConnectionGlobal.GetDataByAddress(1, (ushort)0x4000, 1);

            byte Picon2JournalReportCountLOByte = LOBYTE(Picon2JournalReportCountUshort[0]);
            byte Picon2JournalReportCountHIByte = HIBYTE(Picon2JournalReportCountUshort[0]);

            for (int i = 0; i < Picon2JournalReportCountLOByte; i++)
            {
                this.Picon2EventsCollection.Add(new Picon2JournalEventRecord(await RTUConnectionGlobal.GetDataByAddress(1, (ushort)(0x4300 + i), 8)));
            }
            //todo: попробовать подогнать записи журнала под одни правила для всех устройств(не получится скорее всего)
        }
Exemple #17
0
        public async Task Update()
        {
            if (DeviceSelection.SelectedDevice == (int)DeviceSelectionEnum.DEVICE_PICON2)
            {
                try
                {
                    //ushort[] value = await RTUConnectionGlobal.GetDataByAddress(1, 0x6000, 2);
                    //Application.Current.Dispatcher.Invoke(() =>
                    //{
                    //    SetJournalValue(value);

                    //});

                    //this.ReadJournalValue();
                }
                catch (Exception ex)
                {
                    ShowMessage(ex.Message, "Error", MessageBoxImage.Error);
                }
            }
            else
            {
                try
                {
                    ushort[] value = await RTUConnectionGlobal.GetDataByAddress(1, 0x2001, 5727);

                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        SetJournalValue(value);
                    });

                    this.ReadJournalValue();
                }
                catch (Exception ex)
                {
                    ShowMessage(ex.Message, "Error", MessageBoxImage.Error);
                }
            }
            //if (this.StopWork != null)
            //{
            //    this.Dispatcher.BeginInvoke(DispatcherPriority.SystemIdle, new Action(() =>
            //    {
            //        StopWork();
            //        StateTextBlock.Text = string.Empty;
            //    }));
            //}
        }
Exemple #18
0
        public async Task Update()
        {
            //if (_semaphoreSlim.CurrentCount == 0) return;
            //await _semaphoreSlim.WaitAsync();

            ushort[] value = await RTUConnectionGlobal.GetDataByAddress(1, 0x0200, 5);

            Application.Current.Dispatcher.Invoke(() =>
            {
                SetValue(value);
            });

            //if (_semaphoreSlim.CurrentCount == 0)
            //{
            //    _semaphoreSlim.Release();
            //}
        }
Exemple #19
0
        private async void uiImport_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                uiImport.IsEnabled = uiExport.IsEnabled = false;
                List <ushort> ushorts = new List <ushort>();
                ushorts.AddRange(await RTUConnectionGlobal.GetDataByAddress(1, 0x8000, 68));
                ushorts.AddRange(await RTUConnectionGlobal.GetDataByAddress(1, 0x8000 + 68, 60));
                uiImport.IsEnabled = uiExport.IsEnabled = true;
                ushort[] value = ushorts.ToArray();
                ImportComplete(value);
                Value = value;
            }
            catch

            {
            }
        }
Exemple #20
0
        public async Task Update()

        {
            //if (_semaphoreSlim.CurrentCount == 0) return;
            //await _semaphoreSlim.WaitAsync();
            if (DeviceSelection.SelectedDevice == (int)DeviceSelectionEnum.DEVICE_PICON2)
            {
                try
                {
                    ushort[] value = await RTUConnectionGlobal.GetDataByAddress(1, 0x2100, 8);

                    if (value == null)
                    {
                        return;
                    }
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        SetTimeForPicon2(value);
                        uiChangeTime.IsEnabled = uiSystemTime.IsEnabled = true;
                    });
                }
                catch (Exception ex)
                {
                }
            }
            else
            {
                ushort[] value = await RTUConnectionGlobal.GetDataByAddress(1, 0x1000, 16);

                Application.Current.Dispatcher.Invoke(() =>
                {
                    SetTime(value);
                    uiChangeTime.IsEnabled = uiSystemTime.IsEnabled = true;
                });
            }
            //if (_semaphoreSlim.CurrentCount == 0)
            //{
            //    _semaphoreSlim.Release();
            //}
        }
Exemple #21
0
        public async Task <ushort[]> ReadJournalValue()
        {
            //List<ushort> ushorts = new List<ushort>();
            //for (ushort i = 0; i < 3900; i += 100)
            //{
            //    ushorts.AddRange(await RTUConnectionGlobal.GetDataByAddress(1, (ushort)(0x2001 + i), 100));
            //}
            //ushorts.AddRange(await RTUConnectionGlobal.GetDataByAddress(1, 0x2001 + 3900, 10));

            //return ushorts.ToArray();

            List <ushort> ushorts = new List <ushort>();

            for (ushort i = 0; i < 5635; i += 92)
            {
                ushorts.AddRange(await RTUConnectionGlobal.GetDataByAddress(1, (ushort)(0x2001 + i), 92));
            }
            ushorts.AddRange(await RTUConnectionGlobal.GetDataByAddress(1, (ushort)(0x2001 + 5704), 23));


            return(ushorts.ToArray());
        }
Exemple #22
0
        public async Task Update()
        {
            //if (_semaphoreSlim.CurrentCount == 0) return;
            //await _semaphoreSlim.WaitAsync();

            if (DeviceSelection.SelectedDevice == (int)DeviceSelectionEnum.DEVICE_PICON2)
            {
                try
                {
                    ushort[] value = await RTUConnectionGlobal.GetDataByAddress(1, 0x0005, 4);

                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        SetPicon2States(value);
                    });
                }
                catch (Exception ex)
                { }
            }
            else
            {
                try
                {
                    ushort[] value = await RTUConnectionGlobal.GetDataByAddress(1, 0x0005, 8);

                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        SetStates(value);
                    });
                }
                catch (Exception ex)
                { }
            }

            //if (_semaphoreSlim.CurrentCount == 0)
            //{
            //    _semaphoreSlim.Release();
            //}
        }
Exemple #23
0
        public async Task Update()
        {
            //if (_semaphoreSlim.CurrentCount == 0) return;
            //await _semaphoreSlim.WaitAsync();
            if (DeviceSelection.SelectedDevice == (byte)DeviceSelectionEnum.DEVICE_PICON2)
            {
                ushort[] ConnectionModuleId;
                {
                    ConnectionModuleId = await RTUConnectionGlobal.GetDataByAddress(1, 0x3004, 1);
                }
                if ((byte)ConnectionModuleId[0] != 0xE0 && (byte)ConnectionModuleId[0] != 0xE1)
                {
                    return;
                }
                byte[] value = await RTUConnectionGlobal.ExecuteFunction12Async((byte)ConnectionModuleId[0], "Get Picon SignalLevel", 0x60);

                if (value == null)
                {
                    return;
                }
                Application.Current.Dispatcher.Invoke(() =>
                {
                    SetGsmPicon2(value);
                });
            }
            else
            {
                ushort[] value = await RTUConnectionGlobal.GetDataByAddress(1, 0x001F, 8);

                Application.Current.Dispatcher.Invoke(() =>
                {
                    SetGsm(value);
                });
            }
            //if (_semaphoreSlim.CurrentCount == 0)
            //{
            //    _semaphoreSlim.Release();
            //}
        }
Exemple #24
0
        /// <summary>
        /// Анализ модулей, прочитанных из устройства + их расстановка по местам
        /// </summary>
        private async void AnalyzeModulesFromDevice()
        {
            byte _firstModulePos;

            if (IsToggleCrate918Checked)
            {
                _firstModulePos = 0;
            }
            else
            {
                _firstModulePos = 1;
            }
            /// читаем модуль с верхом
            try
            {
                ushort[] upperModule = await RTUConnectionGlobal.GetDataByAddress(1, UPPER_MODULE_ADDRESS, 5);

                if (upperModule != null)
                {
                    byte[] byteArrayUpper    = ArrayExtension.UshortArrayToByteArray(upperModule);
                    string _typeAddressUpper = Converters.Convert.ConvertFromDecToHexStr(byteArrayUpper[1]);
                    byte   _typeUpper        = Converters.Convert.ConvertFromHexToDec((byte)Int32.Parse(_typeAddressUpper.First().ToString(), System.Globalization.NumberStyles.HexNumber));
                    byte   _addressUpper     = Converters.Convert.ConvertFromHexToDec((byte)Int32.Parse(_typeAddressUpper.Last().ToString(), System.Globalization.NumberStyles.HexNumber));
                    string upperName         = "Заглушка";
                    if (_typeUpper != 0)
                    {
                        if (_typeUpper == 0x0E)
                        {
                            //немного костыли, но че уж поделать, если таски возникают после того, как ниписано практически все
                            Config915Series cfg915 = new Config915Series(byteArrayUpper[5]);
                            if (cfg915.ModbusSpeed == 115200)
                            {
                                upperName = "MС915";
                            }
                            if (cfg915.ModbusSpeed == 19200)
                            {
                                upperName = "MС917";
                            }
                        }
                        if (_typeUpper == 0x0F)
                        {
                            upperName = "MС911";
                        }
                        this.ModuleListForUI[_addressUpper - _firstModulePos] = upperName;
                    }
                }
            }
            catch (Exception ex)
            {
                ShowMessage("При чтении запроса модуля связи с верхом произошла ошибка.", "Внимание", MessageBoxImage.Warning);
            }
            /// читаем модуль с низом
            try
            {
                ushort[] slaveCount = await RTUConnectionGlobal.GetDataByAddress(1, LOWER_MODULE_REQUEST_TO_SLAVES_COUNT_ADDRESS, 1);

                if (slaveCount[0] != 0)
                {
                    ushort[] lowerModule = await RTUConnectionGlobal.GetDataByAddress(1, LOWER_MODULE_ADDRESS, 5);

                    if (lowerModule != null)
                    {
                        byte[] byteArrayLower    = ArrayExtension.UshortArrayToByteArray(lowerModule);
                        string _typeAddressLower = Converters.Convert.ConvertFromDecToHexStr(byteArrayLower[1]);
                        byte   _typeLower        = Converters.Convert.ConvertFromHexToDec((byte)Int32.Parse(_typeAddressLower.First().ToString(), System.Globalization.NumberStyles.HexNumber));
                        byte   _addressLower     = Converters.Convert.ConvertFromHexToDec((byte)Int32.Parse(_typeAddressLower.Last().ToString(), System.Globalization.NumberStyles.HexNumber));
                        string lowerName         = "Заглушка";
                        if (_typeLower == 0x0E)
                        {
                            lowerName = "Люксметр";
                        }
                        this.ModuleListForUI[_addressLower - _firstModulePos] = lowerName;
                    }
                }
            }
            catch (Exception ex)
            {
                ShowMessage("При чтении запроса модуля связи с низом произошла ошибка.", "Внимание", MessageBoxImage.Warning);
            }
            ///модули

            for (int i = 0; i < RequestsFromDevice.Count(); i++)
            {
                this.ModuleListForUI[RequestsFromDevice[i].CrateAddress - _firstModulePos] = GetModuleNameFromType(RequestsFromDevice[i].Type, RequestsFromDevice[i].ParameterCount);
            }
            ///верх


            ///низ
        }