private void ScannerThreadCom(object obj) { TCPCom ThreadCom = (TCPCom)obj; if (!ThreadCom.SetupCom()) { //DebugWrite("Error setting up communication with Scanner."); } else { while (ProgramActive) { string ReceivedData = ThreadCom.UseCom(); if (ReceivedData != "" && ReceivedData != null && ReceivedData.Length > 0) { var newString = ReceivedData.Replace("\u0002", "").Replace("\u0003", ""); StatusBar.Dispatcher.Invoke(() => { StatusBar.Content = ReceivedData; }); PopulateList(newString); } } } }
private void PrinterThreadCom(object obj) { TCPCom ThreadCom = (TCPCom)obj; string ReceivedData; if (!ThreadCom.SetupCom()) { //DebugWrite("Error setting up communication with printer."); } else { while (ProgramActive) { if (tick) { tick = false; ReceivedData = ThreadCom.GetACC(); if (ReceivedData != "" && ReceivedData != null && ReceivedData.Length > 0) { //StatusBar.Dispatcher.Invoke(() => //{ // StatusBar.Content = ReceivedData; //}); } if (ReceivedData.Contains("0A44") && ReceivedData.Length > 15) { if (ReceivedData[14].ToString() == "1") { palletInPosition = true; PalletStatus.Dispatcher.Invoke(() => { PalletStatus.Icon = FontAwesome.WPF.FontAwesomeIcon.CheckCircle; PalletStatus.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#009d58")); }); } else if (ReceivedData[14].ToString() == "0") { palletInPosition = false; printSent = false; PalletStatus.Dispatcher.Invoke(() => { PalletStatus.Icon = FontAwesome.WPF.FontAwesomeIcon.TimesCircle; PalletStatus.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ca0b00")); }); } } if (palletInPosition && !printSent) { SendPrint(); } } } } }
private void MainWindow_Loaded(object sender, RoutedEventArgs e) { ScanCom.SetupCom(); ScanComThread = new Thread(new ParameterizedThreadStart(ScannerThreadCom)); ScanComThread.Start(ScanCom); PrintCom.SetupCom(); PrintComThread = new Thread(new ParameterizedThreadStart(PrinterThreadCom)); PrintComThread.Start(PrintCom); ACCStatusTimer.Tick += ACCStatusTimer_Tick; ACCStatusTimer.Interval = new TimeSpan(0, 0, 2); ACCStatusTimer.Start(); ConStatusTimer.Tick += ConStatusTimer_Tick; ConStatusTimer.Interval = new TimeSpan(0, 0, 2); ConStatusTimer.Start(); PrintDate = DateTime.Now; datePick.SelectedDate = PrintDate; }