/// <summary> /// MDB устройства включены /// </summary> private static void CashDevices_MDBStarted() { Task.Run(() => { StartPage.UpdateProgress(10); StartPage.UpdateStartLEDs(StartPage.StartPageInstance.MDBLED, Colors.Green); StartPage.AddItemToLogBox("Найден адаптер MDB-RS232"); int count = 0; while (count < 10) { Task.Delay(100).Wait(); count++; } MDB.MDBInitStep = 1; MDB.ResetCashDevices(); }); }
/// <summary> /// MDB устройства включены /// </summary> private static void CashDevices_MDBStarted() { Task.Run(() => { StartPage.UpdateProgress(15); StartPage.UpdateStartLEDs(StartPage.StartPageInstance.MDBLED, Colors.Green); StartPage.UpdateStartLEDs(StartPage.StartPageInstance.UART0LED, Colors.Green); StartPage.AddItemToLogBox("Найден адаптер MDB-RS232"); int count = 0; while (count < 10) { Task.Delay(100).Wait(); count++; } MDBInitStep = 1; #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed MDB.ResetCashDevicesAsync(); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed }); }
/// <summary> /// Инициализирует последовательный порт шины MDB /// </summary> /// <param name="cashdeskseroalportid">Исключить конкретный порт из поиска</param> public static async void ConnectMDBSerialPort(string cashdeskseroalportid) { try { MDBCommandsListSemaphore.Release(); StartPage.UpdateStartLEDs(StartPage.StartPageInstance.UART0LED, Colors.Yellow); StartPage.UpdateProgress(5); StartPage.AddItemToLogBox("Поиск последовательного порта шины MDB..."); string aqs = SerialDevice.GetDeviceSelector(); var dis = await DeviceInformation.FindAllAsync(aqs); foreach (var item in dis) { if (item.Id != cashdeskseroalportid) { MDBSerialPort = await SerialDevice.FromIdAsync(item.Id); } } if (MDBSerialPort == null) { return; } MDBSerialPort.WriteTimeout = TimeSpan.FromMilliseconds(1000); MDBSerialPort.ReadTimeout = TimeSpan.FromMilliseconds(1000); MDBSerialPort.BaudRate = 9600; MDBSerialPort.Parity = SerialParity.None; MDBSerialPort.StopBits = SerialStopBitCount.One; MDBSerialPort.DataBits = 8; string a = "Порт шины MDB успешно настроен: "; a += MDBSerialPort.BaudRate + "-"; a += MDBSerialPort.DataBits + "-"; a += MDBSerialPort.Parity.ToString() + "-"; a += MDBSerialPort.StopBits; StartPage.AddItemToLogBox(a); ListenMDBSerialPort(); } catch (Exception ex) { StartPage.AddItemToLogBox(ex.Message); } }
/// <summary> /// произведен сброс купюроприемника /// </summary> private static void CashDevices_MDBBAReseted() { Task.Run(() => { Mutex m2 = new Mutex(true, "MDBDeviceResetHandlerMutex", out bool mutexWasCreated); if (!mutexWasCreated) { try { m2.WaitOne(); } catch (AbandonedMutexException) { } } try { if ((!StartPage.bareset) && (MDB.MDBInitStep == 3 || MDB.MDBInitStep == 4)) { MDB.MDBInitStep++; StartPage.UpdateProgress(5); StartPage.bareset = true; StartPage.UpdateStartLEDs(StartPage.StartPageInstance.MDBBALED, Colors.Green); StartPage.AddItemToLogBox("Купюроприемник готов к работе"); if (StartPage.ccreset) { string oosfilename = ApplicationData.Current.LocalFolder.Path + "\\" + GlobalVars.HardWareID + ".031"; StartPage.CurrentState = StartPage.States.OutOfService; #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { var frame = Window.Current.Content as Frame; frame.Navigate(typeof(OutOfServicePage)); }); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed StartPage.AddItemToLogBox("Ожидание полной инициализации..."); int count = 0; while (count < 100) { Task.Delay(100).Wait(); count++; } MDB.MDBInitStep = 5; StartPage.AddItemToLogBox("Устройства приема наличных обнаружены и настроены"); } } if ((!StartPage.bainit) && (MDB.MDBInitStep == 1 || MDB.MDBInitStep == 2)) { MDB.MDBInitStep++; StartPage.UpdateProgress(5); StartPage.bainit = true; StartPage.UpdateStartLEDs(StartPage.StartPageInstance.MDBBALED, Colors.Yellow); StartPage.AddItemToLogBox("Купюроприемник инициализирован"); StartPage.UpdateProgress(5); int count = 0; while (count < 20) { Task.Delay(100).Wait(); count++; } MDB.ResetBA(); } } catch (Exception ex) { StartPage.AddItemToLogBox("Ошибка: " + ex.Message); } finally { } m2.ReleaseMutex(); m2.Dispose(); }); }
/// <summary> /// Инициализирует последовательный порт фискального регистратора /// </summary> public static async void CashDesk_Init() { try { StartPage.UpdateStartLEDs(StartPage.StartPageInstance.UART1LED, Colors.Yellow); StartPage.UpdateProgress(5); StartPage.AddItemToLogBox("Поиск последовательного порта ККТ..."); string aqs = SerialDevice.GetDeviceSelector(); var dis = await DeviceInformation.FindAllAsync(aqs); foreach (var item in dis) { if (item.Name.Contains("FT232")) { CashDesk.CashDeskDeviceSerialPort = await SerialDevice.FromIdAsync(item.Id); StartPage.CashDeskDeviceID = item.Id; break; } } if (CashDesk.CashDeskDeviceSerialPort == null) { return; } CashDesk.CashDeskDeviceSerialPort.WriteTimeout = TimeSpan.FromMilliseconds(100); CashDesk.CashDeskDeviceSerialPort.ReadTimeout = TimeSpan.FromMilliseconds(100); CashDesk.CashDeskDeviceSerialPort.BaudRate = 9600; CashDesk.CashDeskDeviceSerialPort.Parity = SerialParity.None; CashDesk.CashDeskDeviceSerialPort.StopBits = SerialStopBitCount.One; CashDesk.CashDeskDeviceSerialPort.DataBits = 8; CashDesk.DeviceTypeReceived += CashDesk_DeviceTypeReceived; CashDesk.KKTPrinterStateReceived += CashDesk_KKTPrinterStateReceived; CashDesk.KKTStateReceived += CashDesk_KKTStateReceived; CashDesk.CashDeskCurrentStageParametersReceived += CashDesk_CashDeskCurrentStageParametersReceived; CashDesk.StageStateReceived += CashDesk_StageStateReceived; CashDesk.CurrentModeChanged += CashDesk_CurrentModeChanged; CashDesk.CloseStageResult += CashDesk_CloseStageResult; CashDesk.OpenStageResult += CashDesk_OpenStageResult; CashDesk.OpenReceiptResult += CashDesk_OpenReceiptResult; CashDesk.CancelReceiptResult += CashDesk_CancelReceiptResult; CashDesk.StartReceiptEntryResult += CashDesk_StartReceiptEntryResult; CashDesk.AddEntryDataResult += CashDesk_AddEntryDataResult; CashDesk.ReceiptPaymentResult += CashDesk_ReceiptPaymentResult; CashDesk.CloseReceiptResult += CashDesk_CloseReceiptResult; CashDesk.AllTasksCancelled += CashDesk_AllTasksCancelled; string a = "Последовательный порт ККТ успешно настроен: "; a += CashDesk.CashDeskDeviceSerialPort.BaudRate + "-"; a += CashDesk.CashDeskDeviceSerialPort.DataBits + "-"; a += CashDesk.CashDeskDeviceSerialPort.Parity.ToString() + "-"; a += CashDesk.CashDeskDeviceSerialPort.StopBits; StartPage.AddItemToLogBox(a); while (CashDesk.CashDeskDeviceSerialPort == null) { await Task.Delay(100); } StartPage.AddItemToLogBox("Порт ККТ открыт, ожидание данных..."); StartPage.UpdateStartLEDs(StartPage.StartPageInstance.UART1LED, Colors.Green); CashDesk.StartCommunication(); #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed Task.Run(CashDesk.IncomingKKTDataWatcher, StartPage.GlobalCancellationTokenSource.Token); Task.Run(CashDesk.KKTTaskWatcher, StartPage.GlobalCancellationTokenSource.Token); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed } catch (Exception ex) { StartPage.AddItemToLogBox(ex.Message); } }
/// <summary> /// Считывает данные с ппоследовательного порта шины MDB /// </summary> private static async void ListenMDBSerialPort() { StartPage.UpdateProgress(5); while (true) { try { while (MDBSerialPort == null) { await Task.Delay(100); } StartPage.UpdateStartLEDs(StartPage.StartPageInstance.UART0LED, Colors.Green); StartPage.AddItemToLogBox("Порт MDB открыт, ожидание данных..."); MDBSerialDataReaderObject = new DataReader(MDBSerialPort.InputStream) { InputStreamOptions = InputStreamOptions.Partial }; List <byte> tmpres = new List <byte> { }; while (true) { Task <UInt32> loadAsyncTask = MDBSerialDataReaderObject.LoadAsync(64).AsTask(StartPage.GlobalCancellationTokenSource.Token); UInt32 bytesRead = 0; bytesRead = await loadAsyncTask; if (bytesRead > 0) { byte[] tmpbyte = new byte[bytesRead]; MDBSerialDataReaderObject.ReadBytes(tmpbyte); for (int i = 0; i < tmpbyte.Length; i++) { if ((tmpbyte[i] == '\n') /* || (tmpbyte[tmpbyte.Length - 1] == 10)*/) { byte[] b = tmpres.ToArray(); //Task.Factory.StartNew(() => { ProcessIncomingMDB(b); }); //ProcessIncomingMDB(b); #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed Task.Run(() => { Mutex mut = new Mutex(true, "DataProcessMutex", out bool created); if (!created) { try { mut.WaitOne(); } catch { } } string tmpstr = Encoding.UTF8.GetString(b).Trim(); if (tmpstr == "00 00 00") { return; } tmpstr = tmpstr.Replace("\r", ""); CurrenzaC2Green_ICTA7V7_DataProcess(tmpstr); mut.ReleaseMutex(); mut.Dispose(); }); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed tmpres = new List <byte> { }; } else { tmpres.Add(tmpbyte[i]); } } //CollectMDBData(tmpbyte); //Task.Factory.StartNew(() => { CollectMDBData(tmpbyte); }); } } } catch (TaskCanceledException) { CloseMDBSerialDevice(); } catch (Exception ex) { StartPage.AddItemToLogBox(ex.Message); } finally { if (MDBSerialDataReaderObject != null) { MDBSerialDataReaderObject.DetachStream(); MDBSerialDataReaderObject = null; } } } }