Connecting to an ASCII 2 reader
Overview
The TSL ASCII 2 readers support two main modes of use. (see Comparison of Bluetooth modes for TSL ASCII 2 Readers )
- ASCII 2 Protocol
- Keyboard emulation
ASCII 2 Protocol
To get the most use our of our readers use the Technology Solutions UK Ltd ASCII 2 Protocol
The SDK uses the readers in ASCII 2 Protocol mode. You can connect to the reader over Bluetooth or USB. The USB connection has priority over the Bluetooth connection so if a reader is connected via Bluetooth it will be mute/unresponsive over Bluetooth while a USB connection also exists.
Keyboard Emulation
For legacy support environments the TSL ASCII 2 readers also support a keyboard emulation mode. In addition to the Bluetooth HID mode the reader can also support HID over serial for Bluetooth or USB. This is a mixed mode where the reader is still presented as a serial port and responds to ASCII 2 protocol commands but the responses are sent as text rather than ASCII Protocol responses. This HID over serial is enabled using .sh Serial HID Command
Connection APIs
Reader Connection Manager
When the SDK was first released the API used to connect to readers was Reader Connection Manager. This provided a list of Named Readers which could be connected to. Once the Reader Connection Manager had connected to a reader the Connection Transport provided communication with the reader itself
The IReaderConnectionManager provided ListAvailableReadersAsync() to provide a list of INamedReader to connect to.
Once a INamedReader was selected this was passed to the ConnectAsync(INamedReader) method to setup a connection to the reader. If successful the ConnectionTransport provided the IAsciiSerialTransport to the reader.
Changes to the single connection are raised via events through the Reader connection manager
An IAsciiSerialTransport is set as the Transport property of the AsciiCommander
The IReaderConnectionManager should have a single instance per application, created at the start of the application and disposed with the app. The sample application use Galasoft MvvmLight SimpleIoc to provide an instance but this could just be a property on the App class. To get an instance of IReaderConnectionManager You can use a new @TechnologySolutions.Rfid.AsciiProtocol.Extensions.ReaderConnectionManager. This returns a platform specific instance using a 'bait and switch' technique commonly employed with nuget multi platform packages.
ASCII Transports Manager
The preferred API for connection management is built upon the ASCII Transports Manager. The ASCII Transports manager provides two main features
- An Enumerator for each supported Physical Transport (e.g. Bluetooth, USB)
- An event source notifying an application to all changes to ASCII Transports
The ASCII Transports Manager provides ASCII Transport Enumerators which list available ASCII Transports. An ASCII Transport is used to create an ASCII Connection to an ASCII 2 Reader. Changes to any ASCII Transport is reported centrally through the ASCII Transports Manager
The IAsciiTransportsManager instance can be obtained from a singleton instance of @TechnologySolutions.Rfid.AsciiProtocol.Extensions.AsciiTransportsManager (Note the lifecycle registration required for Android).
Once the ASCII Transports Manager created the enumerators should be started with a call to Start() The enumerators will then start reporting available transports via TransportChanged.
Once an IAsciiTransport has been selected a connection is created with a call to ConnectAsync(). Once successful the IAsciiConnection is available from Connection property of the transport