Révision 340558f2
TestXamConnections/TestXamConnections.Android/Connection/BluetoothConnectionService.cs | ||
---|---|---|
15 | 15 |
/* Classe permettant d'établir une connection Bluetooth |
16 | 16 |
* Avec socket RFCOMM connecté au SPP |
17 | 17 |
*/ |
18 |
public class BluetoothConnectionService : IConnectionService
|
|
18 |
public class BluetoothConnexionService : IConnexionService
|
|
19 | 19 |
{ |
20 | 20 |
private readonly BluetoothAdapter bluetoothAdapter; |
21 | 21 |
private Thread listeningThread; |
22 | 22 |
private BluetoothSocket socket; |
23 | 23 |
private readonly string sppUUID = "00001101-0000-1000-8000-00805f9b34fb"; |
24 | 24 |
|
25 |
public BluetoothConnectionService()
|
|
25 |
public BluetoothConnexionService()
|
|
26 | 26 |
{ |
27 | 27 |
bluetoothAdapter = BluetoothAdapter.DefaultAdapter; |
28 | 28 |
} |
29 | 29 |
|
30 | 30 |
// Pour le bluetooth, le paramètre de connection est l'addresse MAC |
31 |
public async Task<bool> Connect(Dictionary<string, string> param)
|
|
31 |
public async Task<bool> Connexion(Dictionary<string, string> param)
|
|
32 | 32 |
{ |
33 | 33 |
try |
34 | 34 |
{ |
... | ... | |
39 | 39 |
_ = bluetoothAdapter.CancelDiscovery(); |
40 | 40 |
} |
41 | 41 |
|
42 |
if (param.ContainsKey(ConnectionConstants.MAC_ADDR_KEY))
|
|
42 |
if (param.ContainsKey(ConnexionConstantes.MAC_ADDR_KEY))
|
|
43 | 43 |
{ |
44 |
BluetoothDevice droidBtDevice = bluetoothAdapter.GetRemoteDevice(param[ConnectionConstants.MAC_ADDR_KEY]);
|
|
44 |
BluetoothDevice droidBtDevice = bluetoothAdapter.GetRemoteDevice(param[ConnexionConstantes.MAC_ADDR_KEY]);
|
|
45 | 45 |
if (droidBtDevice != null) |
46 | 46 |
{ |
47 | 47 |
// Si le socket est occupé pour une autre connexion |
... | ... | |
80 | 80 |
return true; |
81 | 81 |
} |
82 | 82 |
|
83 |
public EventHandler<byte[]> DataReceivedEvent { get; set; }
|
|
83 |
public EventHandler<byte[]> DonneesRecuesEvent { get; set; }
|
|
84 | 84 |
|
85 | 85 |
// Fonction d'écoute pour le Thread d'écoute |
86 | 86 |
private async Task ListeningAsync() |
... | ... | |
94 | 94 |
// Resize the byte array |
95 | 95 |
byte[] filledBuffer = buffer.Take(byteAvailable).ToArray(); |
96 | 96 |
// Trigger DataReceivedEvent |
97 |
Application.SynchronizationContext.Post(_ => { DataReceivedEvent.Invoke(this, filledBuffer); }, null);
|
|
97 |
Application.SynchronizationContext.Post(_ => { DonneesRecuesEvent.Invoke(this, filledBuffer); }, null);
|
|
98 | 98 |
} |
99 | 99 |
} |
100 | 100 |
catch (IOException ex) |
... | ... | |
118 | 118 |
return Task.FromResult(true); |
119 | 119 |
} |
120 | 120 |
|
121 |
public Task<bool> SendCommand(byte[] command)
|
|
121 |
public Task<bool> EnvoiCommande(byte[] command)
|
|
122 | 122 |
{ |
123 | 123 |
|
124 | 124 |
if (socket.IsConnected == false) |
TestXamConnections/TestXamConnections.Android/Connection/InternConnectionService.cs | ||
---|---|---|
14 | 14 |
* Pré-installée sur l'appareil |
15 | 15 |
* Basée sur filtrage d'intent sur BroadcastReceiver |
16 | 16 |
*/ |
17 |
public class InternConnectionService : IConnectionService
|
|
17 |
public class InternConnexionService : IConnexionService
|
|
18 | 18 |
{ |
19 |
public EventHandler<byte[]> DataReceivedEvent { get; set; }
|
|
19 |
public EventHandler<byte[]> DonneesRecuesEvent { get; set; }
|
|
20 | 20 |
|
21 | 21 |
private readonly IntentReceiver intentReceiver; |
22 | 22 |
private readonly Context appContext; |
... | ... | |
24 | 24 |
/* La fonction connect dans le cas du connexion en interne |
25 | 25 |
* Est en fait, la configuration de l'IntentReceiver |
26 | 26 |
*/ |
27 |
public Task<bool> Connect(Dictionary<string, string> param)
|
|
27 |
public Task<bool> Connexion(Dictionary<string, string> param)
|
|
28 | 28 |
{ |
29 |
if (param.ContainsKey(ConnectionConstants.RECEIVABLE_INTENTS_KEY))
|
|
29 |
if (param.ContainsKey(ConnexionConstantes.RECEIVABLE_INTENTS_KEY))
|
|
30 | 30 |
{ |
31 | 31 |
// Récupérations des intents recevable sous forme de csv |
32 | 32 |
List<string> intents = new List<string>(); |
33 |
intents.AddRange(param[ConnectionConstants.RECEIVABLE_INTENTS_KEY].Split(","));
|
|
33 |
intents.AddRange(param[ConnexionConstantes.RECEIVABLE_INTENTS_KEY].Split(","));
|
|
34 | 34 |
// Ajout des intents recevable au IntentFilter |
35 | 35 |
IntentFilter intentFilter = new IntentFilter(); |
36 | 36 |
intents.ForEach(intent => intentFilter.AddAction(intent)); |
... | ... | |
44 | 44 |
return Task.FromResult(true); |
45 | 45 |
} |
46 | 46 |
|
47 |
public Task<bool> SendCommand(byte[] commandBytes)
|
|
47 |
public Task<bool> EnvoiCommande(byte[] commandBytes)
|
|
48 | 48 |
{ |
49 | 49 |
string command = Encoding.ASCII.GetString(commandBytes); |
50 | 50 |
Intent launchIntent = appContext.PackageManager.GetLaunchIntentForPackage(command); |
... | ... | |
56 | 56 |
return Task.FromResult(false); |
57 | 57 |
} |
58 | 58 |
|
59 |
public InternConnectionService()
|
|
59 |
public InternConnexionService()
|
|
60 | 60 |
{ |
61 | 61 |
intentReceiver = new IntentReceiver(); |
62 | 62 |
intentReceiver.OnIntentReceived += IntentReceived; |
... | ... | |
68 | 68 |
{ |
69 | 69 |
switch (recIntent.Action) |
70 | 70 |
{ |
71 |
case AgridentConstants.ACTION_AGRIDENT_SUCCESS: |
|
72 |
string readData = recIntent.GetStringExtra(AgridentConstants.KEY_BARCODE_DATA); |
|
73 |
DataReceivedEvent.Invoke(this, Encoding.ASCII.GetBytes(readData));
|
|
71 |
case AgridentConstantes.ACTION_AGRIDENT_SUCCESS:
|
|
72 |
string readData = recIntent.GetStringExtra(AgridentConstantes.KEY_BARCODE_DATA);
|
|
73 |
DonneesRecuesEvent.Invoke(this, Encoding.ASCII.GetBytes(readData));
|
|
74 | 74 |
break; |
75 | 75 |
|
76 |
case AgridentConstants.ACTION_AGRIDENT_ERROR: |
|
77 |
DataReceivedEvent.Invoke(this, Encoding.ASCII.GetBytes(AgridentConstants.ACTION_AGRIDENT_ERROR));
|
|
76 |
case AgridentConstantes.ACTION_AGRIDENT_ERROR:
|
|
77 |
DonneesRecuesEvent.Invoke(this, Encoding.ASCII.GetBytes(AgridentConstantes.ACTION_AGRIDENT_ERROR));
|
|
78 | 78 |
break; |
79 | 79 |
|
80 | 80 |
default: |
TestXamConnections/TestXamConnections.Android/Connection/WifiConnectionService.cs | ||
---|---|---|
8 | 8 |
/* Classe permettant d'établir une connection Wifi |
9 | 9 |
* NON IMPLEMENTEE |
10 | 10 |
*/ |
11 |
public class WifiConnectionService : IConnectionService
|
|
11 |
public class WifiConnexionService : IConnexionService
|
|
12 | 12 |
{ |
13 |
public EventHandler<byte[]> DataReceivedEvent { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
|
13 |
public EventHandler<byte[]> DonneesRecuesEvent { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
|
14 | 14 |
|
15 |
public Task<bool> Connect(Dictionary<string, string> connectParam)
|
|
15 |
public Task<bool> Connexion(Dictionary<string, string> connectParam)
|
|
16 | 16 |
{ |
17 | 17 |
throw new NotImplementedException(); |
18 | 18 |
} |
19 | 19 |
|
20 |
public Task<bool> SendCommand(byte[] hexValues)
|
|
20 |
public Task<bool> EnvoiCommande(byte[] hexValues)
|
|
21 | 21 |
{ |
22 | 22 |
throw new NotImplementedException(); |
23 | 23 |
} |
TestXamConnections/TestXamConnections.Android/Helper/ConnectionServiceProvider.cs | ||
---|---|---|
1 |
using TestXamConnections.Connection; |
|
2 |
using TestXamConnections.Droid.Connection; |
|
3 |
|
|
4 |
namespace TestBLE.Droid.Helper |
|
5 |
{ |
|
6 |
public class ConnectionServiceProvider : IConnectionServiceProvider |
|
7 |
{ |
|
8 |
public IConnectionService GetConnectionServiceInstance(ConnectionType ct) |
|
9 |
{ |
|
10 |
IConnectionService instance = null; |
|
11 |
switch (ct) |
|
12 |
{ |
|
13 |
case ConnectionType.Bluetooth: |
|
14 |
// instance = BluetoothConnectionService.Instance; |
|
15 |
instance = new BluetoothConnectionService(); |
|
16 |
break; |
|
17 |
|
|
18 |
case ConnectionType.Intern: |
|
19 |
instance = new InternConnectionService(); |
|
20 |
break; |
|
21 |
|
|
22 |
case ConnectionType.Wifi: |
|
23 |
instance = new WifiConnectionService(); |
|
24 |
break; |
|
25 |
|
|
26 |
default: |
|
27 |
break; |
|
28 |
} |
|
29 |
|
|
30 |
return instance; |
|
31 |
} |
|
32 |
} |
|
33 |
} |
TestXamConnections/TestXamConnections.Android/Helper/ConnexionServiceFournisseur.cs | ||
---|---|---|
1 |
using TestXamConnections.Connection; |
|
2 |
using TestXamConnections.Droid.Connection; |
|
3 |
|
|
4 |
namespace TestBLE.Droid.Helper |
|
5 |
{ |
|
6 |
public class ConnexionServiceFournisseur : IConnexionServiceFournisseur |
|
7 |
{ |
|
8 |
public IConnexionService GetConnectionServiceInstance(ConnexionType ct) |
|
9 |
{ |
|
10 |
IConnexionService instance = null; |
|
11 |
switch (ct) |
|
12 |
{ |
|
13 |
case ConnexionType.Bluetooth: |
|
14 |
// instance = BluetoothConnectionService.Instance; |
|
15 |
instance = new BluetoothConnexionService(); |
|
16 |
break; |
|
17 |
|
|
18 |
case ConnexionType.Intern: |
|
19 |
instance = new InternConnexionService(); |
|
20 |
break; |
|
21 |
|
|
22 |
case ConnexionType.Wifi: |
|
23 |
instance = new WifiConnexionService(); |
|
24 |
break; |
|
25 |
|
|
26 |
default: |
|
27 |
break; |
|
28 |
} |
|
29 |
|
|
30 |
return instance; |
|
31 |
} |
|
32 |
} |
|
33 |
} |
TestXamConnections/TestXamConnections.Android/MainActivity.cs | ||
---|---|---|
20 | 20 |
|
21 | 21 |
Xamarin.Essentials.Platform.Init(this, savedInstanceState); |
22 | 22 |
Forms.Init(this, savedInstanceState); |
23 |
DependencyService.RegisterSingleton<IConnectionServiceProvider>(new ConnectionServiceProvider());
|
|
23 |
DependencyService.RegisterSingleton<IConnexionServiceFournisseur>(new ConnexionServiceFournisseur());
|
|
24 | 24 |
DependencyService.RegisterSingleton<IBluetoothService>(new BluetoothService()); |
25 | 25 |
LoadApplication(new App()); |
26 | 26 |
} |
TestXamConnections/TestXamConnections.Android/Receivers/BluetoothReceiver.cs | ||
---|---|---|
17 | 17 |
BluetoothDevice foundDevice = intent.GetParcelableExtra(BluetoothDevice.ExtraDevice) as BluetoothDevice; |
18 | 18 |
if (foundDevice != null) |
19 | 19 |
{ |
20 |
var btDevice = new DeviceInfo
|
|
20 |
var btDevice = new InfoAppareil
|
|
21 | 21 |
{ |
22 |
MACAddress = foundDevice.Address,
|
|
23 |
Name = foundDevice.Name
|
|
22 |
AdresseMAC = foundDevice.Address,
|
|
23 |
Nom = foundDevice.Name
|
|
24 | 24 |
}; |
25 | 25 |
} |
26 | 26 |
OnBluetoothDeviceDiscovered.Invoke(this, foundDevice); |
TestXamConnections/TestXamConnections.Android/Services/BluetoothService.cs | ||
---|---|---|
10 | 10 |
{ |
11 | 11 |
private readonly BluetoothAdapter bluetoothAdapter; |
12 | 12 |
|
13 |
public ObservableCollection<DeviceInfo> FoundDevices = new ObservableCollection<DeviceInfo>();
|
|
13 |
public ObservableCollection<InfoAppareil> FoundDevices = new ObservableCollection<InfoAppareil>();
|
|
14 | 14 |
public BluetoothService() |
15 | 15 |
{ |
16 |
FoundDevices = new ObservableCollection<DeviceInfo>();
|
|
16 |
FoundDevices = new ObservableCollection<InfoAppareil>();
|
|
17 | 17 |
bluetoothAdapter = BluetoothAdapter.DefaultAdapter; |
18 | 18 |
} |
19 | 19 |
|
20 |
public ICollection<DeviceInfo> GetBondedDevices()
|
|
20 |
public ICollection<InfoAppareil> GetBondedDevices()
|
|
21 | 21 |
{ |
22 |
ICollection<DeviceInfo> ret = new ObservableCollection<DeviceInfo>();
|
|
22 |
ICollection<InfoAppareil> ret = new ObservableCollection<InfoAppareil>();
|
|
23 | 23 |
foreach (BluetoothDevice bondedDevice in bluetoothAdapter.BondedDevices) |
24 | 24 |
{ |
25 |
DeviceInfo toAddItem = new DeviceInfo
|
|
25 |
InfoAppareil toAddItem = new InfoAppareil
|
|
26 | 26 |
{ |
27 |
MACAddress = bondedDevice.Address,
|
|
28 |
Name = bondedDevice.Name
|
|
27 |
AdresseMAC = bondedDevice.Address,
|
|
28 |
Nom = bondedDevice.Name
|
|
29 | 29 |
}; |
30 | 30 |
ret.Add(toAddItem); |
31 | 31 |
} |
TestXamConnections/TestXamConnections.Android/TestXamConnections.Android.csproj | ||
---|---|---|
63 | 63 |
</ItemGroup> |
64 | 64 |
<ItemGroup> |
65 | 65 |
<Compile Include="Connection\BluetoothConnectionService.cs" /> |
66 |
<Compile Include="Helper\ConnectionServiceProvider.cs" />
|
|
66 |
<Compile Include="Helper\ConnexionServiceFournisseur.cs" />
|
|
67 | 67 |
<Compile Include="Connection\InternConnectionService.cs" /> |
68 | 68 |
<Compile Include="Connection\WifiConnectionService.cs" /> |
69 | 69 |
<Compile Include="MainActivity.cs" /> |
TestXamConnections/TestXamConnections/Connection/ConnectionConstants.cs | ||
---|---|---|
1 |
namespace TestXamConnections.Connection |
|
2 |
{ |
|
3 |
/// <summary> |
|
4 |
/// Constantes de connexion à utiliser lors de l'utilisation |
|
5 |
/// de la fonction Connect de IConnection Service |
|
6 |
/// </summary> |
|
7 |
public static class ConnectionConstants |
|
8 |
{ |
|
9 |
public static readonly string MAC_ADDR_KEY = "mac_address"; |
|
10 |
// public static readonly string LAUNCH_INTENT_KEY = "launch_intent"; |
|
11 |
public static readonly string RECEIVABLE_INTENTS_KEY = "receivable_intents"; |
|
12 |
|
|
13 |
} |
|
14 |
} |
TestXamConnections/TestXamConnections/Connection/ConnexionConstantes.cs | ||
---|---|---|
1 |
namespace TestXamConnections.Connection |
|
2 |
{ |
|
3 |
/// <summary> |
|
4 |
/// Constantes de connexion à utiliser lors de l'utilisation |
|
5 |
/// de la fonction Connect de IConnection Service |
|
6 |
/// </summary> |
|
7 |
public static class ConnexionConstantes |
|
8 |
{ |
|
9 |
public static readonly string MAC_ADDR_KEY = "mac_address"; |
|
10 |
// public static readonly string LAUNCH_INTENT_KEY = "launch_intent"; |
|
11 |
public static readonly string RECEIVABLE_INTENTS_KEY = "receivable_intents"; |
|
12 |
|
|
13 |
} |
|
14 |
} |
TestXamConnections/TestXamConnections/Connection/IConnectionService.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Threading.Tasks; |
|
4 |
|
|
5 |
namespace TestXamConnections.Connection |
|
6 |
{ |
|
7 |
public interface IConnectionService |
|
8 |
{ |
|
9 |
/// <summary> |
|
10 |
/// Fonction de connexion à la fonctionnalité cible. |
|
11 |
/// </summary> |
|
12 |
/// <param name="connectParam">Paramètre de connection.\nPour Bluetooth, addresse MAC.\n |
|
13 |
/// Pour connexion interne, les intents recevables (ajoutés à un IntentFilter).</param> |
|
14 |
/// <returns>true si la connexion a réussi, false sinon.</returns> |
|
15 |
Task<bool> Connect(Dictionary<string, string> connectParam); |
|
16 |
|
|
17 |
/// <summary> |
|
18 |
/// Fonction d'envoi de commande pour le bluetooth |
|
19 |
/// </summary> |
|
20 |
/// <param name="hexValues">Données à envoyer sous forme de tableau d'octets</param> |
|
21 |
/// <returns>true si la commande s'est bien envoyée, false sinon.</returns> |
|
22 |
Task<bool> SendCommand(byte[] hexValues); |
|
23 |
|
|
24 |
/// <summary> |
|
25 |
/// Événement déclenché à la réception de données. Présente les donénes sous forme d’un tableau d’octets. |
|
26 |
/// </summary> |
|
27 |
EventHandler<byte[]> DataReceivedEvent { get; set; } |
|
28 |
} |
|
29 |
} |
TestXamConnections/TestXamConnections/Connection/IConnectionServiceProvider.cs | ||
---|---|---|
1 |
namespace TestXamConnections.Connection |
|
2 |
{ |
|
3 |
/// <summary> |
|
4 |
/// Type de connection service à demander. |
|
5 |
/// </summary> |
|
6 |
public enum ConnectionType |
|
7 |
{ |
|
8 |
Bluetooth, |
|
9 |
Intern, |
|
10 |
Wifi |
|
11 |
} |
|
12 |
|
|
13 |
public interface IConnectionServiceProvider |
|
14 |
{ |
|
15 |
IConnectionService GetConnectionServiceInstance(ConnectionType ct); |
|
16 |
} |
|
17 |
} |
TestXamConnections/TestXamConnections/Connection/IConnexionService.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Threading.Tasks; |
|
4 |
|
|
5 |
namespace TestXamConnections.Connection |
|
6 |
{ |
|
7 |
public interface IConnexionService |
|
8 |
{ |
|
9 |
/// <summary> |
|
10 |
/// Fonction de connexion à la fonctionnalité cible. |
|
11 |
/// </summary> |
|
12 |
/// <param name="connectParam">Paramètre de connexion.\nPour Bluetooth, addresse MAC.\n |
|
13 |
/// Pour connexion interne, les intents recevables (ajoutés à un IntentFilter).</param> |
|
14 |
/// <returns>true si la connexion a réussi, false sinon.</returns> |
|
15 |
Task<bool> Connexion(Dictionary<string, string> connectParam); |
|
16 |
|
|
17 |
/// <summary> |
|
18 |
/// Fonction d'envoi de commande pour le bluetooth |
|
19 |
/// </summary> |
|
20 |
/// <param name="hexValues">Données à envoyer sous forme de tableau d'octets</param> |
|
21 |
/// <returns>true si la commande s'est bien envoyée, false sinon.</returns> |
|
22 |
Task<bool> EnvoiCommande(byte[] hexValues); |
|
23 |
|
|
24 |
/// <summary> |
|
25 |
/// Événement déclenché à la réception de données. Présente les donénes sous forme d’un tableau d’octets. |
|
26 |
/// </summary> |
|
27 |
EventHandler<byte[]> DonneesRecuesEvent { get; set; } |
|
28 |
} |
|
29 |
} |
TestXamConnections/TestXamConnections/Connection/IConnexionServiceFournisseur.cs | ||
---|---|---|
1 |
namespace TestXamConnections.Connection |
|
2 |
{ |
|
3 |
/// <summary> |
|
4 |
/// Type de connection service à demander. |
|
5 |
/// </summary> |
|
6 |
public enum ConnexionType |
|
7 |
{ |
|
8 |
Bluetooth, |
|
9 |
Intern, |
|
10 |
Wifi |
|
11 |
} |
|
12 |
|
|
13 |
public interface IConnexionServiceFournisseur |
|
14 |
{ |
|
15 |
IConnexionService GetConnectionServiceInstance(ConnexionType ct); |
|
16 |
} |
|
17 |
} |
TestXamConnections/TestXamConnections/Device/Balance/BalanceFournisseur.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Text; |
|
4 |
using TestXamConnections.Connection; |
|
5 |
using TestXamConnections.Device.Balance.Balea; |
|
6 |
|
|
7 |
namespace TestXamConnections.Device.Balance |
|
8 |
{ |
|
9 |
public enum Balance |
|
10 |
{ |
|
11 |
TeoBalance |
|
12 |
} |
|
13 |
|
|
14 |
public static class BalanceFournisseur |
|
15 |
{ |
|
16 |
public static IBalance GetBalance(Balance b, ConnexionType ct, InfoAppareil deviceI) |
|
17 |
{ |
|
18 |
return b switch |
|
19 |
{ |
|
20 |
Balance.TeoBalance => new TeoBalance(deviceI), |
|
21 |
_ => null, |
|
22 |
}; |
|
23 |
} |
|
24 |
} |
|
25 |
} |
TestXamConnections/TestXamConnections/Device/Balance/BalanceProvider.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Text; |
|
4 |
using TestXamConnections.Connection; |
|
5 |
using TestXamConnections.Device.Balance.Balea; |
|
6 |
|
|
7 |
namespace TestXamConnections.Device.Balance |
|
8 |
{ |
|
9 |
public enum Balance |
|
10 |
{ |
|
11 |
TeoBalance |
|
12 |
} |
|
13 |
|
|
14 |
public static class BalanceProvider |
|
15 |
{ |
|
16 |
public static IBalance GetBalance(Balance b, ConnectionType ct, DeviceInfo deviceI) |
|
17 |
{ |
|
18 |
return b switch |
|
19 |
{ |
|
20 |
Balance.TeoBalance => new TeoBalance(deviceI), |
|
21 |
_ => null, |
|
22 |
}; |
|
23 |
} |
|
24 |
} |
|
25 |
} |
TestXamConnections/TestXamConnections/Device/Balance/Balea/TeoBalance.cs | ||
---|---|---|
4 | 4 |
using System.Text; |
5 | 5 |
using System.Threading.Tasks; |
6 | 6 |
using TestXamConnections.Connection; |
7 |
using TestXamConnections.Models; |
|
8 | 7 |
using Xamarin.Forms; |
9 | 8 |
|
10 | 9 |
namespace TestXamConnections.Device.Balance.Balea |
11 | 10 |
{ |
12 | 11 |
public class TeoBalance : IBalance |
13 | 12 |
{ |
14 |
public DeviceInfo DeviceI { get; set; }
|
|
15 |
public IConnectionService ConnectionService { get; set; }
|
|
16 |
public EventHandler<ReponsePesee> PeseeReceivedEvent { get; set; }
|
|
13 |
public InfoAppareil AppareilInfos { get; set; }
|
|
14 |
public IConnexionService ConnexionService { get; set; }
|
|
15 |
public EventHandler<ReponsePesee> PeseeRecueEvent { get; set; }
|
|
17 | 16 |
|
18 |
public TeoBalance(DeviceInfo deviceI)
|
|
17 |
public TeoBalance(InfoAppareil deviceI)
|
|
19 | 18 |
{ |
20 |
DeviceI = deviceI;
|
|
21 |
ConnectionService = DependencyService.Get<IConnectionServiceProvider>().GetConnectionServiceInstance(ConnectionType.Bluetooth);
|
|
22 |
ConnectionService.DataReceivedEvent += TeoDataReceived;
|
|
19 |
AppareilInfos = deviceI;
|
|
20 |
ConnexionService = DependencyService.Get<IConnexionServiceFournisseur>().GetConnectionServiceInstance(ConnexionType.Bluetooth);
|
|
21 |
ConnexionService.DonneesRecuesEvent += TeoDataReceived;
|
|
23 | 22 |
} |
24 | 23 |
|
25 | 24 |
~TeoBalance() |
26 | 25 |
{ |
27 |
ConnectionService.DataReceivedEvent -= TeoDataReceived;
|
|
26 |
ConnexionService.DonneesRecuesEvent -= TeoDataReceived;
|
|
28 | 27 |
} |
29 | 28 |
|
30 | 29 |
/* |
... | ... | |
67 | 66 |
// Trigger evènement en fonction de la trame |
68 | 67 |
if (_bufferedData.Length == 12) |
69 | 68 |
{ |
70 |
PeseeReceivedEvent.Invoke(this, new ReponsePesee(_bufferedData));
|
|
69 |
PeseeRecueEvent.Invoke(this, new ReponsePesee(_bufferedData));
|
|
71 | 70 |
} |
72 | 71 |
else if (_bufferedData[2] == '6') |
73 | 72 |
{ |
74 |
PeseeReceivedEvent.Invoke(this, new ReponsePesee("err"));
|
|
73 |
PeseeRecueEvent.Invoke(this, new ReponsePesee("err"));
|
|
75 | 74 |
} |
76 | 75 |
else |
77 | 76 |
{ |
78 |
PeseeReceivedEvent.Invoke(this, new ReponsePesee("err"));
|
|
77 |
PeseeRecueEvent.Invoke(this, new ReponsePesee("err"));
|
|
79 | 78 |
} |
80 | 79 |
} |
81 | 80 |
} |
... | ... | |
85 | 84 |
/// Important : le bluetooth doit être activé, la balance allumée et les appareils doivent déjà être appairés. |
86 | 85 |
/// </summary> |
87 | 86 |
/// <returns>true si la connection a réussi, false sinon.</returns> |
88 |
public async Task<bool> ConnectToBalanceAsync()
|
|
87 |
public async Task<bool> ConnexionBalanceAsync()
|
|
89 | 88 |
{ |
90 | 89 |
Dictionary<string, string> param = new Dictionary<string, string>() |
91 | 90 |
{ |
92 |
{ ConnectionConstants.MAC_ADDR_KEY, DeviceI.MACAddress }
|
|
91 |
{ ConnexionConstantes.MAC_ADDR_KEY, AppareilInfos.AdresseMAC }
|
|
93 | 92 |
}; |
94 |
return await ConnectionService.Connect(param);
|
|
93 |
return await ConnexionService.Connexion(param);
|
|
95 | 94 |
} |
96 | 95 |
|
97 | 96 |
/// <summary> |
... | ... | |
99 | 98 |
/// </summary> |
100 | 99 |
/// <param name="commandType">La commande à envoyer.</param> |
101 | 100 |
/// <returns>true si l'envoi a réussi, false sinon.</returns> |
102 |
public async Task<bool> SendCommandAsync(TeoConstants.TeoCommandType cmd)
|
|
101 |
public async Task<bool> EnvoiCommandeAsync(TeoConstantes.TeoCommandeType cmd)
|
|
103 | 102 |
{ |
104 |
byte[] commandValue = TeoConstants.TeoCommandValues.GetValueOrDefault(cmd); |
|
105 |
return await ConnectionService.SendCommand(commandValue);
|
|
103 |
byte[] commandValue = TeoConstantes.TeoCommandValues.GetValueOrDefault(cmd);
|
|
104 |
return await ConnexionService.EnvoiCommande(commandValue);
|
|
106 | 105 |
} |
107 | 106 |
|
108 | 107 |
/// <summary> |
109 | 108 |
/// Envoie d'une commande d'émission de poids au Teo. |
110 | 109 |
/// </summary> |
111 | 110 |
/// <returns>true si l'envoi a réussi, false sinon.</returns> |
112 |
public async Task<bool> ReadWeightAsync()
|
|
111 |
public async Task<bool> LirePeseeAsync()
|
|
113 | 112 |
{ |
114 |
byte[] commandValue = TeoConstants.TeoCommandValues.GetValueOrDefault(TeoConstants.TeoCommandType.EmissionPoids);
|
|
115 |
return await ConnectionService.SendCommand(commandValue);
|
|
113 |
byte[] commandValue = TeoConstantes.TeoCommandValues.GetValueOrDefault(TeoConstantes.TeoCommandeType.EmissionPoids);
|
|
114 |
return await ConnexionService.EnvoiCommande(commandValue);
|
|
116 | 115 |
} |
117 | 116 |
|
118 | 117 |
} |
TestXamConnections/TestXamConnections/Device/Balance/Balea/TeoConstantes.cs | ||
---|---|---|
1 |
using System.Collections.Generic; |
|
2 |
|
|
3 |
namespace TestXamConnections.Device.Balance.Balea |
|
4 |
{ |
|
5 |
public static class TeoConstantes |
|
6 |
{ |
|
7 |
/// <summary> |
|
8 |
/// Liste des commandes disponibles pour la balance Teo, pour le programme INRAE. |
|
9 |
/// </summary> |
|
10 |
public enum TeoCommandeType |
|
11 |
{ |
|
12 |
// Voir documentation TEO INRAE |
|
13 |
// Codes ASCII |
|
14 |
ModeOrdre, |
|
15 |
SortieOrdre, |
|
16 |
EmissionPoids, |
|
17 |
ModePeseeSimple, |
|
18 |
SortiePeseeSimple |
|
19 |
} |
|
20 |
|
|
21 |
public static readonly Dictionary<TeoCommandeType, string> TeoCommandNames = new Dictionary<TeoCommandeType, string>() |
|
22 |
{ |
|
23 |
{ TeoCommandeType.ModeOrdre, "Mode attente ordre" }, |
|
24 |
{ TeoCommandeType.SortieOrdre, "Sortie mode ordre" }, |
|
25 |
{ TeoCommandeType.EmissionPoids, "Emission poids" }, |
|
26 |
{ TeoCommandeType.ModePeseeSimple, "Mode simple pesage" }, |
|
27 |
{ TeoCommandeType.SortiePeseeSimple, "Sortie mode simple pesage" } |
|
28 |
|
|
29 |
}; |
|
30 |
|
|
31 |
public static readonly Dictionary<TeoCommandeType, byte[]> TeoCommandValues = new Dictionary<TeoCommandeType, byte[]>() |
|
32 |
{ |
|
33 |
{ TeoCommandeType.ModeOrdre, new byte[] { 0x02, 0x61, 0x0D } }, |
|
34 |
{ TeoCommandeType.SortieOrdre, new byte[] { 0x02, 0x6B, 0x0D } }, |
|
35 |
{ TeoCommandeType.EmissionPoids, new byte[] { 0x02, 0x63, 0x0D } }, |
|
36 |
{ TeoCommandeType.ModePeseeSimple, new byte[] { 0x02, 0x62, 0x0D } }, |
|
37 |
{ TeoCommandeType.SortiePeseeSimple, new byte[] { 0x02, 0x65, 0x0D } } |
|
38 |
}; |
|
39 |
} |
|
40 |
} |
TestXamConnections/TestXamConnections/Device/Balance/Balea/TeoConstants.cs | ||
---|---|---|
1 |
using System.Collections.Generic; |
|
2 |
|
|
3 |
namespace TestXamConnections.Device.Balance.Balea |
|
4 |
{ |
|
5 |
public static class TeoConstants |
|
6 |
{ |
|
7 |
/// <summary> |
|
8 |
/// Liste des commandes disponibles pour la balance Teo, pour le programme INRAE. |
|
9 |
/// </summary> |
|
10 |
public enum TeoCommandType |
|
11 |
{ |
|
12 |
// Voir documentation TEO INRAE |
|
13 |
// Codes ASCII |
|
14 |
ModeOrdre, |
|
15 |
SortieOrdre, |
|
16 |
EmissionPoids, |
|
17 |
ModePeseeSimple, |
|
18 |
SortiePeseeSimple |
|
19 |
} |
|
20 |
|
|
21 |
public static readonly Dictionary<TeoCommandType, string> TeoCommandNames = new Dictionary<TeoCommandType, string>() |
|
22 |
{ |
|
23 |
{ TeoCommandType.ModeOrdre, "Mode attente ordre" }, |
|
24 |
{ TeoCommandType.SortieOrdre, "Sortie mode ordre" }, |
|
25 |
{ TeoCommandType.EmissionPoids, "Emission poids" }, |
|
26 |
{ TeoCommandType.ModePeseeSimple, "Mode simple pesage" }, |
|
27 |
{ TeoCommandType.SortiePeseeSimple, "Sortie mode simple pesage" } |
|
28 |
|
|
29 |
}; |
|
30 |
|
|
31 |
public static readonly Dictionary<TeoCommandType, byte[]> TeoCommandValues = new Dictionary<TeoCommandType, byte[]>() |
|
32 |
{ |
|
33 |
{ TeoCommandType.ModeOrdre, new byte[] { 0x02, 0x61, 0x0D } }, |
|
34 |
{ TeoCommandType.SortieOrdre, new byte[] { 0x02, 0x6B, 0x0D } }, |
|
35 |
{ TeoCommandType.EmissionPoids, new byte[] { 0x02, 0x63, 0x0D } }, |
|
36 |
{ TeoCommandType.ModePeseeSimple, new byte[] { 0x02, 0x62, 0x0D } }, |
|
37 |
{ TeoCommandType.SortiePeseeSimple, new byte[] { 0x02, 0x65, 0x0D } } |
|
38 |
}; |
|
39 |
} |
|
40 |
} |
TestXamConnections/TestXamConnections/Device/Balance/IBalance.cs | ||
---|---|---|
1 | 1 |
using System; |
2 | 2 |
using System.Threading.Tasks; |
3 |
using TestXamConnections.Models; |
|
4 |
using static TestXamConnections.Device.Balance.Balea.TeoConstants; |
|
3 |
using static TestXamConnections.Device.Balance.Balea.TeoConstantes; |
|
5 | 4 |
|
6 | 5 |
namespace TestXamConnections.Device.Balance |
7 | 6 |
{ |
8 |
public interface IBalance : IDevice
|
|
7 |
public interface IBalance : IAppareil
|
|
9 | 8 |
{ |
10 | 9 |
/// <summary> |
11 | 10 |
/// Événement déclenché à la reception d'une pesée de la part du Teo. |
12 | 11 |
/// </summary> |
13 |
EventHandler<ReponsePesee> PeseeReceivedEvent { get; set; }
|
|
12 |
EventHandler<ReponsePesee> PeseeRecueEvent { get; set; }
|
|
14 | 13 |
|
15 | 14 |
/// <summary> |
16 | 15 |
/// Permet d’établir une connection bluetooth avec une balance. |
17 | 16 |
/// Important : le bluetooth doit être activé, la balance allumée et les appareils doivent déjà être appairés. |
18 | 17 |
/// </summary> |
19 | 18 |
/// <returns>true si la connection a réussi, false sinon.</returns> |
20 |
Task<bool> ConnectToBalanceAsync();
|
|
19 |
Task<bool> ConnexionBalanceAsync();
|
|
21 | 20 |
|
22 | 21 |
// <summary> |
23 | 22 |
/// Envoie d'une commande à la balance. |
24 | 23 |
/// </summary> |
25 | 24 |
/// <param name="commandType">La commande à envoyer.</param> |
26 | 25 |
/// <returns></returns> |
27 |
Task<bool> SendCommandAsync(TeoCommandType cmd);
|
|
26 |
Task<bool> EnvoiCommandeAsync(TeoCommandeType cmd);
|
|
28 | 27 |
|
29 | 28 |
// <summary> |
30 | 29 |
/// Envoie d'une commande de pesée simple à la balance. |
31 | 30 |
/// </summary> |
32 | 31 |
/// <param name="commandType">La commande à envoyer.</param> |
33 | 32 |
/// <returns></returns> |
34 |
Task<bool> ReadWeightAsync();
|
|
33 |
Task<bool> LirePeseeAsync();
|
|
35 | 34 |
|
36 | 35 |
} |
37 | 36 |
} |
TestXamConnections/TestXamConnections/Device/Balance/ReponsePesee.cs | ||
---|---|---|
1 |
using System.Linq; |
|
2 |
|
|
3 |
namespace TestXamConnections.Device.Balance |
|
4 |
{ |
|
5 |
public class ReponsePesee |
|
6 |
{ |
|
7 |
|
|
8 |
private bool err; |
|
9 |
/// <summary> |
|
10 |
/// Indicateur si erreur de pesée |
|
11 |
/// </summary> |
|
12 |
public bool Err |
|
13 |
{ |
|
14 |
get => err; |
|
15 |
set => err = value; |
|
16 |
} |
|
17 |
|
|
18 |
|
|
19 |
private int numPlateau; |
|
20 |
/// <summary> |
|
21 |
/// Le numéro du plateau. |
|
22 |
/// </summary> |
|
23 |
public int NumPlateau |
|
24 |
{ |
|
25 |
get => numPlateau; |
|
26 |
set => numPlateau = value; |
|
27 |
} |
|
28 |
|
|
29 |
private int typePlateau; |
|
30 |
/// <summary> |
|
31 |
/// Le type du plateau. |
|
32 |
/// </summary> |
|
33 |
public int TypePlateau |
|
34 |
{ |
|
35 |
get => typePlateau; |
|
36 |
set => typePlateau = value; |
|
37 |
} |
|
38 |
|
|
39 |
private string poidsMesure; |
|
40 |
/// <summary> |
|
41 |
/// Le poids mesuré, en kilogramme. |
|
42 |
/// </summary> |
|
43 |
public string PoidsMesure |
|
44 |
{ |
|
45 |
get => poidsMesure; |
|
46 |
set => poidsMesure = value; |
|
47 |
} |
|
48 |
|
|
49 |
private bool estNegatif; |
|
50 |
/// <summary> |
|
51 |
/// Indique si le poids mesurée est négatif. True = poids négatif. |
|
52 |
/// </summary> |
|
53 |
public bool EstNegative |
|
54 |
{ |
|
55 |
get => estNegatif; |
|
56 |
set => estNegatif = value; |
|
57 |
} |
|
58 |
|
|
59 |
public ReponsePesee(string data) |
|
60 |
{ |
|
61 |
if (data == "err") |
|
62 |
{ |
|
63 |
Err = true; |
|
64 |
} |
|
65 |
else |
|
66 |
{ |
|
67 |
// Voir doc Balance Teo INRAE |
|
68 |
NumPlateau = int.Parse(data[0].ToString()); |
|
69 |
TypePlateau = int.Parse(data[1].ToString()); |
|
70 |
EstNegative = data[4] == '-'; |
|
71 |
PoidsMesure = new string(data.Skip(5).ToArray()).Trim(); |
|
72 |
|
|
73 |
} |
|
74 |
} |
|
75 |
} |
|
76 |
} |
TestXamConnections/TestXamConnections/Device/Barcode/BarcodeReaderProvider.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Text; |
|
4 |
using TestXamConnections.Connection; |
|
5 |
using TestXamConnections.Device.Barcode.Honeywell; |
|
6 |
|
|
7 |
namespace TestXamConnections.Device.Barcode |
|
8 |
{ |
|
9 |
public enum BarcodeDevice |
|
10 |
{ |
|
11 |
HoneywellIntern, |
|
12 |
HoneywellBT |
|
13 |
} |
|
14 |
|
|
15 |
public static class BarcodeReaderProvider |
|
16 |
{ |
|
17 |
public static IBarcodeReader GetBarcodeReader(BarcodeDevice d, ConnectionType ct, DeviceInfo deviceI) |
|
18 |
{ |
|
19 |
return d switch |
|
20 |
{ |
|
21 |
BarcodeDevice.HoneywellIntern => new HoneywellInternReader(deviceI), |
|
22 |
BarcodeDevice.HoneywellBT => new HoneywellBTReader(deviceI), |
|
23 |
_ => null, |
|
24 |
}; |
|
25 |
} |
|
26 |
} |
|
27 |
} |
TestXamConnections/TestXamConnections/Device/Barcode/Honeywell/HoneyWellConstantes.cs | ||
---|---|---|
1 |
namespace TestXamConnections.Device.Barcode.Honeywell |
|
2 |
{ |
|
3 |
/// <summary> |
|
4 |
/// Constantes utilisées pour la communication avec le module Barcode Honeywell interne au C-One². |
|
5 |
/// </summary> |
|
6 |
public static class HoneyWellConstantes |
|
7 |
{ |
|
8 |
public const string ACTION_SCAN = "fr.coppernic.intent.action.SCAN"; |
|
9 |
public const string ACTION_STOP_SCAN = "fr.coppernic.intent.action.STOP"; |
|
10 |
public const string ACTION_SCAN_SUCCESS = "fr.coppernic.intent.scansuccess"; |
|
11 |
public const string ACTION_SCAN_ERROR = "fr.coppernic.intent.scanfailed"; |
|
12 |
public const string HONEYWELL_BARCODE = "fr.coppernic.features.barcode.conen"; |
|
13 |
} |
|
14 |
} |
TestXamConnections/TestXamConnections/Device/Barcode/Honeywell/HoneyWellConstants.cs | ||
---|---|---|
1 |
namespace TestXamConnections.Device.Barcode.Honeywell |
|
2 |
{ |
|
3 |
/// <summary> |
|
4 |
/// Constantes utilisées pour la communication avec le module Barcode Honeywell interne au C-One². |
|
5 |
/// </summary> |
|
6 |
public static class HoneyWellConstants |
|
7 |
{ |
|
8 |
public const string ACTION_SCAN = "fr.coppernic.intent.action.SCAN"; |
|
9 |
public const string ACTION_STOP_SCAN = "fr.coppernic.intent.action.STOP"; |
|
10 |
public const string ACTION_SCAN_SUCCESS = "fr.coppernic.intent.scansuccess"; |
|
11 |
public const string ACTION_SCAN_ERROR = "fr.coppernic.intent.scanfailed"; |
|
12 |
public const string HONEYWELL_BARCODE = "fr.coppernic.features.barcode.conen"; |
|
13 |
} |
|
14 |
} |
TestXamConnections/TestXamConnections/Device/Barcode/Honeywell/HoneywellBTReader.cs | ||
---|---|---|
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 |
} |
TestXamConnections/TestXamConnections/Device/Barcode/Honeywell/HoneywellInternReader.cs | ||
---|---|---|
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 HoneywellInternReader : IBarcodeReader |
|
11 |
{ |
|
12 |
public DeviceInfo DeviceI { get; set; } |
|
13 |
public IConnectionService ConnectionService { get; set; } |
|
14 |
|
|
15 |
/// <summary> |
|
16 |
/// Événement déclenché à la reception de données par le lecteur Honeywell . |
|
17 |
/// </summary> |
|
18 |
public EventHandler<string> BarcodeDataReceivedEvent { get; set; } |
|
19 |
|
|
20 |
public HoneywellInternReader(DeviceInfo deviceI) |
|
21 |
{ |
|
22 |
DeviceI = deviceI; |
|
23 |
ConnectionService = DependencyService.Get<IConnectionServiceProvider>().GetConnectionServiceInstance(ConnectionType.Intern); |
|
24 |
ConnectionService.DataReceivedEvent += InternDataReceived; |
|
25 |
} |
|
26 |
|
|
27 |
private void InternDataReceived(object sender, byte[] intent) |
|
28 |
{ |
|
29 |
string data = Encoding.ASCII.GetString(intent); |
|
30 |
data = data == HoneyWellConstants.ACTION_SCAN_ERROR ? "err" : data; |
|
31 |
BarcodeDataReceivedEvent.Invoke(this, data); |
|
32 |
} |
|
33 |
|
|
34 |
|
|
35 |
/// <summary> |
|
36 |
/// Initialise la lecture de code barre avec lecteur interne Honeywell. |
|
37 |
/// </summary> |
|
38 |
/// <returns>true la connexion a réussi, false sinon.</returns> |
|
39 |
public async Task<bool> EnableServiceAsync() |
|
40 |
{ |
|
41 |
bool ret; |
|
42 |
// Enregistrement des intents recevable par Agrident |
|
43 |
List<string> intentsList = new List<string>() |
|
44 |
{ |
|
45 |
HoneyWellConstants.ACTION_SCAN_SUCCESS, |
|
46 |
HoneyWellConstants.ACTION_SCAN_ERROR |
|
47 |
}; |
|
48 |
string intents = string.Join(',', intentsList); |
|
49 |
|
|
50 |
// Encapsulation des intents recevables pour envoyer au service de connexion |
|
51 |
Dictionary<string, string> param = new Dictionary<string, string>() |
|
52 |
{ |
|
53 |
{ ConnectionConstants.RECEIVABLE_INTENTS_KEY, intents } |
|
54 |
}; |
|
55 |
|
|
56 |
ret = await ConnectionService.Connect(param); |
|
57 |
return ret; |
|
58 |
} |
|
59 |
|
|
60 |
/// <summary> |
|
61 |
/// Lance un scan de code barre avec le lecteur Honeywell interne. |
|
62 |
/// Important : Il faut d'abord |
|
63 |
/// </summary> |
|
64 |
/// <returns>true si le scan s'est lancé correctement, false sinon.</returns> |
|
65 |
public async Task<bool> StartScanAsync() |
|
66 |
{ |
|
67 |
byte[] startIntentBytes = Encoding.ASCII.GetBytes(HoneyWellConstants.HONEYWELL_BARCODE); |
|
68 |
return await ConnectionService.SendCommand(startIntentBytes); |
|
69 |
} |
|
70 |
} |
|
71 |
} |
TestXamConnections/TestXamConnections/Device/Barcode/Honeywell/HoneywellLecteurBT.cs | ||
---|---|---|
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 HoneywellLecteurBT : ILecteurCodeBarre |
|
11 |
{ |
|
12 |
public InfoAppareil AppareilInfos { get; set; } |
|
13 |
public IConnexionService ConnexionService { 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> CBDonneesRecuesEvent { get; set; } |
|
18 |
|
|
19 |
public HoneywellLecteurBT(InfoAppareil device) |
|
20 |
{ |
|
21 |
AppareilInfos.Nom = device.Nom; |
|
22 |
AppareilInfos.AdresseMAC = device.AdresseMAC; |
|
23 |
ConnexionService = DependencyService.Get<IConnexionServiceFournisseur>().GetConnectionServiceInstance(ConnexionType.Bluetooth); |
|
24 |
ConnexionService.DonneesRecuesEvent += BluetoothDataReceived; |
|
25 |
} |
|
26 |
|
|
27 |
private void BluetoothDataReceived(object sender, byte[] e) |
|
28 |
{ |
|
29 |
string data = Encoding.ASCII.GetString(e); |
|
30 |
CBDonneesRecuesEvent.Invoke(this, data); |
|
31 |
} |
|
32 |
|
|
33 |
public async Task<bool> InitServiceAsync() |
|
34 |
{ |
|
35 |
Dictionary<string, string> param = new Dictionary<string, string>() |
|
36 |
{ |
|
37 |
{ ConnexionConstantes.MAC_ADDR_KEY, AppareilInfos.AdresseMAC } |
|
38 |
}; |
|
39 |
bool ret = await ConnexionService.Connexion(param); |
|
40 |
return ret; |
|
41 |
} |
|
42 |
|
|
43 |
public Task<bool> LancerScanAsync() |
|
44 |
{ |
|
45 |
throw new NotImplementedException(); |
|
46 |
} |
|
47 |
} |
|
48 |
} |
TestXamConnections/TestXamConnections/Device/Barcode/Honeywell/HoneywellLecteurInterne.cs | ||
---|---|---|
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 HoneywellLecteurInterne : ILecteurCodeBarre |
|
11 |
{ |
|
12 |
public InfoAppareil AppareilInfos { get; set; } |
|
13 |
public IConnexionService ConnexionService { get; set; } |
|
14 |
|
|
15 |
/// <summary> |
|
16 |
/// Événement déclenché à la reception de données par le lecteur Honeywell . |
|
17 |
/// </summary> |
|
18 |
public EventHandler<string> CBDonneesRecuesEvent { get; set; } |
|
19 |
|
|
20 |
public HoneywellLecteurInterne(InfoAppareil deviceI) |
|
21 |
{ |
|
22 |
AppareilInfos = deviceI; |
|
23 |
ConnexionService = DependencyService.Get<IConnexionServiceFournisseur>().GetConnectionServiceInstance(ConnexionType.Intern); |
|
24 |
ConnexionService.DonneesRecuesEvent += InternDataReceived; |
|
25 |
} |
|
26 |
|
|
27 |
private void InternDataReceived(object sender, byte[] intent) |
|
28 |
{ |
|
29 |
string data = Encoding.ASCII.GetString(intent); |
|
30 |
data = data == HoneyWellConstantes.ACTION_SCAN_ERROR ? "err" : data; |
|
31 |
CBDonneesRecuesEvent.Invoke(this, data); |
|
32 |
} |
|
33 |
|
|
34 |
|
|
35 |
/// <summary> |
|
36 |
/// Initialise la lecture de code barre avec lecteur interne Honeywell. |
|
37 |
/// </summary> |
|
38 |
/// <returns>true la connexion a réussi, false sinon.</returns> |
|
39 |
public async Task<bool> InitServiceAsync() |
|
40 |
{ |
|
41 |
bool ret; |
|
42 |
// Enregistrement des intents recevable par Agrident |
|
43 |
List<string> intentsList = new List<string>() |
|
44 |
{ |
|
45 |
HoneyWellConstantes.ACTION_SCAN_SUCCESS, |
|
46 |
HoneyWellConstantes.ACTION_SCAN_ERROR |
|
47 |
}; |
|
48 |
string intents = string.Join(',', intentsList); |
|
49 |
|
|
50 |
// Encapsulation des intents recevables pour envoyer au service de connexion |
|
51 |
Dictionary<string, string> param = new Dictionary<string, string>() |
|
52 |
{ |
|
53 |
{ ConnexionConstantes.RECEIVABLE_INTENTS_KEY, intents } |
|
54 |
}; |
|
55 |
|
|
56 |
ret = await ConnexionService.Connexion(param); |
|
57 |
return ret; |
|
58 |
} |
|
59 |
|
|
60 |
/// <summary> |
|
61 |
/// Lance un scan de code barre avec le lecteur Honeywell interne. |
|
62 |
/// Important : Il faut d'abord |
|
63 |
/// </summary> |
|
64 |
/// <returns>true si le scan s'est lancé correctement, false sinon.</returns> |
|
65 |
public async Task<bool> LancerScanAsync() |
|
66 |
{ |
|
67 |
byte[] startIntentBytes = Encoding.ASCII.GetBytes(HoneyWellConstantes.HONEYWELL_BARCODE); |
|
68 |
return await ConnexionService.EnvoiCommande(startIntentBytes); |
|
69 |
} |
|
70 |
} |
|
71 |
} |
TestXamConnections/TestXamConnections/Device/Barcode/IBarcodeReader.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Threading.Tasks; |
|
3 |
|
|
4 |
namespace TestXamConnections.Device.Barcode |
|
5 |
{ |
|
6 |
public interface IBarcodeReader : IDevice |
|
7 |
{ |
|
8 |
/// <summary> |
|
9 |
/// Événement déclenché à la reception de données par le lecteur de code barre. |
|
10 |
/// </summary> |
|
11 |
public EventHandler<string> BarcodeDataReceivedEvent { get; set; } |
|
12 |
|
|
13 |
/// <summary> |
|
14 |
/// Initialise la lecture de code barre. |
|
15 |
/// </summary> |
|
16 |
/// <returns>true l'init a réussi, false sinon.</returns> |
|
17 |
Task<bool> EnableServiceAsync(); |
|
18 |
|
|
19 |
/// <summary> |
|
20 |
/// Lance un scan de code barre. |
|
21 |
/// </summary> |
|
22 |
/// <returns>true si le scan s'est lancé correctement, false sinon.</returns> |
|
23 |
Task<bool> StartScanAsync(); |
|
24 |
} |
|
25 |
} |
TestXamConnections/TestXamConnections/Device/Barcode/ILecteurCodeBarre.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Threading.Tasks; |
|
3 |
|
|
4 |
namespace TestXamConnections.Device.Barcode |
|
5 |
{ |
|
6 |
public interface ILecteurCodeBarre : IAppareil |
|
7 |
{ |
|
8 |
/// <summary> |
|
9 |
/// Événement déclenché à la reception de données par le lecteur de code barre. |
|
10 |
/// </summary> |
|
11 |
public EventHandler<string> CBDonneesRecuesEvent { get; set; } |
|
12 |
|
|
13 |
/// <summary> |
|
14 |
/// Initialise la lecture de code barre. |
|
15 |
/// </summary> |
|
16 |
/// <returns>true l'init a réussi, false sinon.</returns> |
|
17 |
Task<bool> InitServiceAsync(); |
|
18 |
|
|
19 |
/// <summary> |
|
20 |
/// Lance un scan de code barre. |
|
21 |
/// </summary> |
|
22 |
/// <returns>true si le scan s'est lancé correctement, false sinon.</returns> |
|
23 |
Task<bool> LancerScanAsync(); |
|
24 |
} |
|
25 |
} |
TestXamConnections/TestXamConnections/Device/Barcode/LecteurCodeBarreFournisseur.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Text; |
|
4 |
using TestXamConnections.Connection; |
|
5 |
using TestXamConnections.Device.Barcode.Honeywell; |
|
6 |
|
|
7 |
namespace TestXamConnections.Device.Barcode |
|
8 |
{ |
|
9 |
public enum BarcodeDevice |
|
10 |
{ |
|
11 |
HoneywellIntern, |
|
12 |
HoneywellBT |
|
13 |
} |
|
14 |
|
|
15 |
public static class LecteurCodeBarreFournisseur |
|
16 |
{ |
|
17 |
public static ILecteurCodeBarre GetBarcodeReader(BarcodeDevice d, ConnexionType ct, InfoAppareil deviceI) |
|
18 |
{ |
|
19 |
return d switch |
|
20 |
{ |
|
21 |
BarcodeDevice.HoneywellIntern => new HoneywellLecteurInterne(deviceI), |
|
22 |
BarcodeDevice.HoneywellBT => new HoneywellLecteurBT(deviceI), |
|
23 |
_ => null, |
|
24 |
}; |
|
25 |
} |
|
26 |
} |
|
27 |
} |
TestXamConnections/TestXamConnections/Device/DeviceInfo.cs | ||
---|---|---|
1 |
namespace TestXamConnections.Device |
|
2 |
{ |
|
3 |
/// <summary> |
|
4 |
/// Représente un appareil caractérisé par un nom et une adresse MAC. |
|
5 |
/// </summary> |
|
6 |
public class DeviceInfo |
|
7 |
{ |
|
8 |
/// <summary> |
|
9 |
/// Le nom de l'appareil. |
|
10 |
/// </summary> |
|
11 |
public string Name { get; set; } |
|
12 |
|
|
13 |
/// <summary> |
|
14 |
/// L'adresse MAC de l'appareil |
|
15 |
/// </summary> |
|
16 |
public string MACAddress { get; set; } |
|
17 |
|
|
18 |
public override string ToString() |
|
19 |
{ |
|
20 |
return Name + ":" + MACAddress; |
|
21 |
} |
|
22 |
} |
|
23 |
} |
TestXamConnections/TestXamConnections/Device/IAppareil.cs | ||
---|---|---|
1 |
using TestXamConnections.Connection; |
|
2 |
|
|
3 |
namespace TestXamConnections.Device |
|
4 |
{ |
|
5 |
public interface IAppareil |
|
6 |
{ |
|
7 |
InfoAppareil AppareilInfos { get; set; } |
|
8 |
IConnexionService ConnexionService { get; set; } |
|
9 |
} |
|
10 |
} |
TestXamConnections/TestXamConnections/Device/IDevice.cs | ||
---|---|---|
1 |
using TestXamConnections.Connection; |
|
2 |
|
|
3 |
namespace TestXamConnections.Device |
|
4 |
{ |
|
5 |
public interface IDevice |
|
6 |
{ |
|
7 |
DeviceInfo DeviceI { get; set; } |
|
8 |
IConnectionService ConnectionService { get; set; } |
|
9 |
} |
|
10 |
} |
TestXamConnections/TestXamConnections/Device/InfoAppareil.cs | ||
---|---|---|
1 |
namespace TestXamConnections.Device |
|
2 |
{ |
|
3 |
/// <summary> |
|
4 |
/// Représente un appareil caractérisé par un nom et une adresse MAC. |
|
5 |
/// </summary> |
|
6 |
public class InfoAppareil |
|
7 |
{ |
|
8 |
/// <summary> |
|
9 |
/// Le nom de l'appareil. |
|
10 |
/// </summary> |
|
11 |
public string Nom { get; set; } |
|
12 |
|
|
13 |
/// <summary> |
|
14 |
/// L'adresse MAC de l'appareil |
|
15 |
/// </summary> |
|
16 |
public string AdresseMAC { get; set; } |
|
17 |
|
|
18 |
public override string ToString() |
|
19 |
{ |
|
20 |
return Nom + ":" + AdresseMAC; |
|
21 |
} |
|
22 |
} |
|
23 |
} |
TestXamConnections/TestXamConnections/Device/RFID/Agrident/AgridentConstantes.cs | ||
---|---|---|
1 |
namespace TestXamConnections.Device.RFID.Agrident |
|
2 |
{ |
|
3 |
/// <summary> |
|
4 |
/// Constantes utilisées pour la communication avec le module Agrident Wedge interne au C-One². |
|
5 |
/// </summary> |
|
6 |
public static class AgridentConstantes |
|
7 |
{ |
|
8 |
public const string ACTION_AGRIDENT_SUCCESS = "fr.coppernic.intent.agridentsuccess"; |
|
9 |
public const string ACTION_AGRIDENT_ERROR = "fr.coppernic.intent.agridentfailed"; |
|
10 |
public const string ACTION_AGRIDENT_SERVICE_STOP = "fr.coppernic.intent.action.stop.agrident.service"; |
|
11 |
public const string ACTION_AGRIDENT_SERVICE_START = "fr.coppernic.intent.action.start.agrident.service"; |
|
12 |
public const string ACTION_AGRIDENT_READ = "fr.coppernic.tools.agrident.wedge.READ"; |
|
13 |
public const string AGRIDENT_WEDGE = "fr.coppernic.tools.cpcagridentwedge"; |
|
14 |
public const string KEY_BARCODE_DATA = "BarcodeData"; |
|
15 |
} |
|
16 |
} |
TestXamConnections/TestXamConnections/Device/RFID/Agrident/AgridentConstants.cs | ||
---|---|---|
1 |
namespace TestXamConnections.Device.RFID.Agrident |
|
2 |
{ |
|
3 |
/// <summary> |
|
4 |
/// Constantes utilisées pour la communication avec le module Agrident Wedge interne au C-One². |
|
5 |
/// </summary> |
|
6 |
public static class AgridentConstants |
|
7 |
{ |
|
8 |
public const string ACTION_AGRIDENT_SUCCESS = "fr.coppernic.intent.agridentsuccess"; |
|
9 |
public const string ACTION_AGRIDENT_ERROR = "fr.coppernic.intent.agridentfailed"; |
|
10 |
public const string ACTION_AGRIDENT_SERVICE_STOP = "fr.coppernic.intent.action.stop.agrident.service"; |
|
11 |
public const string ACTION_AGRIDENT_SERVICE_START = "fr.coppernic.intent.action.start.agrident.service"; |
|
12 |
public const string ACTION_AGRIDENT_READ = "fr.coppernic.tools.agrident.wedge.READ"; |
|
13 |
public const string AGRIDENT_WEDGE = "fr.coppernic.tools.cpcagridentwedge"; |
|
14 |
public const string KEY_BARCODE_DATA = "BarcodeData"; |
|
15 |
} |
|
16 |
} |
TestXamConnections/TestXamConnections/Device/RFID/Agrident/AgridentInternReader.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Text; |
|
4 |
using System.Threading.Tasks; |
|
5 |
using TestXamConnections.Connection; |
|
6 |
using TestXamConnections.Models; |
|
7 |
using Xamarin.Forms; |
|
8 |
|
|
9 |
namespace TestXamConnections.Device.RFID.Agrident |
|
10 |
{ |
|
11 |
/// <summary> |
|
12 |
/// Important: Cette classe est utilisable avec le lecteur agrident interne au C-One. |
|
13 |
/// </summary> |
|
14 |
public class AgridentInternReader : IRFIDReader |
|
15 |
{ |
|
16 |
public DeviceInfo DeviceI { get; set; } |
|
17 |
public IConnectionService ConnectionService { get; set; } |
|
18 |
/// <summary> |
|
19 |
/// Événement déclenché à la reception de données par le lecteur RFID Agrident. |
|
20 |
/// </summary> |
|
21 |
public EventHandler<ReponseRFID> RFIDDataReceivedEvent { get; set; } |
|
22 |
|
|
23 |
public AgridentInternReader(DeviceInfo deviceI) |
|
24 |
{ |
|
25 |
DeviceI = deviceI; |
|
26 |
ConnectionService = DependencyService.Get<IConnectionServiceProvider>().GetConnectionServiceInstance(ConnectionType.Intern); |
|
27 |
ConnectionService.DataReceivedEvent += InternDataReceived; |
|
28 |
} |
|
29 |
|
|
30 |
~AgridentInternReader() |
|
31 |
{ |
|
32 |
ConnectionService.DataReceivedEvent -= InternDataReceived; |
|
33 |
} |
|
34 |
|
|
35 |
/* Fonction déclenchée à la reception de données Agrident |
|
36 |
* Trigger l'évènement AgridentDataReceivedEvent |
|
37 |
*/ |
|
38 |
private void InternDataReceived(object sender, byte[] intent) |
|
39 |
{ |
|
40 |
string data = Encoding.ASCII.GetString(intent); |
|
41 |
ReponseRFID ret = new ReponseRFID(); |
|
42 |
|
|
43 |
if (data == AgridentConstants.ACTION_AGRIDENT_ERROR) |
|
44 |
{ |
|
45 |
ret.IsoRfid = "No Tag"; |
|
46 |
ret.TagLu = false; |
|
47 |
} else |
|
48 |
{ |
|
49 |
/* Par défaut le lecteur envoie le numéro sur 16 chiffres |
|
50 |
* (le code pays peut théoriquement être > 999). Donc on se retrouve avec un 0 devant. |
|
51 |
* Un paramêtre permet de supprimer l'envoie de ce premier 0. |
|
52 |
* Mais comme on sait pas si se paramétre est coché ou pas, |
|
53 |
* on fait en sorte de traiter tjs sur 16 chiffres. |
|
54 |
*/ |
|
55 |
if (data.Length == 15) |
|
56 |
{ |
|
57 |
data = "0" + data; |
|
58 |
} |
|
59 |
ret.IsoRfid = data.Substring(1, 15); |
|
60 |
ret.CodePays = data.Substring(1, 3); |
|
61 |
ret.NumeroAnimal = data.Substring(4, 12); |
|
62 |
ret.TypeTag = ""; |
Formats disponibles : Unified diff