Révision b6f7a16a
TestXamConnections/TestXamConnections/Device/Balance/Balea/TeoBalance.cs | ||
---|---|---|
72 | 72 |
else if (_bufferedData[2] == '6') |
73 | 73 |
{ |
74 | 74 |
PeseeReceivedEvent.Invoke(this, new ReponsePesee("err")); |
75 |
}
|
|
75 |
} |
|
76 | 76 |
else |
77 | 77 |
{ |
78 | 78 |
PeseeReceivedEvent.Invoke(this, new ReponsePesee("err")); |
... | ... | |
98 | 98 |
/// Envoi d'une commande au Teo. |
99 | 99 |
/// </summary> |
100 | 100 |
/// <param name="commandType">La commande à envoyer.</param> |
101 |
/// <returns></returns> |
|
101 |
/// <returns>true si l'envoi a réussi, false sinon.</returns>
|
|
102 | 102 |
public async Task<bool> SendCommandAsync(TeoConstants.TeoCommandType cmd) |
103 | 103 |
{ |
104 | 104 |
byte[] commandValue = TeoConstants.TeoCommandValues.GetValueOrDefault(cmd); |
105 | 105 |
return await ConnectionService.SendCommand(commandValue); |
106 | 106 |
} |
107 |
|
|
108 |
/// <summary> |
|
109 |
/// Envoie d'une commande d'émission de poids au Teo. |
|
110 |
/// </summary> |
|
111 |
/// <returns>true si l'envoi a réussi, false sinon.</returns> |
|
112 |
public async Task<bool> ReadWeightAsync() |
|
113 |
{ |
|
114 |
byte[] commandValue = TeoConstants.TeoCommandValues.GetValueOrDefault(TeoConstants.TeoCommandType.EmissionPoids); |
|
115 |
return await ConnectionService.SendCommand(commandValue); |
|
116 |
} |
|
117 |
|
|
107 | 118 |
} |
108 | 119 |
} |
TestXamConnections/TestXamConnections/Device/Balance/IBalance.cs | ||
---|---|---|
26 | 26 |
/// <returns></returns> |
27 | 27 |
Task<bool> SendCommandAsync(TeoCommandType cmd); |
28 | 28 |
|
29 |
// <summary> |
|
30 |
/// Envoie d'une commande de pesée simple à la balance. |
|
31 |
/// </summary> |
|
32 |
/// <param name="commandType">La commande à envoyer.</param> |
|
33 |
/// <returns></returns> |
|
34 |
Task<bool> ReadWeightAsync(); |
|
35 |
|
|
29 | 36 |
} |
30 | 37 |
} |
TestXamConnections/TestXamConnections/Device/Barcode/Honeywell/HoneywellBTReader.cs | ||
---|---|---|
1 | 1 |
using System; |
2 | 2 |
using System.Collections.Generic; |
3 |
using System.Text; |
|
3 | 4 |
using System.Threading.Tasks; |
4 | 5 |
using TestXamConnections.Connection; |
5 | 6 |
using Xamarin.Forms; |
... | ... | |
25 | 26 |
|
26 | 27 |
private void BluetoothDataReceived(object sender, byte[] e) |
27 | 28 |
{ |
28 |
BarcodeDataReceivedEvent.Invoke(this, e); |
|
29 |
string data = Encoding.ASCII.GetString(e); |
|
30 |
BarcodeDataReceivedEvent.Invoke(this, data); |
|
29 | 31 |
} |
30 | 32 |
|
31 |
public async Task<bool> ConnectToBTReaderAsync()
|
|
33 |
public async Task<bool> EnableServiceAsync()
|
|
32 | 34 |
{ |
33 | 35 |
Dictionary<string, string> param = new Dictionary<string, string>() |
34 | 36 |
{ |
... | ... | |
37 | 39 |
bool ret = await ConnectionService.Connect(param); |
38 | 40 |
return ret; |
39 | 41 |
} |
42 |
|
|
43 |
public Task<bool> StartScanAsync() |
|
44 |
{ |
|
45 |
throw new NotImplementedException(); |
|
46 |
} |
|
40 | 47 |
} |
41 | 48 |
} |
TestXamConnections/TestXamConnections/Device/Barcode/Honeywell/HoneywellInternReader.cs | ||
---|---|---|
1 | 1 |
using System; |
2 |
using System.Collections.Generic; |
|
3 |
using System.Text; |
|
2 | 4 |
using System.Threading.Tasks; |
3 | 5 |
using TestXamConnections.Connection; |
4 | 6 |
using Xamarin.Forms; |
... | ... | |
8 | 10 |
public class HoneywellInternReader : IBarcodeReader |
9 | 11 |
{ |
10 | 12 |
public DeviceInfo DeviceI { get; set; } |
11 |
public IConnectionService ConnectionService = DependencyService.Get<IConnectionServiceProvider>().GetConnectionServiceInstance(ConnectionType.Intern);
|
|
13 |
public IConnectionService ConnectionService { get; set; }
|
|
12 | 14 |
|
13 | 15 |
/// <summary> |
14 | 16 |
/// Événement déclenché à la reception de données par le lecteur Honeywell . |
... | ... | |
18 | 20 |
public HoneywellInternReader(DeviceInfo deviceI) |
19 | 21 |
{ |
20 | 22 |
DeviceI = deviceI; |
21 |
|
|
23 |
ConnectionService = DependencyService.Get<IConnectionServiceProvider>().GetConnectionServiceInstance(ConnectionType.Intern); |
|
24 |
ConnectionService.DataReceivedEvent += InternDataReceived; |
|
22 | 25 |
} |
23 | 26 |
|
24 |
public Task<bool> ConnectToBTReaderAsync()
|
|
27 |
private void InternDataReceived(object sender, byte[] intent)
|
|
25 | 28 |
{ |
26 |
throw new NotImplementedException(); |
|
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 |
/// </summary> |
|
63 |
/// <returns>true si le scan s'est lancé correctement, false sinon.</returns> |
|
64 |
public async Task<bool> StartScanAsync() |
|
65 |
{ |
|
66 |
byte[] startIntentBytes = Encoding.ASCII.GetBytes(HoneyWellConstants.HONEYWELL_BARCODE); |
|
67 |
return await ConnectionService.SendCommand(startIntentBytes); |
|
27 | 68 |
} |
28 | 69 |
} |
29 | 70 |
} |
TestXamConnections/TestXamConnections/Device/Barcode/IBarcodeReader.cs | ||
---|---|---|
10 | 10 |
/// </summary> |
11 | 11 |
public EventHandler<string> BarcodeDataReceivedEvent { get; set; } |
12 | 12 |
|
13 |
Task<bool> ConnectToBTReaderAsync(); |
|
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(); |
|
14 | 24 |
} |
15 | 25 |
} |
TestXamConnections/TestXamConnections/Device/RFID/Agrident/AgridentConstants.cs | ||
---|---|---|
11 | 11 |
public const string ACTION_AGRIDENT_SERVICE_START = "fr.coppernic.intent.action.start.agrident.service"; |
12 | 12 |
public const string ACTION_AGRIDENT_READ = "fr.coppernic.tools.agrident.wedge.READ"; |
13 | 13 |
public const string AGRIDENT_WEDGE = "fr.coppernic.tools.cpcagridentwedge"; |
14 |
public const string KEY_BARCODE_DATA = "BarcodeData"; |
|
14 | 15 |
} |
15 | 16 |
} |
TestXamConnections/TestXamConnections/Device/RFID/Agrident/AgridentInternReader.cs | ||
---|---|---|
3 | 3 |
using System.Text; |
4 | 4 |
using System.Threading.Tasks; |
5 | 5 |
using TestXamConnections.Connection; |
6 |
using TestXamConnections.Models; |
|
6 | 7 |
using Xamarin.Forms; |
7 | 8 |
|
8 | 9 |
namespace TestXamConnections.Device.RFID.Agrident |
... | ... | |
17 | 18 |
/// <summary> |
18 | 19 |
/// Événement déclenché à la reception de données par le lecteur RFID Agrident. |
19 | 20 |
/// </summary> |
20 |
public EventHandler<string> RFIDDataReceivedEvent { get; set; }
|
|
21 |
public EventHandler<ReponseRFID> RFIDDataReceivedEvent { get; set; }
|
|
21 | 22 |
|
22 | 23 |
public AgridentInternReader(DeviceInfo deviceI) |
23 | 24 |
{ |
... | ... | |
37 | 38 |
private void InternDataReceived(object sender, byte[] intent) |
38 | 39 |
{ |
39 | 40 |
string data = Encoding.ASCII.GetString(intent); |
40 |
|
|
41 |
switch (data) |
|
41 |
ReponseRFID ret = new ReponseRFID(); |
|
42 |
|
|
43 |
if (data == AgridentConstants.ACTION_AGRIDENT_ERROR) |
|
42 | 44 |
{ |
43 |
case AgridentConstants.ACTION_AGRIDENT_ERROR: |
|
44 |
RFIDDataReceivedEvent.Invoke(this, ""); |
|
45 |
break; |
|
46 |
|
|
47 |
default: |
|
48 |
RFIDDataReceivedEvent.Invoke(this, data); |
|
49 |
break; |
|
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 = ""; |
|
63 |
ret.IsoEtendu = data; |
|
64 |
ret.CodeEtendu = data.Substring(0, 1); |
|
65 |
ret.TagLu = true; |
|
50 | 66 |
} |
67 |
RFIDDataReceivedEvent.Invoke(this, ret); |
|
51 | 68 |
} |
52 | 69 |
|
53 | 70 |
/// <summary> |
TestXamConnections/TestXamConnections/Device/RFID/IRFIDReader.cs | ||
---|---|---|
1 | 1 |
using System; |
2 | 2 |
using System.Threading.Tasks; |
3 |
using TestXamConnections.Models; |
|
3 | 4 |
|
4 | 5 |
namespace TestXamConnections.Device.RFID |
5 | 6 |
{ |
... | ... | |
8 | 9 |
/// <summary> |
9 | 10 |
/// Événement déclenché à la reception de données par le lecteur RFID. |
10 | 11 |
/// </summary> |
11 |
public EventHandler<string> RFIDDataReceivedEvent { get; set; }
|
|
12 |
public EventHandler<ReponseRFID> RFIDDataReceivedEvent { get; set; }
|
|
12 | 13 |
|
13 | 14 |
/// <summary> |
14 | 15 |
/// Initialise la lecture de tag RFID. |
15 | 16 |
/// </summary> |
16 |
/// <returns>true la connexion a réussi, false sinon.</returns>
|
|
17 |
/// <returns>true l'init a réussi, false sinon.</returns>
|
|
17 | 18 |
Task<bool> EnableServiceAsync(); |
18 | 19 |
|
19 | 20 |
/// <summary> |
TestXamConnections/TestXamConnections/Models/ReponseRFID.cs | ||
---|---|---|
2 | 2 |
{ |
3 | 3 |
public class ReponseRFID |
4 | 4 |
{ |
5 |
// TODO (doc JF Bompa) |
|
5 |
/// <summary> |
|
6 |
/// Numéro rfid 15 chiffres |
|
7 |
/// </summary> |
|
8 |
public string IsoRfid { get; set; } |
|
9 |
/// <summary> |
|
10 |
/// Code pays, ou fabriquant, 3 chiffres |
|
11 |
/// </summary> |
|
12 |
public string CodePays { get; set; } |
|
13 |
/// <summary> |
|
14 |
/// Numéro animal 12 chiffres |
|
15 |
/// </summary> |
|
16 |
public string NumeroAnimal { get; set; } |
|
17 |
/// <summary> |
|
18 |
/// Type tag, HDX ou FDX |
|
19 |
/// </summary> |
|
20 |
public string TypeTag { get; set; } |
|
21 |
/// <summary> |
|
22 |
/// Numéro Iso étendu |
|
23 |
/// </summary> |
|
24 |
public string IsoEtendu { get; set; } |
|
25 |
/// <summary> |
|
26 |
/// Code de l'extention de l'Iso etendu |
|
27 |
/// </summary> |
|
28 |
public string CodeEtendu { get; set; } |
|
29 |
/// <summary> |
|
30 |
/// Un tag à été lu |
|
31 |
/// </summary> |
|
32 |
public bool TagLu { get; set; } |
|
33 |
|
|
6 | 34 |
} |
7 | 35 |
} |
TestXamConnections/TestXamConnections/ViewModels/BarcodeReaderViewModel.cs | ||
---|---|---|
43 | 43 |
|
44 | 44 |
public async Task<bool> ConnectToDevice() |
45 | 45 |
{ |
46 |
if (await bcReader.ConnectToBTReaderAsync())
|
|
46 |
if (await bcReader.EnableServiceAsync())
|
|
47 | 47 |
{ |
48 | 48 |
ConnectionIndicator = "Connecté"; |
49 | 49 |
CIColor = "Green"; |
... | ... | |
74 | 74 |
bcReader.BarcodeDataReceivedEvent -= DataReceived; |
75 | 75 |
} |
76 | 76 |
|
77 |
private void DataReceived(object sender, byte[] e)
|
|
77 |
private void DataReceived(object sender, string receivedData)
|
|
78 | 78 |
{ |
79 | 79 |
IsVisibleData = true; |
80 |
Data += Encoding.ASCII.GetString(e) + "\n";
|
|
80 |
Data += receivedData + "\n";
|
|
81 | 81 |
} |
82 | 82 |
} |
83 | 83 |
} |
TestXamConnections/TestXamConnections/ViewModels/InternServiceViewModel.cs | ||
---|---|---|
3 | 3 |
using System.Windows.Input; |
4 | 4 |
using TestXamConnections.Device.RFID; |
5 | 5 |
using TestXamConnections.Device.RFID.Agrident; |
6 |
using TestXamConnections.Models; |
|
6 | 7 |
using Xamarin.Forms; |
7 | 8 |
|
8 | 9 |
namespace TestXamConnections.ViewModels |
... | ... | |
77 | 78 |
ShowRFID = false; |
78 | 79 |
} |
79 | 80 |
|
80 |
private void OnRFIDResultReceived(object sender, string e)
|
|
81 |
private void OnRFIDResultReceived(object sender, ReponseRFID reponseRFID)
|
|
81 | 82 |
{ |
82 | 83 |
ResetAffichage(); |
83 |
if (e == "")
|
|
84 |
if (reponseRFID.TagLu == false)
|
|
84 | 85 |
{ |
85 | 86 |
ShowError = true; |
86 | 87 |
ErrorMessage = "Pas de TAG RFID detecté"; |
87 | 88 |
} else |
88 | 89 |
{ |
89 | 90 |
ShowRFID = true; |
90 |
RFIDResult = e;
|
|
91 |
RFIDResult = reponseRFID.IsoEtendu;
|
|
91 | 92 |
} |
92 | 93 |
IsScanning = false; |
93 | 94 |
} |
TestXamConnections/TestXamConnections/ViewModels/TeoDeviceViewModel.cs | ||
---|---|---|
91 | 91 |
{ |
92 | 92 |
// Appel au Balance provider pour récupérer l'item TeoBalancea avec les fonctions d'initiation |
93 | 93 |
TeoScale = BalanceProvider.GetBalance(Balance.TeoBalance, ConnectionType.Bluetooth, device); |
94 |
TeoScale.SendCommandAsync(TeoConstants.TeoCommandType.EmissionPoids) |
|
94 |
TeoScale.SendCommandAsync(TeoConstants.TeoCommandType.EmissionPoids);
|
|
95 | 95 |
Init(); |
96 | 96 |
} |
97 | 97 |
|
TestXamConnections/TestXamConnections/Views/InternServiceView.xaml | ||
---|---|---|
51 | 51 |
Color="#4f5a64" /> |
52 | 52 |
|
53 | 53 |
<Label |
54 |
Margin="0,10" |
|
54 | 55 |
FontAttributes="Bold" |
56 |
FontSize="17" |
|
55 | 57 |
HorizontalTextAlignment="Center" |
56 | 58 |
Text="{Binding RFIDResult}" |
57 | 59 |
TextColor="White" /> |
Formats disponibles : Unified diff