teotestbluetooth / TestXamConnections / TestXamConnections / Device / Barcode / Honeywell / HoneywellBTReader.cs @ 6e6ea455
Historique | Voir | Annoter | Télécharger (1,435 ko)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Threading.Tasks; |
4 |
using TestXamConnections.Connection; |
5 |
using Xamarin.Forms; |
6 |
|
7 |
namespace TestXamConnections.Device.Barcode.Honeywell |
8 |
{ |
9 |
public class HoneywellBTReader : IBarcodeReader |
10 |
{ |
11 |
public DeviceInfo DeviceI { get; set; } |
12 |
public IConnectionService ConnectionService { get; set; } |
13 |
/// <summary> |
14 |
/// Événement déclenché à la reception de données par le lecteur de code barre Honeywell. |
15 |
/// </summary> |
16 |
public EventHandler<byte[]> BarcodeDataReceivedEvent { get; set; } |
17 |
|
18 |
public HoneywellBTReader(DeviceInfo device) |
19 |
{ |
20 |
DeviceI.Name = device.Name; |
21 |
DeviceI.MACAddress = device.MACAddress; |
22 |
ConnectionService = DependencyService.Get<IConnectionServiceProvider>().GetConnectionServiceInstance(ConnectionType.Bluetooth); |
23 |
ConnectionService.DataReceivedEvent += BluetoothDataReceived; |
24 |
} |
25 |
|
26 |
private void BluetoothDataReceived(object sender, byte[] e) |
27 |
{ |
28 |
BarcodeDataReceivedEvent.Invoke(this, e); |
29 |
} |
30 |
|
31 |
public async Task<bool> ConnectToBTReaderAsync() |
32 |
{ |
33 |
Dictionary<string, string> param = new Dictionary<string, string>() |
34 |
{ |
35 |
{ ConnectionConstants.MAC_ADDR_KEY, DeviceI.MACAddress } |
36 |
}; |
37 |
bool ret = await ConnectionService.Connect(param); |
38 |
return ret; |
39 |
} |
40 |
} |
41 |
} |