예제 #1
0
 public async void Connect(DeviceListEntry device)
 {
     if (device != null)
     {
         EventHandlerForDevice.CreateNewEventHandlerForDevice();
         EventHandlerForDevice.Current.OnDeviceConnected = this.OnDeviceConnected;
         EventHandlerForDevice.Current.OnDeviceClose     = this.OnDeviceClosing;
         Boolean openSuccess = await EventHandlerForDevice.Current.OpenDeviceAsync(device.DeviceInformation, device.DeviceSelector);
     }
 }
예제 #2
0
 private async void OnDeviceClosing(EventHandlerForDevice sender, DeviceInformation deviceInformation)
 {
     await Dispatcher.RunAsync(
         CoreDispatcherPriority.Normal,
         new DispatchedHandler(() =>
     {
         if (ButtonDisconnectFromDevice.IsEnabled && EventHandlerForDevice.Current.IsEnabledAutoReconnect)
         {
             ButtonDisconnectFromDevice.Content = "Disconnect";
         }
     }));
 }
예제 #3
0
        public void OnDeviceConnected(EventHandlerForDevice sender, DeviceInformation deviceInformation)
        {
            // Find and select our connected device
            if (isAllDevicesEnumerated)
            {
                SelectDeviceInList(EventHandlerForDevice.Current.DeviceInformation.Id);
            }

            if (EventHandlerForDevice.Current.Device.PortName != "")
            {
                EventHandlerForDevice.Current.Device.Parity    = SerialParity.None;
                EventHandlerForDevice.Current.Device.StopBits  = SerialStopBitCount.One;
                EventHandlerForDevice.Current.Device.Handshake = SerialHandshake.None;
                EventHandlerForDevice.Current.Device.DataBits  = 8;
                EventHandlerForDevice.Current.Device.BaudRate  = 115200;

                EventHandlerForDevice.Current.Device.ReadTimeout = new TimeSpan(10 * 10000);
            }
        }
예제 #4
0
        private async void ConnectBtn_Clicked(Object sender, RoutedEventArgs eventArgs)
        {
            var             selection = ConnectDevices.SelectedItems;
            DeviceListEntry entry     = null;

            if (selection.Count > 0)
            {
                var obj = selection[0];
                entry = (DeviceListEntry)obj;

                if (entry != null)
                {
                    EventHandlerForDevice.CreateNewEventHandlerForDevice();
                    EventHandlerForDevice.Current.OnDeviceConnected = this.OnDeviceConnected;
                    EventHandlerForDevice.Current.OnDeviceClose     = this.OnDeviceClosing;
                    Boolean openSuccess = await EventHandlerForDevice.Current.OpenDeviceAsync(entry.DeviceInformation, entry.DeviceSelector);

                    UpdateConnectDisconnectButtonsAndList(!openSuccess);
                }
            }
        }
예제 #5
0
        private void OnDeviceConnected(EventHandlerForDevice sender, DeviceInformation deviceInformation)
        {
            // Find and select our connected device
            if (isAllDevicesEnumerated)
            {
                SelectDeviceInList(EventHandlerForDevice.Current.DeviceInformation.Id);
                ButtonDisconnectFromDevice.Content = "Disconnect";
            }

            if (EventHandlerForDevice.Current.Device.PortName != "")
            {
                EventHandlerForDevice.Current.Device.Parity    = SerialParity.None;
                EventHandlerForDevice.Current.Device.StopBits  = SerialStopBitCount.One;
                EventHandlerForDevice.Current.Device.Handshake = SerialHandshake.None;
                EventHandlerForDevice.Current.Device.DataBits  = 8;
                EventHandlerForDevice.Current.Device.BaudRate  = 115200;
                ResetReadCancellationTokenSource();
                ResetWriteCancellationTokenSource();

                isActive = true;
                EventHandlerForDevice.Current.Device.ReadTimeout = new System.TimeSpan(10 * 10000);
                ReadButton_Click();
            }
        }
예제 #6
0
 public void OnDeviceClosing(EventHandlerForDevice sender, DeviceInformation deviceInformation)
 {
 }
 /// <summary>
 /// Creates a new instance of EventHandlerForDevice, enables auto reconnect, and uses it as the Current instance.
 /// </summary>
 public static void CreateNewEventHandlerForDevice()
 {
     eventHandlerForDevice = new EventHandlerForDevice();
 }