Example #1
0
        private void StopButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                byte[] convertedString = Encoding.Default.GetBytes("CSTOP\r");

                _Serial.Write(convertedString, 0, convertedString.Length);

                Debug.WriteLine("전송 성공!");
            }
            catch
            {
                string           Message = "포트가 닫겨있습니다.\n포트 연결 페이지로 가시겠습니까?";
                string           Title   = "경고";
                MessageBoxButton button  = MessageBoxButton.YesNo;
                MessageBoxImage  image   = MessageBoxImage.Warning;

                MessageBoxResult result = MessageBox.Show(Application.Current.MainWindow, Message, Title, button, image);

                if (result == MessageBoxResult.Yes)
                {
                    ///////////////////////////////////////////////////////
                    ((MainWindow)App.Current.MainWindow).SendButton.Background    = MainWindow.LightGray;
                    ((MainWindow)App.Current.MainWindow).ConnectButton.Background = MainWindow.DarkGray;

                    SettingPage settingPage = new SettingPage();

                    NavigationService.Navigate(settingPage);
                    ////////////////////////////////////////////////////////
                }

                Debug.WriteLine("포트가 닫겨있습니다.");
            }
        }
Example #2
0
        private void DefaultSendButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                byte[] convertedString = Encoding.Default.GetBytes(InputTextBox.Text + "\r");

                byte[] STX = new byte[1] {
                    0x02
                };
                byte[] ETX = new byte[1] {
                    0x03
                };
                byte[] CR = new byte[1] {
                    0x0D
                };
                byte[] LF = new byte[1] {
                    0x0A
                };

                IEnumerable <byte> result = STX.Concat(convertedString).Concat(CR).Concat(LF).Concat(ETX);

                _Serial.Write(result.ToArray(), 0, result.ToArray().Length);

                Debug.WriteLine("전송 성공!");
            }
            catch
            {
                string           Message = "포트가 닫겨있습니다.\n포트 연결 페이지로 가시겠습니까?";
                string           Title   = "경고";
                MessageBoxButton button  = MessageBoxButton.YesNo;
                MessageBoxImage  image   = MessageBoxImage.Warning;

                MessageBoxResult result = MessageBox.Show(Application.Current.MainWindow, Message, Title, button, image);

                if (result == MessageBoxResult.Yes)
                {
                    ((MainWindow)App.Current.MainWindow).SendButton.Background    = MainWindow.LightGray;
                    ((MainWindow)App.Current.MainWindow).ConnectButton.Background = MainWindow.DarkGray;

                    SettingPage settingPage = new SettingPage();

                    NavigationService.Navigate(settingPage);
                }

                Debug.WriteLine("포트가 닫겨있습니다.");
            }
        }