Example #1
0
 // <summary>
 /// Given a valid deviceId key string, this method returns a particular <see cref="SerialDeviceDisplay"/> instance.
 /// </summary>
 /// <param name="deviceId">
 /// A unique key that represents a physically connected serial device display.
 /// </param>
 /// <returns>
 /// Returns the <see cref="SerialDeviceDisplay"/> if found, otherwise returns null.
 /// </returns>
 private SerialDeviceDisplay LookupDevice(string deviceId)
 {
     if (this.SerialDeviceDisplays.ContainsKey(deviceId))
     {
         SerialDeviceDisplay serialDeviceDisplay = this.SerialDeviceDisplays[deviceId];
         return(serialDeviceDisplay);
     }
     return(null);
 }
Example #2
0
        /// <summary>
        /// Finds 1 to N connected 4D Systems display modules.
        /// Each display found is identified by a string identifier.
        /// The client app must retain this string identifier in order to use the other class methods.
        /// IMPORTANT TODO:
        /// The client application must add the DeviceCapability to their project's Package.appxmanifest file.
        /// Capability must be defined only once in your app's Package.appxmanifest as follows:
        /// <Capabilities>
        ///     <DeviceCapability Name="serialcommunication">
        ///         <Device Id = "any" >
        ///             <Function Type="name:serialPort" />
        ///         </Device>
        ///     </DeviceCapability>
        /// </Capabilities>
        /// </summary>
        /// <returns>
        /// Returns a <see cref="Task{List{string}}"/> that contains one or more device indentifiers that logically represent serial device displays.
        /// </returns>
        public async Task <List <string> > DiscoverDeviceIds()
        {
            this.SerialDeviceDisplays.Clear();

            string advancedQuerySyntax = SerialDevice.GetDeviceSelector();
            DeviceInformationCollection deviceInformationCollection = await DeviceInformation.FindAllAsync(advancedQuerySyntax);

            var ids = new List <string>();

            foreach (var di in deviceInformationCollection)
            {
                ids.Add(di.Id);

                var device = new SerialDeviceDisplay();

                //Remember each id, as this will be the token for client to use on the adjacent public methods in this class
                this.SerialDeviceDisplays.Add(di.Id, device);
            }

            return(ids);
        }