예제 #1
0
        private void MultiSendItemsAdd(object sender, RoutedEventArgs e)
        {
            if (isListening)
            {
                MainPage.Notify("请先暂停发送");
                return;
            }
            Button btn = (sender as Button);
            int    k   = int.Parse(btn.Tag.ToString());

            for (int i = 0; i < listOfSendItems.Count; i++)
            {
                if (listOfSendItems[i].ID == k)
                {
                    k = i;
                    break;
                }
            }
            MultiSendListItem temp = new MultiSendListItem(NumOfSendItems++);

            listOfSendItems.Insert(k, temp);
            //MultiSendListView.ScrollIntoView(temp);
            //refreshListOfItemsID();
            //MultiSendListView.ScrollIntoView(listOfSendItems[listOfSendItems.Count - 1]);
        }
예제 #2
0
        /*
         */
        private async void MultiSendItemButtonClick(object sender, RoutedEventArgs e)
        {
            object            tag      = (sender as Button).Tag;
            int               k        = int.Parse(tag.ToString());
            MultiSendListItem item     = (MultiSendListItem)MultiSendListView.Items[k];
            string            sendText = item.SendText;

            try
            {
                if (!isListening)
                {
                    MainPage.Notify("请保持串口打开状态");
                    return;
                }
                if (serialPort != null)
                {
                    dataWriteObject = new DataWriter(serialPort.OutputStream);
                    await WriteAsync(sendText);
                }
                else
                {
                    MainPage.Notify("请打开串口");
                }
            }
            catch (Exception ex)
            {
                MainPage.Notify("sendTextButton_Click: " + ex.Message);
            }
            finally
            {
                // Cleanup once complete
                if (dataWriteObject != null)
                {
                    dataWriteObject.DetachStream();
                    dataWriteObject = null;
                }
            }
        }