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