Révision d14bc0b1
TestTeoBluetooth.sln | ||
---|---|---|
1 |
|
|
2 |
Microsoft Visual Studio Solution File, Format Version 12.00 |
|
3 |
# Visual Studio Version 16 |
|
4 |
VisualStudioVersion = 16.0.31729.503 |
|
5 |
MinimumVisualStudioVersion = 10.0.40219.1 |
|
6 |
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestXamConnections.Android", "TestTeoBluetooth\TestTeoBluetooth.Android\TestXamConnections.Android.csproj", "{A6E319ED-E59B-4FAA-A143-1E1E653FD0BC}" |
|
7 |
EndProject |
|
8 |
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestXamConnections", "TestTeoBluetooth\TestTeoBluetooth\TestXamConnections.csproj", "{5C87F357-DF5A-4AEC-9663-ED55C0E4904D}" |
|
9 |
EndProject |
|
10 |
Global |
|
11 |
GlobalSection(SolutionConfigurationPlatforms) = preSolution |
|
12 |
Debug|Any CPU = Debug|Any CPU |
|
13 |
Release|Any CPU = Release|Any CPU |
|
14 |
EndGlobalSection |
|
15 |
GlobalSection(ProjectConfigurationPlatforms) = postSolution |
|
16 |
{A6E319ED-E59B-4FAA-A143-1E1E653FD0BC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
|
17 |
{A6E319ED-E59B-4FAA-A143-1E1E653FD0BC}.Debug|Any CPU.Build.0 = Debug|Any CPU |
|
18 |
{A6E319ED-E59B-4FAA-A143-1E1E653FD0BC}.Debug|Any CPU.Deploy.0 = Debug|Any CPU |
|
19 |
{A6E319ED-E59B-4FAA-A143-1E1E653FD0BC}.Release|Any CPU.ActiveCfg = Release|Any CPU |
|
20 |
{A6E319ED-E59B-4FAA-A143-1E1E653FD0BC}.Release|Any CPU.Build.0 = Release|Any CPU |
|
21 |
{A6E319ED-E59B-4FAA-A143-1E1E653FD0BC}.Release|Any CPU.Deploy.0 = Release|Any CPU |
|
22 |
{5C87F357-DF5A-4AEC-9663-ED55C0E4904D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
|
23 |
{5C87F357-DF5A-4AEC-9663-ED55C0E4904D}.Debug|Any CPU.Build.0 = Debug|Any CPU |
|
24 |
{5C87F357-DF5A-4AEC-9663-ED55C0E4904D}.Debug|Any CPU.Deploy.0 = Debug|Any CPU |
|
25 |
{5C87F357-DF5A-4AEC-9663-ED55C0E4904D}.Release|Any CPU.ActiveCfg = Release|Any CPU |
|
26 |
{5C87F357-DF5A-4AEC-9663-ED55C0E4904D}.Release|Any CPU.Build.0 = Release|Any CPU |
|
27 |
{5C87F357-DF5A-4AEC-9663-ED55C0E4904D}.Release|Any CPU.Deploy.0 = Release|Any CPU |
|
28 |
EndGlobalSection |
|
29 |
GlobalSection(SolutionProperties) = preSolution |
|
30 |
HideSolutionNode = FALSE |
|
31 |
EndGlobalSection |
|
32 |
GlobalSection(ExtensibilityGlobals) = postSolution |
|
33 |
SolutionGuid = {5962BE11-9ED3-4A22-B6CA-D8B4D3F98D54} |
|
34 |
EndGlobalSection |
|
35 |
EndGlobal |
TestTeoBluetooth/TestTeoBluetooth.Android/Connection/BluetoothConnectionService.cs | ||
---|---|---|
24 | 24 |
*/ |
25 | 25 |
public class BluetoothConnectionService : IConnectionService |
26 | 26 |
{ |
27 |
|
|
28 | 27 |
private readonly BluetoothAdapter bluetoothAdapter; |
29 | 28 |
private Thread listeningThread; |
30 | 29 |
private BluetoothSocket socket; |
31 | 30 |
private readonly string sppUUID = "00001101-0000-1000-8000-00805f9b34fb"; |
32 | 31 |
|
33 |
public static readonly BluetoothConnectionService Instance = new BluetoothConnectionService(); |
|
34 |
|
|
35 | 32 |
public BluetoothConnectionService() |
36 | 33 |
{ |
37 | 34 |
bluetoothAdapter = BluetoothAdapter.DefaultAdapter; |
... | ... | |
49 | 46 |
} |
50 | 47 |
|
51 | 48 |
BluetoothDevice droidBtDevice = bluetoothAdapter.GetRemoteDevice(btDevice.MACAddress); |
52 |
//Android.Bluetooth.BluetoothDevice droidBtDevice = adapter.BondedDevices.FirstOrDefault(x => (x.Address == bluetoothDevice.Address)); |
|
53 | 49 |
if (droidBtDevice != null) |
54 | 50 |
{ |
55 | 51 |
// Si le socket est occupé pour une autre connexion |
... | ... | |
67 | 63 |
cts.CancelAfter(50000); |
68 | 64 |
await socket.ConnectAsync().WithCancellation(cts.Token); |
69 | 65 |
|
70 |
if (listeningThread != null) listeningThread.Abort(); |
|
66 |
if (listeningThread != null) |
|
67 |
{ |
|
68 |
listeningThread.Abort(); |
|
69 |
} |
|
70 |
|
|
71 | 71 |
listeningThread = new Thread(async delagate => await ListeningAsync()); |
72 | 72 |
listeningThread.Start(); |
73 | 73 |
|
... | ... | |
82 | 82 |
return false; |
83 | 83 |
} |
84 | 84 |
|
85 |
public EventHandler<byte[]> DataReceivedEvent { get; set; } |
|
86 |
|
|
85 | 87 |
// Fonction d'écoute pour le Thread d'écoute |
86 | 88 |
private async Task ListeningAsync() |
87 | 89 |
{ |
... | ... | |
93 | 95 |
int byteAvailable = await socket.InputStream.ReadAsync(buffer, 0, buffer.Length); |
94 | 96 |
// Resize the byte array |
95 | 97 |
byte[] filledBuffer = buffer.Take(byteAvailable).ToArray(); |
96 |
Application.SynchronizationContext.Post(_ => { OnDataReceived(filledBuffer); }, null); |
|
98 |
// Trigger DataReceivedEvent |
|
99 |
Application.SynchronizationContext.Post(_ => { DataReceivedEvent.Invoke(this, filledBuffer); }, null); |
|
97 | 100 |
} |
98 | 101 |
} |
99 | 102 |
catch (IOException ex) |
... | ... | |
110 | 113 |
} |
111 | 114 |
} |
112 | 115 |
|
113 |
public EventHandler<string> DataReceivedEvent { get; set; } |
|
114 |
private string _bufferedData; |
|
115 |
|
|
116 |
/* |
|
117 |
* Fonction appelée à la reception de données |
|
118 |
* Trigger l'evenement DataReceivedEvent |
|
119 |
* |
|
120 |
* IMPORTANT: Les trames peuvent arriver découpées, |
|
121 |
* Donc les données sont gardées dans un buffer d'envoi |
|
122 |
* nommé _bufferedData |
|
123 |
*/ |
|
124 |
private void OnDataReceived(byte[] buffer) |
|
125 |
{ |
|
126 |
// Si le premier character est 2 (ASCII: STX) |
|
127 |
// Alors c'est le début de la trame. |
|
128 |
if (buffer[0] == 2) |
|
129 |
{ |
|
130 |
_bufferedData = ""; |
|
131 |
// Si character seul on quitte |
|
132 |
if (buffer.Length == 1) |
|
133 |
{ |
|
134 |
return; |
|
135 |
} |
|
136 |
// On enlève STX |
|
137 |
buffer = buffer.Skip(1).ToArray(); |
|
138 |
// On mets le début de la trame dans buffer d'envoi |
|
139 |
_bufferedData += Encoding.ASCII.GetString(buffer); |
|
140 |
} |
|
141 |
|
|
142 |
// Si le dernier character est 13 (ASCII: CR) |
|
143 |
// Alors la trame est terminée |
|
144 |
if (buffer[^1] == 13) |
|
145 |
{ |
|
146 |
// On enlève CR |
|
147 |
buffer = buffer.SkipLast(1).ToArray(); |
|
148 |
// Conversion en chaîne de caractères |
|
149 |
// Et on complète le buffer d'envoi |
|
150 |
_bufferedData += Encoding.ASCII.GetString(buffer); |
|
151 |
// Trigger evènement |
|
152 |
DataReceivedEvent.Invoke(this, _bufferedData); |
|
153 |
} |
|
154 |
} |
|
155 | 116 |
|
156 | 117 |
private Task<bool> CloseConnection() |
157 | 118 |
{ |
TestTeoBluetooth/TestTeoBluetooth.Android/Connection/InternConnectionService.cs | ||
---|---|---|
20 | 20 |
*/ |
21 | 21 |
public class InternConnectionService : IConnectionService |
22 | 22 |
{ |
23 |
public static readonly InternConnectionService Instance = new InternConnectionService(); |
|
24 |
public EventHandler<string> DataReceivedEvent { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } |
|
23 |
public EventHandler<byte[]> DataReceivedEvent { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } |
|
25 | 24 |
|
26 | 25 |
public Task<bool> Connect(Device device) |
27 | 26 |
{ |
TestTeoBluetooth/TestTeoBluetooth.Android/Connection/WifiConnectionService.cs | ||
---|---|---|
19 | 19 |
*/ |
20 | 20 |
public class WifiConnectionService : IConnectionService |
21 | 21 |
{ |
22 |
public static readonly WifiConnectionService Instance = new WifiConnectionService(); |
|
23 |
public EventHandler<string> DataReceivedEvent { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } |
|
22 |
public EventHandler<byte[]> DataReceivedEvent { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } |
|
24 | 23 |
|
25 | 24 |
public Task<bool> Connect(Device device) |
26 | 25 |
{ |
TestTeoBluetooth/TestTeoBluetooth.Android/Helper/ConnectionServiceProvider.cs | ||
---|---|---|
1 |
using Android.App; |
|
2 |
using Android.Content; |
|
3 |
using Android.OS; |
|
4 |
using Android.Runtime; |
|
5 |
using Android.Views; |
|
6 |
using Android.Widget; |
|
7 |
using System; |
|
8 |
using System.Collections.Generic; |
|
9 |
using System.Linq; |
|
10 |
using System.Text; |
|
11 |
using System.Threading.Tasks; |
|
12 |
using TestXamConnections; |
|
13 |
using TestXamConnections.Connection; |
|
14 |
using TestXamConnections.Droid.Connection; |
|
15 |
using TestXamConnections.Helper; |
|
16 |
using Xamarin.Forms; |
|
17 |
|
|
18 |
namespace TestBLE.Droid.Helper |
|
19 |
{ |
|
20 |
public class ConnectionServiceProvider : IConnectionServiceProvider |
|
21 |
{ |
|
22 |
public IConnectionService GetConnectionInstance(ConnectionType ct) |
|
23 |
{ |
|
24 |
IConnectionService instance = null; |
|
25 |
switch (ct) |
|
26 |
{ |
|
27 |
case ConnectionType.Bluetooth: |
|
28 |
// instance = BluetoothConnectionService.Instance; |
|
29 |
instance = new BluetoothConnectionService(); |
|
30 |
break; |
|
31 |
|
|
32 |
case ConnectionType.Intern: |
|
33 |
instance = new InternConnectionService(); |
|
34 |
break; |
|
35 |
|
|
36 |
case ConnectionType.Wifi: |
|
37 |
instance = new WifiConnectionService (); |
|
38 |
break; |
|
39 |
|
|
40 |
default: |
|
41 |
break; |
|
42 |
} |
|
43 |
|
|
44 |
return instance; |
|
45 |
} |
|
46 |
} |
|
47 |
} |
TestTeoBluetooth/TestTeoBluetooth.Android/Helper/ConnectionServiceUpdater.cs | ||
---|---|---|
1 |
using Android.App; |
|
2 |
using Android.Content; |
|
3 |
using Android.OS; |
|
4 |
using Android.Runtime; |
|
5 |
using Android.Views; |
|
6 |
using Android.Widget; |
|
7 |
using System; |
|
8 |
using System.Collections.Generic; |
|
9 |
using System.Linq; |
|
10 |
using System.Text; |
|
11 |
using System.Threading.Tasks; |
|
12 |
using TestXamConnections; |
|
13 |
using TestXamConnections.Connection; |
|
14 |
using TestXamConnections.Droid.Connection; |
|
15 |
using TestXamConnections.Helper; |
|
16 |
using Xamarin.Forms; |
|
17 |
|
|
18 |
namespace TestBLE.Droid.Helper |
|
19 |
{ |
|
20 |
public class ConnectionServiceUpdater : IConnectionServiceProvider |
|
21 |
{ |
|
22 |
public IConnectionService GetConnectionInstance(ConnectionType ct) |
|
23 |
{ |
|
24 |
IConnectionService instance = null; |
|
25 |
switch (ct) |
|
26 |
{ |
|
27 |
case ConnectionType.Bluetooth: |
|
28 |
instance = BluetoothConnectionService.Instance; |
|
29 |
break; |
|
30 |
|
|
31 |
case ConnectionType.Intern: |
|
32 |
instance = InternConnectionService.Instance; |
|
33 |
break; |
|
34 |
|
|
35 |
case ConnectionType.Wifi: |
|
36 |
instance = WifiConnectionService.Instance; |
|
37 |
break; |
|
38 |
|
|
39 |
default: |
|
40 |
break; |
|
41 |
} |
|
42 |
|
|
43 |
return instance; |
|
44 |
} |
|
45 |
} |
|
46 |
} |
TestTeoBluetooth/TestTeoBluetooth.Android/MainActivity.cs | ||
---|---|---|
14 | 14 |
|
15 | 15 |
namespace TestXamConnections.Droid |
16 | 16 |
{ |
17 |
[Activity(Label = "TestBLE", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize )]
|
|
17 |
[Activity(Label = "TestXamConnections", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize )]
|
|
18 | 18 |
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity |
19 | 19 |
{ |
20 | 20 |
protected override void OnCreate(Bundle savedInstanceState) |
... | ... | |
23 | 23 |
|
24 | 24 |
Xamarin.Essentials.Platform.Init(this, savedInstanceState); |
25 | 25 |
Forms.Init(this, savedInstanceState); |
26 |
DependencyService.RegisterSingleton<IConnectionServiceProvider>(new ConnectionServiceUpdater());
|
|
26 |
DependencyService.RegisterSingleton<IConnectionServiceProvider>(new ConnectionServiceProvider());
|
|
27 | 27 |
DependencyService.RegisterSingleton<IBluetoothService>(new BluetoothService()); |
28 | 28 |
LoadApplication(new App()); |
29 | 29 |
} |
TestTeoBluetooth/TestTeoBluetooth.Android/TestXamConnections.Android.csproj | ||
---|---|---|
33 | 33 |
<ErrorReport>prompt</ErrorReport> |
34 | 34 |
<WarningLevel>4</WarningLevel> |
35 | 35 |
<AndroidLinkMode>None</AndroidLinkMode> |
36 |
<AotAssemblies>false</AotAssemblies> |
|
37 |
<EnableLLVM>false</EnableLLVM> |
|
38 |
<AndroidEnableProfiledAot>false</AndroidEnableProfiledAot> |
|
39 |
<BundleAssemblies>false</BundleAssemblies> |
|
36 | 40 |
</PropertyGroup> |
37 | 41 |
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
38 | 42 |
<DebugSymbols>true</DebugSymbols> |
... | ... | |
59 | 63 |
</ItemGroup> |
60 | 64 |
<ItemGroup> |
61 | 65 |
<Compile Include="Connection\BluetoothConnectionService.cs" /> |
62 |
<Compile Include="Helper\ConnectionServiceUpdater.cs" />
|
|
66 |
<Compile Include="Helper\ConnectionServiceProvider.cs" />
|
|
63 | 67 |
<Compile Include="Connection\InternConnectionService.cs" /> |
64 | 68 |
<Compile Include="Connection\WifiConnectionService.cs" /> |
65 | 69 |
<Compile Include="MainActivity.cs" /> |
TestTeoBluetooth/TestTeoBluetooth/Connection/IConnectionService.cs | ||
---|---|---|
11 | 11 |
{ |
12 | 12 |
Task<bool> Connect(Device device); |
13 | 13 |
Task<bool> SendCommand(byte[] hexValues); |
14 |
EventHandler<string> DataReceivedEvent { get; set; }
|
|
14 |
EventHandler<byte[]> DataReceivedEvent { get; set; }
|
|
15 | 15 |
} |
16 | 16 |
} |
TestTeoBluetooth/TestTeoBluetooth/Helper/AsyncLazy.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Runtime.CompilerServices; |
|
4 |
using System.Text; |
|
5 |
using System.Threading.Tasks; |
|
6 |
|
|
7 |
namespace TestXamConnections.Helper |
|
8 |
{ |
|
9 |
public class AsyncLazy<T> |
|
10 |
{ |
|
11 |
readonly Lazy<Task<T>> instance; |
|
12 |
|
|
13 |
public AsyncLazy(Func<T> factory) |
|
14 |
{ |
|
15 |
instance = new Lazy<Task<T>>(() => Task.Run(factory)); |
|
16 |
} |
|
17 |
|
|
18 |
public AsyncLazy(Func<Task<T>> factory) |
|
19 |
{ |
|
20 |
instance = new Lazy<Task<T>>(() => Task.Run(factory)); |
|
21 |
} |
|
22 |
|
|
23 |
public TaskAwaiter<T> GetAwaiter() |
|
24 |
{ |
|
25 |
return instance.Value.GetAwaiter(); |
|
26 |
} |
|
27 |
|
|
28 |
public void Start() |
|
29 |
{ |
|
30 |
var unused = instance.Value; |
|
31 |
} |
|
32 |
} |
|
33 |
} |
TestTeoBluetooth/TestTeoBluetooth/Models/ReponsePesee.cs | ||
---|---|---|
42 | 42 |
public ReponsePesee(string data) |
43 | 43 |
{ |
44 | 44 |
// Voir doc Balance Teo INRAE |
45 |
NumPlateau = data[0];
|
|
46 |
TypePlateau = data[1];
|
|
45 |
NumPlateau = int.Parse(data[0].ToString());
|
|
46 |
TypePlateau = int.Parse(data[1].ToString());
|
|
47 | 47 |
IsNegative = data[4] == '-'; |
48 |
PoidsMesure = data.ToCharArray().Skip(7).ToArray().ToString();
|
|
48 |
PoidsMesure = new string(data.Skip(5).ToArray()).Trim();
|
|
49 | 49 |
} |
50 | 50 |
} |
51 | 51 |
} |
TestTeoBluetooth/TestTeoBluetooth/Models/TeoBalance.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Linq; |
|
4 |
using System.Text; |
|
5 |
using System.Threading.Tasks; |
|
6 |
using TestXamConnections.Connection; |
|
7 |
using TestXamConnections.Helper; |
|
8 |
using Xamarin.Forms; |
|
9 |
|
|
10 |
namespace TestXamConnections.Models |
|
11 |
{ |
|
12 |
public enum TeoCommandType |
|
13 |
{ |
|
14 |
// Voir documentation TEO INRAE |
|
15 |
// Codes ASCII |
|
16 |
ModeOrdre, |
|
17 |
EmissionPoids, |
|
18 |
SortieOrdreGardeBluetooth, |
|
19 |
SortieOrdreEtBluetooth, |
|
20 |
ModePeseeSimple, |
|
21 |
SortiePeseeSimple, |
|
22 |
PeseeStabilisee, |
|
23 |
InterrompPS, |
|
24 |
TareP1, |
|
25 |
TareP2, |
|
26 |
ZeroP1, |
|
27 |
ZeroP2, |
|
28 |
InfosMetrologie, |
|
29 |
} |
|
30 |
|
|
31 |
public class TeoBalance : Device |
|
32 |
{ |
|
33 |
public IConnectionService ConnectionService { get; set; } |
|
34 |
public EventHandler<string> TeoDataReceivedEvent { get; set; } |
|
35 |
public EventHandler<ReponsePesee> TeoPeseeReceivedEvent { get; set; } |
|
36 |
|
|
37 |
public TeoBalance(Device device) |
|
38 |
{ |
|
39 |
Name = device.Name; |
|
40 |
MACAddress = device.MACAddress; |
|
41 |
ConnectionService = DependencyService.Get<IConnectionServiceProvider>().GetConnectionInstance(ConnectionType.Bluetooth); |
|
42 |
ConnectionService.DataReceivedEvent += (s, args) => TeoDataReceived(args); |
|
43 |
} |
|
44 |
|
|
45 |
~TeoBalance() |
|
46 |
{ |
|
47 |
ConnectionService.DataReceivedEvent -= (s, args) => TeoDataReceived(args); |
|
48 |
} |
|
49 |
|
|
50 |
/* |
|
51 |
* Fonction déclenchée à la reception de données |
|
52 |
* Trigger l'evenement TeoDataReceivedEvent |
|
53 |
* |
|
54 |
* IMPORTANT: Les trames du Teo peuvent arriver découpées, |
|
55 |
* Donc les données sont gardées dans un buffer d'envoi |
|
56 |
* nommé _bufferedData |
|
57 |
*/ |
|
58 |
private string _bufferedData; |
|
59 |
|
|
60 |
private void TeoDataReceived(byte[] buffer) |
|
61 |
{ |
|
62 |
// Si le premier character est 2 (ASCII: STX) |
|
63 |
// Alors c'est le début de la trame. |
|
64 |
if (buffer[0] == 2) |
|
65 |
{ |
|
66 |
_bufferedData = ""; |
|
67 |
// Si character seul on quitte |
|
68 |
if (buffer.Length == 1) |
|
69 |
{ |
|
70 |
return; |
|
71 |
} |
|
72 |
// On enlève STX |
|
73 |
buffer = buffer.Skip(1).ToArray(); |
|
74 |
// On mets le début de la trame dans buffer d'envoi |
|
75 |
_bufferedData += Encoding.ASCII.GetString(buffer); |
|
76 |
} |
|
77 |
|
|
78 |
// Si le dernier character est 13 (ASCII: CR) |
|
79 |
// Alors la trame est terminée |
|
80 |
if (buffer[^1] == 13) |
|
81 |
{ |
|
82 |
// On enlève CR |
|
83 |
buffer = buffer.SkipLast(1).ToArray(); |
|
84 |
// Conversion en chaîne de caractères |
|
85 |
// Et on complète le buffer d'envoi |
|
86 |
_bufferedData += Encoding.ASCII.GetString(buffer); |
|
87 |
// Trigger evènement en fonction de la trame |
|
88 |
|
|
89 |
if (_bufferedData.Length == 12) |
|
90 |
{ |
|
91 |
TeoPeseeReceivedEvent.Invoke(this, new ReponsePesee(_bufferedData)); |
|
92 |
} else if (_bufferedData[2] == '6') |
|
93 |
{ |
|
94 |
TeoDataReceivedEvent.Invoke(this, "Erreur pesée"); |
|
95 |
} |
|
96 |
else |
|
97 |
{ |
|
98 |
TeoDataReceivedEvent.Invoke(this, _bufferedData); |
|
99 |
} |
|
100 |
} |
|
101 |
} |
|
102 |
|
|
103 |
// Retourne la chaine d'octets d'une commande Teo (prog INRAE) |
|
104 |
public static byte[] GetCommandCode(TeoCommandType c) |
|
105 |
{ |
|
106 |
// Les commandes envoyées sont sur 3 octets |
|
107 |
byte[] ret = new byte[3]; |
|
108 |
// STX |
|
109 |
ret[0] = 0x02; |
|
110 |
// CR |
|
111 |
ret[2] = 0x0D; |
|
112 |
|
|
113 |
// Commande |
|
114 |
switch (c) |
|
115 |
{ |
|
116 |
case TeoCommandType.ModeOrdre: |
|
117 |
ret[1] = 0x61; |
|
118 |
break; |
|
119 |
|
|
120 |
case TeoCommandType.SortieOrdreGardeBluetooth: |
|
121 |
ret[1] = 0x6B; |
|
122 |
break; |
|
123 |
|
|
124 |
case TeoCommandType.SortieOrdreEtBluetooth: |
|
125 |
ret[1] = 0x67; |
|
126 |
break; |
|
127 |
|
|
128 |
case TeoCommandType.ModePeseeSimple: |
|
129 |
ret[1] = 0x62; |
|
130 |
break; |
|
131 |
|
|
132 |
case TeoCommandType.SortiePeseeSimple: |
|
133 |
ret[1] = 0x65; |
|
134 |
break; |
|
135 |
|
|
136 |
case TeoCommandType.TareP1: |
|
137 |
ret[1] = 0x74; |
|
138 |
break; |
|
139 |
|
|
140 |
case TeoCommandType.TareP2: |
|
141 |
ret[1] = 0x6A; |
|
142 |
break; |
|
143 |
|
|
144 |
case TeoCommandType.ZeroP1: |
|
145 |
ret[1] = 0x7A; |
|
146 |
break; |
|
147 |
|
|
148 |
case TeoCommandType.ZeroP2: |
|
149 |
ret[1] = 0x64; |
|
150 |
break; |
|
151 |
|
|
152 |
case TeoCommandType.InfosMetrologie: |
|
153 |
ret[1] = 0x73; |
|
154 |
break; |
|
155 |
|
|
156 |
case TeoCommandType.EmissionPoids: |
|
157 |
ret[1] = 0x63; |
|
158 |
break; |
|
159 |
// TODO |
|
160 |
case TeoCommandType.PeseeStabilisee: |
|
161 |
break; |
|
162 |
|
|
163 |
case TeoCommandType.InterrompPS: |
|
164 |
break; |
|
165 |
|
|
166 |
default: |
|
167 |
break; |
|
168 |
} |
|
169 |
return ret; |
|
170 |
} |
|
171 |
|
|
172 |
// Retourne le nom d'une commande Teo (prog INRAE) |
|
173 |
public static string GetCommandName(TeoCommandType c) |
|
174 |
{ |
|
175 |
// Les commandes envoyées sont sur 3 octets |
|
176 |
string ret = ""; |
|
177 |
|
|
178 |
// Commande |
|
179 |
switch (c) |
|
180 |
{ |
|
181 |
case TeoCommandType.ModeOrdre: |
|
182 |
ret = "Mode attente ordre"; |
|
183 |
break; |
|
184 |
|
|
185 |
case TeoCommandType.SortieOrdreGardeBluetooth: |
|
186 |
ret = "Sortie mode ordre"; |
|
187 |
break; |
|
188 |
|
|
189 |
case TeoCommandType.SortieOrdreEtBluetooth: |
|
190 |
ret = "Sortie mode ordre & couper bluetooth"; |
|
191 |
break; |
|
192 |
|
|
193 |
case TeoCommandType.ModePeseeSimple: |
|
194 |
ret = "Mode simple pesage"; |
|
195 |
break; |
|
196 |
|
|
197 |
case TeoCommandType.SortiePeseeSimple: |
|
198 |
ret = "Sortie mode simple pesage"; |
|
199 |
break; |
|
200 |
|
|
201 |
case TeoCommandType.TareP1: |
|
202 |
ret = "Tare plateau 1"; |
|
203 |
break; |
|
204 |
|
|
205 |
case TeoCommandType.TareP2: |
|
206 |
ret = "Tare plateau 2"; |
|
207 |
break; |
|
208 |
|
|
209 |
case TeoCommandType.ZeroP1: |
|
210 |
ret = "Zero plateau 1"; |
|
211 |
break; |
|
212 |
|
|
213 |
case TeoCommandType.ZeroP2: |
|
214 |
ret = "Zero plateau 2"; |
|
215 |
break; |
|
216 |
|
|
217 |
case TeoCommandType.InfosMetrologie: |
|
218 |
ret = "Informations métrologie"; |
|
219 |
break; |
|
220 |
|
|
221 |
case TeoCommandType.EmissionPoids: |
|
222 |
ret = "Emission poids"; |
|
223 |
break; |
|
224 |
// TODO |
|
225 |
case TeoCommandType.PeseeStabilisee: |
|
226 |
ret = "Pesée stabilisée - NON implémenté"; |
|
227 |
break; |
|
228 |
|
|
229 |
case TeoCommandType.InterrompPS: |
|
230 |
ret = "STOP Pesée stabilisée - NON implémenté"; |
|
231 |
break; |
|
232 |
|
|
233 |
default: |
|
234 |
break; |
|
235 |
} |
|
236 |
return ret; |
|
237 |
} |
|
238 |
|
|
239 |
} |
|
240 |
} |
TestTeoBluetooth/TestTeoBluetooth/Models/TeoBluetoothCommands.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Text; |
|
4 |
|
|
5 |
namespace TestXamConnections.Models |
|
6 |
{ |
|
7 |
public static class TeoBluetoothCommand |
|
8 |
{ |
|
9 |
public enum CommandType |
|
10 |
{ |
|
11 |
// Voir documentation TEO INRAE |
|
12 |
// Codes ASCII |
|
13 |
ModeOrdre, |
|
14 |
EmissionPoids, |
|
15 |
SortieOrdreGardeBluetooth, |
|
16 |
SortieOrdreEtBluetooth, |
|
17 |
ModePeseeSimple, |
|
18 |
SortiePeseeSimple, |
|
19 |
PeseeStabilisee, |
|
20 |
InterrompPS, |
|
21 |
TareP1, |
|
22 |
TareP2, |
|
23 |
ZeroP1, |
|
24 |
ZeroP2, |
|
25 |
InfosMetrologie, |
|
26 |
} |
|
27 |
|
|
28 |
// Retourne la chaine d'octets d'une commande Teo (prog INRAE) |
|
29 |
public static byte[] GetCommandCode(CommandType c) |
|
30 |
{ |
|
31 |
// Les commandes envoyées sont sur 3 octets |
|
32 |
byte[] ret = new byte[3]; |
|
33 |
// STX |
|
34 |
ret[0] = 0x02; |
|
35 |
// CR |
|
36 |
ret[2] = 0x0D; |
|
37 |
|
|
38 |
// Commande |
|
39 |
switch (c) |
|
40 |
{ |
|
41 |
case CommandType.ModeOrdre: |
|
42 |
ret[1] = 0x61; |
|
43 |
break; |
|
44 |
|
|
45 |
case CommandType.SortieOrdreGardeBluetooth: |
|
46 |
ret[1] = 0x6B; |
|
47 |
break; |
|
48 |
|
|
49 |
case CommandType.SortieOrdreEtBluetooth: |
|
50 |
ret[1] = 0x67; |
|
51 |
break; |
|
52 |
|
|
53 |
case CommandType.ModePeseeSimple: |
|
54 |
ret[1] = 0x62; |
|
55 |
break; |
|
56 |
|
|
57 |
case CommandType.SortiePeseeSimple: |
|
58 |
ret[1] = 0x65; |
|
59 |
break; |
|
60 |
|
|
61 |
case CommandType.TareP1: |
|
62 |
ret[1] = 0x74; |
|
63 |
break; |
|
64 |
|
|
65 |
case CommandType.TareP2: |
|
66 |
ret[1] = 0x6A; |
|
67 |
break; |
|
68 |
|
|
69 |
case CommandType.ZeroP1: |
|
70 |
ret[1] = 0x7A; |
|
71 |
break; |
|
72 |
|
|
73 |
case CommandType.ZeroP2: |
|
74 |
ret[1] = 0x64; |
|
75 |
break; |
|
76 |
|
|
77 |
case CommandType.InfosMetrologie: |
|
78 |
ret[1] = 0x73; |
|
79 |
break; |
|
80 |
|
|
81 |
case CommandType.EmissionPoids: |
|
82 |
ret[1] = 0x63; |
|
83 |
break; |
|
84 |
// TODO |
|
85 |
case CommandType.PeseeStabilisee: |
|
86 |
break; |
|
87 |
|
|
88 |
case CommandType.InterrompPS: |
|
89 |
break; |
|
90 |
|
|
91 |
default: |
|
92 |
break; |
|
93 |
} |
|
94 |
return ret; |
|
95 |
} |
|
96 |
|
|
97 |
// Retourne le nom d'une commande Teo (prog INRAE) |
|
98 |
public static string GetCommandName(CommandType c) |
|
99 |
{ |
|
100 |
// Les commandes envoyées sont sur 3 octets |
|
101 |
string ret = ""; |
|
102 |
|
|
103 |
// Commande |
|
104 |
switch (c) |
|
105 |
{ |
|
106 |
case CommandType.ModeOrdre: |
|
107 |
ret = "Mode attente ordre"; |
|
108 |
break; |
|
109 |
|
|
110 |
case CommandType.SortieOrdreGardeBluetooth: |
|
111 |
ret = "Sortie mode ordre"; |
|
112 |
break; |
|
113 |
|
|
114 |
case CommandType.SortieOrdreEtBluetooth: |
|
115 |
ret = "Sortie mode ordre & couper bluetooth"; |
|
116 |
break; |
|
117 |
|
|
118 |
case CommandType.ModePeseeSimple: |
|
119 |
ret = "Mode simple pesage"; |
|
120 |
break; |
|
121 |
|
|
122 |
case CommandType.SortiePeseeSimple: |
|
123 |
ret = "Sortie mode simple pesage"; |
|
124 |
break; |
|
125 |
|
|
126 |
case CommandType.TareP1: |
|
127 |
ret = "Tare plateau 1"; |
|
128 |
break; |
|
129 |
|
|
130 |
case CommandType.TareP2: |
|
131 |
ret = "Tare plateau 2"; |
|
132 |
break; |
|
133 |
|
|
134 |
case CommandType.ZeroP1: |
|
135 |
ret = "Zero plateau 1"; |
|
136 |
break; |
|
137 |
|
|
138 |
case CommandType.ZeroP2: |
|
139 |
ret = "Zero plateau 2"; |
|
140 |
break; |
|
141 |
|
|
142 |
case CommandType.InfosMetrologie: |
|
143 |
ret = "Informations métrologie"; |
|
144 |
break; |
|
145 |
|
|
146 |
case CommandType.EmissionPoids: |
|
147 |
ret = "Emission poids"; |
|
148 |
break; |
|
149 |
// TODO |
|
150 |
case CommandType.PeseeStabilisee: |
|
151 |
ret = "Pesée stabilisée - NON implémenté"; |
|
152 |
break; |
|
153 |
|
|
154 |
case CommandType.InterrompPS: |
|
155 |
ret = "STOP Pesée stabilisée - NON implémenté"; |
|
156 |
break; |
|
157 |
|
|
158 |
default: |
|
159 |
break; |
|
160 |
} |
|
161 |
return ret; |
|
162 |
} |
|
163 |
} |
|
164 |
} |
TestTeoBluetooth/TestTeoBluetooth/TestXamConnections.csproj | ||
---|---|---|
1 | 1 |
<Project Sdk="Microsoft.NET.Sdk"> |
2 | 2 |
|
3 | 3 |
<PropertyGroup> |
4 |
<TargetFramework>netstandard2.0</TargetFramework>
|
|
4 |
<TargetFramework>netstandard2.1</TargetFramework>
|
|
5 | 5 |
<ProduceReferenceAssembly>true</ProduceReferenceAssembly> |
6 | 6 |
<AssemblyName>TestXamConnections</AssemblyName> |
7 | 7 |
<RootNamespace>TestXamConnections</RootNamespace> |
... | ... | |
22 | 22 |
<Compile Update="Views\AccueilView.xaml.cs"> |
23 | 23 |
<DependentUpon>AccueilView.xaml</DependentUpon> |
24 | 24 |
</Compile> |
25 |
<Compile Update="Views\DeviceView.xaml.cs"> |
|
26 |
<DependentUpon>DeviceView.xaml</DependentUpon> |
|
25 |
<Compile Update="Views\TeoDeviceView.xaml.cs">
|
|
26 |
<DependentUpon>TeoDeviceView.xaml</DependentUpon>
|
|
27 | 27 |
</Compile> |
28 | 28 |
</ItemGroup> |
29 | 29 |
|
... | ... | |
31 | 31 |
<EmbeddedResource Update="Views\AccueilView.xaml"> |
32 | 32 |
<Generator>MSBuild:UpdateDesignTimeXaml</Generator> |
33 | 33 |
</EmbeddedResource> |
34 |
<EmbeddedResource Update="Views\DeviceView.xaml"> |
|
34 |
<EmbeddedResource Update="Views\TeoDeviceView.xaml">
|
|
35 | 35 |
<Generator>MSBuild:UpdateDesignTimeXaml</Generator> |
36 | 36 |
</EmbeddedResource> |
37 | 37 |
</ItemGroup> |
TestTeoBluetooth/TestTeoBluetooth/ViewModels/CommandItemViewModel.cs | ||
---|---|---|
9 | 9 |
namespace TestXamConnections.ViewModels |
10 | 10 |
{ |
11 | 11 |
public class CommandItemViewModel : ViewModelBase |
12 |
{ |
|
13 |
public IConnectionService ConnectionService { get; set; } |
|
14 |
|
|
12 |
{ |
|
15 | 13 |
private string name; |
16 |
private TeoBluetoothCommand.CommandType toSendCommand;
|
|
17 |
|
|
14 |
private TeoCommandType toSendCommand; |
|
15 |
private IConnectionService ConnectionService; |
|
18 | 16 |
private string commandBytes; |
19 | 17 |
|
20 | 18 |
public string CommandBytes |
... | ... | |
29 | 27 |
set { SetProperty(ref name, value); } |
30 | 28 |
} |
31 | 29 |
|
32 |
public TeoBluetoothCommand.CommandType ToSendCommand
|
|
30 |
public TeoCommandType ToSendCommand |
|
33 | 31 |
{ |
34 | 32 |
get { return toSendCommand; } |
35 | 33 |
set { SetProperty( ref toSendCommand, value); } |
... | ... | |
37 | 35 |
|
38 | 36 |
private async Task<bool> SendValue() |
39 | 37 |
{ |
40 |
await ConnectionService.SendCommand(TeoBluetoothCommand.GetCommandCode(ToSendCommand));
|
|
38 |
await ConnectionService.SendCommand(TeoBalance.GetCommandCode(ToSendCommand));
|
|
41 | 39 |
return true; |
42 | 40 |
} |
43 | 41 |
|
44 | 42 |
public ICommand SendValueCommand { private set; get; } |
45 | 43 |
|
46 |
public CommandItemViewModel(TeoBluetoothCommand.CommandType cmd)
|
|
44 |
public CommandItemViewModel(TeoCommandType cmd, IConnectionService cs)
|
|
47 | 45 |
{ |
48 | 46 |
ToSendCommand = cmd; |
49 |
Name = TeoBluetoothCommand.GetCommandName(cmd);
|
|
50 |
CommandBytes = string.Join("-", TeoBluetoothCommand.GetCommandCode(cmd));
|
|
51 |
ConnectionService = DependencyService.Get<IConnectionServiceProvider>().GetConnectionInstance(ConnectionType.Bluetooth);
|
|
47 |
ConnectionService = cs;
|
|
48 |
Name = TeoBalance.GetCommandName(cmd);
|
|
49 |
CommandBytes = string.Join("-", TeoBalance.GetCommandCode(cmd));
|
|
52 | 50 |
SendValueCommand = new Command(async () => await SendValue()); |
53 | 51 |
} |
54 | 52 |
|
TestTeoBluetooth/TestTeoBluetooth/ViewModels/DeviceItemViewModel.cs | ||
---|---|---|
24 | 24 |
|
25 | 25 |
private async Task NavigateToDevice() |
26 | 26 |
{ |
27 |
await Application.Current.MainPage.Navigation.PushAsync(new DeviceView(Device)); |
|
27 |
await Application.Current.MainPage.Navigation.PushAsync(new TeoDeviceView(Device));
|
|
28 | 28 |
} |
29 | 29 |
|
30 | 30 |
public ICommand NavigateToDeviceViewCommand { private set; get; } |
TestTeoBluetooth/TestTeoBluetooth/ViewModels/DeviceViewModel.cs | ||
---|---|---|
9 | 9 |
using TestXamConnections.Models; |
10 | 10 |
using TestXamConnections.Services; |
11 | 11 |
using Xamarin.Forms; |
12 |
using static TestXamConnections.Models.TeoBluetoothCommand;
|
|
12 |
using static TestXamConnections.Models.TeoBalance;
|
|
13 | 13 |
|
14 | 14 |
namespace TestXamConnections.ViewModels |
15 | 15 |
{ |
16 |
public class DeviceViewModel : ViewModelBase |
|
16 |
public class TeoDeviceViewModel : ViewModelBase
|
|
17 | 17 |
{ |
18 | 18 |
private bool isConnected; |
19 | 19 |
private string data; |
20 |
private Models.Device device;
|
|
20 |
private TeoBalance teoScale;
|
|
21 | 21 |
|
22 | 22 |
private bool isVisibleData; |
23 | 23 |
|
... | ... | |
33 | 33 |
set { SetProperty(ref isConnected, value); } |
34 | 34 |
} |
35 | 35 |
|
36 |
public Models.Device Device
|
|
36 |
public TeoBalance TeoScale
|
|
37 | 37 |
{ |
38 |
get { return device; }
|
|
39 |
set { SetProperty(ref device, value); }
|
|
38 |
get { return teoScale; }
|
|
39 |
set { SetProperty(ref teoScale, value); }
|
|
40 | 40 |
} |
41 | 41 |
|
42 | 42 |
public string Data |
... | ... | |
44 | 44 |
get { return data; } |
45 | 45 |
set { SetProperty(ref data, value); } |
46 | 46 |
} |
47 |
|
|
48 |
public IConnectionService ConnectionService { get; set; } |
|
49 | 47 |
|
50 | 48 |
public ObservableCollection<CommandItemViewModel> AvailableCommandsList { get; set; } |
51 | 49 |
|
52 | 50 |
public async Task<bool> ConnectToDevice() |
53 | 51 |
{ |
54 |
await ConnectionService.Connect(Device); |
|
55 |
IsConnected = true; |
|
56 |
return true; |
|
52 |
IsConnected = await teoScale.ConnectionService.Connect(TeoScale); |
|
53 |
return IsConnected; |
|
54 |
} |
|
55 |
|
|
56 |
public void DataReceived(string args) |
|
57 |
{ |
|
58 |
IsVisibleData = true; |
|
59 |
Data += args.Trim() + "\n"; |
|
60 |
} |
|
61 |
|
|
62 |
public void PeseeReceived(ReponsePesee args) |
|
63 |
{ |
|
64 |
Data = args.PoidsMesure; |
|
57 | 65 |
} |
66 |
|
|
58 | 67 |
public ICommand ConnectToDeviceCommand { private set; get; } |
59 | 68 |
|
60 |
public DeviceViewModel(Models.Device device) |
|
69 |
public TeoDeviceViewModel(Models.Device device)
|
|
61 | 70 |
{ |
62 |
Device = device;
|
|
71 |
TeoScale = new TeoBalance(device);
|
|
63 | 72 |
IsConnected = false; |
64 | 73 |
IsVisibleData = false; |
65 |
ConnectionService = DependencyService.Get<IConnectionServiceProvider>().GetConnectionInstance(ConnectionType.Bluetooth); |
|
66 |
ConnectionService.DataReceivedEvent += (s, args) => DataReceived(args); |
|
67 | 74 |
ConnectToDeviceCommand = new Command(async () => await ConnectToDevice()); |
75 |
TeoScale.TeoDataReceivedEvent = (s, args) => DataReceived(args); |
|
76 |
TeoScale.TeoPeseeReceivedEvent = (s, args) => PeseeReceived(args); |
|
68 | 77 |
|
69 | 78 |
// Ajout manuel des commandes |
70 | 79 |
AvailableCommandsList = new ObservableCollection<CommandItemViewModel>(); |
71 |
foreach (CommandType _cmd in Enum.GetValues(typeof(CommandType)))
|
|
80 |
foreach (TeoCommandType _cmd in Enum.GetValues(typeof(TeoCommandType)))
|
|
72 | 81 |
{ |
73 |
AvailableCommandsList.Add(new CommandItemViewModel(_cmd)); |
|
82 |
AvailableCommandsList.Add(new CommandItemViewModel(_cmd, TeoScale.ConnectionService));
|
|
74 | 83 |
} |
75 | 84 |
} |
76 | 85 |
|
77 |
~DeviceViewModel() |
|
78 |
{ |
|
79 |
ConnectionService.DataReceivedEvent -= (s, args) => DataReceived(args); |
|
80 |
} |
|
81 |
|
|
82 |
private void DataReceived(string recData) |
|
83 |
{ |
|
84 |
IsVisibleData = true; |
|
85 |
ReponsePesee resp = new ReponsePesee(recData); |
|
86 |
Data += resp.PoidsMesure + "\n"; |
|
87 |
} |
|
86 |
|
|
88 | 87 |
|
89 | 88 |
} |
90 | 89 |
} |
TestTeoBluetooth/TestTeoBluetooth/Views/DeviceView.xaml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8" ?> |
|
2 |
<ContentPage |
|
3 |
x:Class="TestXamConnections.Views.DeviceView" |
|
4 |
xmlns="http://xamarin.com/schemas/2014/forms" |
|
5 |
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" |
|
6 |
xmlns:xe="clr-namespace:XamEffects;assembly=XamEffects" |
|
7 |
Title="Device Page"> |
|
8 |
<ContentPage.Content> |
|
9 |
|
|
10 |
<StackLayout |
|
11 |
Padding="10" |
|
12 |
BackgroundColor="#001729" |
|
13 |
VerticalOptions="FillAndExpand"> |
|
14 |
<StackLayout VerticalOptions="CenterAndExpand"> |
|
15 |
<Frame |
|
16 |
Padding="0" |
|
17 |
BackgroundColor="Transparent" |
|
18 |
BorderColor="#4f5a64" |
|
19 |
CornerRadius="5" |
|
20 |
HasShadow="False" |
|
21 |
HorizontalOptions="Center" |
|
22 |
VerticalOptions="CenterAndExpand" |
|
23 |
WidthRequest="250"> |
|
24 |
<StackLayout Spacing="0"> |
|
25 |
<StackLayout Margin="0,10"> |
|
26 |
<Label |
|
27 |
Margin="0" |
|
28 |
FontAttributes="Bold" |
|
29 |
FontSize="28" |
|
30 |
HorizontalOptions="CenterAndExpand" |
|
31 |
HorizontalTextAlignment="Center" |
|
32 |
Text="{Binding Device.Name}" |
|
33 |
TextColor="White" |
|
34 |
VerticalOptions="CenterAndExpand" /> |
|
35 |
<Label |
|
36 |
Margin="0" |
|
37 |
FontAttributes="Italic" |
|
38 |
FontSize="12" |
|
39 |
HorizontalOptions="CenterAndExpand" |
|
40 |
HorizontalTextAlignment="Center" |
|
41 |
Text="{Binding Device.MACAddress}" |
|
42 |
TextColor="DarkGray" |
|
43 |
VerticalOptions="CenterAndExpand" /> |
|
44 |
</StackLayout> |
|
45 |
<!-- Bouton Connect --> |
|
46 |
<xe:BorderView |
|
47 |
Margin="0,10,0,20" |
|
48 |
xe:Commands.Tap="{Binding ConnectToDeviceCommand}" |
|
49 |
xe:TouchEffect.Color="#0060a8" |
|
50 |
BackgroundColor="#003266" |
|
51 |
CornerRadius="65" |
|
52 |
HorizontalOptions="Center"> |
|
53 |
<StackLayout Padding="15,10"> |
|
54 |
<Label |
|
55 |
FontSize="16" |
|
56 |
HorizontalOptions="Center" |
|
57 |
Text="Connect" |
|
58 |
TextColor="#34a9ff" /> |
|
59 |
</StackLayout> |
|
60 |
</xe:BorderView> |
|
61 |
<BoxView |
|
62 |
HeightRequest="1" |
|
63 |
HorizontalOptions="FillAndExpand" |
|
64 |
IsVisible="{Binding IsConnected}" |
|
65 |
Color="#4f5a64" /> |
|
66 |
<ScrollView Padding="0,10" IsVisible="{Binding IsConnected}"> |
|
67 |
<StackLayout |
|
68 |
x:Name="commandsList" |
|
69 |
Padding="0" |
|
70 |
BindableLayout.ItemsSource="{Binding AvailableCommandsList}" |
|
71 |
HorizontalOptions="FillAndExpand" |
|
72 |
Orientation="Vertical" |
|
73 |
Spacing="5"> |
|
74 |
<BindableLayout.ItemTemplate> |
|
75 |
<DataTemplate> |
|
76 |
<StackLayout |
|
77 |
Padding="0,5" |
|
78 |
xe:Commands.Tap="{Binding SendValueCommand}" |
|
79 |
xe:TouchEffect.Color="#34a9ff" |
|
80 |
Spacing="0"> |
|
81 |
<Label |
|
82 |
FontAttributes="Bold" |
|
83 |
HorizontalTextAlignment="Center" |
|
84 |
Text="{Binding Name}" |
|
85 |
TextColor="White" /> |
|
86 |
<Label |
|
87 |
FontAttributes="Italic" |
|
88 |
HorizontalTextAlignment="Center" |
|
89 |
Text="{Binding CommandBytes}" |
|
90 |
TextColor="DarkGray" /> |
|
91 |
</StackLayout> |
|
92 |
</DataTemplate> |
|
93 |
</BindableLayout.ItemTemplate> |
|
94 |
</StackLayout> |
|
95 |
|
|
96 |
</ScrollView> |
|
97 |
</StackLayout> |
|
98 |
|
|
99 |
</Frame> |
|
100 |
<Frame |
|
101 |
Padding="0" |
|
102 |
BackgroundColor="Transparent" |
|
103 |
BorderColor="#4f5a64" |
|
104 |
CornerRadius="5" |
|
105 |
HasShadow="False" |
|
106 |
HorizontalOptions="Center" |
|
107 |
IsVisible="{Binding IsVisibleData}" |
|
108 |
VerticalOptions="CenterAndExpand" |
|
109 |
WidthRequest="200"> |
|
110 |
<StackLayout HorizontalOptions="CenterAndExpand"> |
|
111 |
<Label |
|
112 |
FontAttributes="Bold" |
|
113 |
FontSize="18" |
|
114 |
HorizontalTextAlignment="Center" |
|
115 |
Text="Received Data" |
|
116 |
TextColor="White" /> |
|
117 |
<Label |
|
118 |
FontAttributes="Italic" |
|
119 |
FontSize="14" |
|
120 |
HorizontalTextAlignment="Center" |
|
121 |
Text="{Binding Data}" |
|
122 |
TextColor="DarkGray" /> |
|
123 |
</StackLayout> |
|
124 |
</Frame> |
|
125 |
</StackLayout> |
|
126 |
</StackLayout> |
|
127 |
</ContentPage.Content> |
|
128 |
</ContentPage> |
TestTeoBluetooth/TestTeoBluetooth/Views/DeviceView.xaml.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Linq; |
|
4 |
using System.Text; |
|
5 |
using System.Threading.Tasks; |
|
6 |
using TestXamConnections.Models; |
|
7 |
using TestXamConnections.ViewModels; |
|
8 |
using Xamarin.Forms; |
|
9 |
using Xamarin.Forms.Xaml; |
|
10 |
|
|
11 |
namespace TestXamConnections.Views |
|
12 |
{ |
|
13 |
[XamlCompilation(XamlCompilationOptions.Compile)] |
|
14 |
public partial class DeviceView : ContentPage |
|
15 |
{ |
|
16 |
public DeviceView(Models.Device device) |
|
17 |
{ |
|
18 |
InitializeComponent(); |
|
19 |
BindingContext = new DeviceViewModel(device); |
|
20 |
} |
|
21 |
} |
|
22 |
} |
TestTeoBluetooth/TestTeoBluetooth/Views/TeoDeviceView.xaml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8" ?> |
|
2 |
<ContentPage |
|
3 |
x:Class="TestXamConnections.Views.TeoDeviceView" |
|
4 |
xmlns="http://xamarin.com/schemas/2014/forms" |
|
5 |
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" |
|
6 |
xmlns:xe="clr-namespace:XamEffects;assembly=XamEffects" |
|
7 |
Title="Device Page"> |
|
8 |
<ContentPage.Content> |
|
9 |
<ScrollView> |
|
10 |
<StackLayout |
|
11 |
Padding="10" |
|
12 |
BackgroundColor="#001729" |
|
13 |
VerticalOptions="FillAndExpand"> |
|
14 |
<StackLayout VerticalOptions="CenterAndExpand"> |
|
15 |
|
|
16 |
<Frame |
|
17 |
Padding="0" |
|
18 |
BackgroundColor="Transparent" |
|
19 |
BorderColor="#4f5a64" |
|
20 |
CornerRadius="5" |
|
21 |
HasShadow="False" |
|
22 |
HorizontalOptions="Center" |
|
23 |
IsVisible="{Binding IsVisibleData}" |
|
24 |
VerticalOptions="CenterAndExpand" |
|
25 |
WidthRequest="200"> |
|
26 |
<StackLayout HorizontalOptions="CenterAndExpand"> |
|
27 |
<Label |
|
28 |
FontAttributes="Bold" |
|
29 |
FontSize="18" |
|
30 |
HorizontalTextAlignment="Center" |
|
31 |
Text="Received Data" |
|
32 |
TextColor="White" /> |
|
33 |
<Label |
|
34 |
FontAttributes="Italic" |
|
35 |
FontSize="14" |
|
36 |
HorizontalTextAlignment="Center" |
|
37 |
Text="{Binding Data}" |
|
38 |
TextColor="DarkGray" /> |
|
39 |
</StackLayout> |
|
40 |
</Frame> |
|
41 |
|
|
42 |
<Frame |
|
43 |
Padding="0" |
|
44 |
BackgroundColor="Transparent" |
|
45 |
BorderColor="#4f5a64" |
|
46 |
CornerRadius="5" |
|
47 |
HasShadow="False" |
|
48 |
HorizontalOptions="Center" |
|
49 |
VerticalOptions="CenterAndExpand" |
|
50 |
WidthRequest="250"> |
|
51 |
<StackLayout Spacing="0"> |
|
52 |
<StackLayout Margin="0,10"> |
|
53 |
<Label |
|
54 |
Margin="0" |
|
55 |
FontAttributes="Bold" |
|
56 |
FontSize="28" |
|
57 |
HorizontalOptions="CenterAndExpand" |
|
58 |
HorizontalTextAlignment="Center" |
|
59 |
Text="{Binding TeoScale.Name}" |
|
60 |
TextColor="White" |
|
61 |
VerticalOptions="CenterAndExpand" /> |
|
62 |
<Label |
|
63 |
Margin="0" |
|
64 |
FontAttributes="Italic" |
|
65 |
FontSize="12" |
|
66 |
HorizontalOptions="CenterAndExpand" |
|
67 |
HorizontalTextAlignment="Center" |
|
68 |
Text="{Binding TeoScale.MACAddress}" |
|
69 |
TextColor="DarkGray" |
|
70 |
VerticalOptions="CenterAndExpand" /> |
|
71 |
</StackLayout> |
|
72 |
<!-- Bouton Connect --> |
|
73 |
<xe:BorderView |
|
74 |
Margin="0,10,0,20" |
|
75 |
xe:Commands.Tap="{Binding ConnectToDeviceCommand}" |
|
76 |
xe:TouchEffect.Color="#0060a8" |
|
77 |
BackgroundColor="#003266" |
|
78 |
CornerRadius="65" |
|
79 |
HorizontalOptions="Center"> |
|
80 |
<StackLayout Padding="15,10"> |
|
81 |
<Label |
|
82 |
FontSize="16" |
|
83 |
HorizontalOptions="Center" |
|
84 |
Text="Connect" |
|
85 |
TextColor="#34a9ff" /> |
|
86 |
</StackLayout> |
|
87 |
</xe:BorderView> |
|
88 |
<BoxView |
|
89 |
HeightRequest="1" |
|
90 |
HorizontalOptions="FillAndExpand" |
|
91 |
IsVisible="{Binding IsConnected}" |
|
92 |
Color="#4f5a64" /> |
|
93 |
<ScrollView Padding="0,10" IsVisible="{Binding IsConnected}"> |
|
94 |
<StackLayout |
|
95 |
x:Name="commandsList" |
|
96 |
Padding="0" |
|
97 |
BindableLayout.ItemsSource="{Binding AvailableCommandsList}" |
|
98 |
HorizontalOptions="FillAndExpand" |
|
99 |
Orientation="Vertical" |
|
100 |
Spacing="5"> |
|
101 |
<BindableLayout.ItemTemplate> |
|
102 |
<DataTemplate> |
|
103 |
<StackLayout |
|
104 |
Padding="0,5" |
|
105 |
xe:Commands.Tap="{Binding SendValueCommand}" |
|
106 |
xe:TouchEffect.Color="#34a9ff" |
|
107 |
Spacing="0"> |
|
108 |
<Label |
|
109 |
FontAttributes="Bold" |
|
110 |
HorizontalTextAlignment="Center" |
|
111 |
Text="{Binding Name}" |
|
112 |
TextColor="White" /> |
|
113 |
<Label |
|
114 |
FontAttributes="Italic" |
|
115 |
HorizontalTextAlignment="Center" |
|
116 |
Text="{Binding CommandBytes}" |
|
117 |
TextColor="DarkGray" /> |
|
118 |
</StackLayout> |
|
119 |
</DataTemplate> |
|
120 |
</BindableLayout.ItemTemplate> |
|
121 |
</StackLayout> |
|
122 |
|
|
123 |
</ScrollView> |
|
124 |
</StackLayout> |
|
125 |
|
|
126 |
</Frame> |
|
127 |
<Frame |
|
128 |
Padding="0" |
|
129 |
BackgroundColor="Transparent" |
|
130 |
BorderColor="#4f5a64" |
|
131 |
CornerRadius="5" |
|
132 |
HasShadow="False" |
|
133 |
HorizontalOptions="Center" |
|
134 |
IsVisible="{Binding IsVisibleData}" |
|
135 |
VerticalOptions="CenterAndExpand" |
|
136 |
WidthRequest="200"> |
|
137 |
<StackLayout HorizontalOptions="CenterAndExpand"> |
|
138 |
<Label |
|
139 |
FontAttributes="Bold" |
|
140 |
FontSize="18" |
|
141 |
HorizontalTextAlignment="Center" |
|
142 |
Text="Received Data" |
|
143 |
TextColor="White" /> |
|
144 |
<Label |
|
145 |
FontAttributes="Italic" |
|
146 |
FontSize="14" |
|
147 |
HorizontalTextAlignment="Center" |
|
148 |
Text="{Binding Data}" |
|
149 |
TextColor="DarkGray" /> |
|
150 |
</StackLayout> |
|
151 |
</Frame> |
|
152 |
</StackLayout> |
|
153 |
</StackLayout> |
|
154 |
</ScrollView> |
|
155 |
</ContentPage.Content> |
|
156 |
</ContentPage> |
TestTeoBluetooth/TestTeoBluetooth/Views/TeoDeviceView.xaml.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Linq; |
|
4 |
using System.Text; |
|
5 |
using System.Threading.Tasks; |
|
6 |
using TestXamConnections.Models; |
|
7 |
using TestXamConnections.ViewModels; |
|
8 |
using Xamarin.Forms; |
|
9 |
using Xamarin.Forms.Xaml; |
|
10 |
|
|
11 |
namespace TestXamConnections.Views |
|
12 |
{ |
|
13 |
[XamlCompilation(XamlCompilationOptions.Compile)] |
|
14 |
public partial class TeoDeviceView : ContentPage |
|
15 |
{ |
|
16 |
public TeoDeviceView(Models.Device device) |
|
17 |
{ |
|
18 |
InitializeComponent(); |
|
19 |
BindingContext = new TeoDeviceViewModel(device); |
|
20 |
} |
|
21 |
} |
|
22 |
} |
TestXamConnections.sln | ||
---|---|---|
1 |
|
|
2 |
Microsoft Visual Studio Solution File, Format Version 12.00 |
|
3 |
# Visual Studio Version 16 |
|
4 |
VisualStudioVersion = 16.0.31729.503 |
|
5 |
MinimumVisualStudioVersion = 10.0.40219.1 |
|
6 |
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestXamConnections.Android", "TestTeoBluetooth\TestTeoBluetooth.Android\TestXamConnections.Android.csproj", "{A6E319ED-E59B-4FAA-A143-1E1E653FD0BC}" |
|
7 |
EndProject |
|
8 |
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestXamConnections", "TestTeoBluetooth\TestTeoBluetooth\TestXamConnections.csproj", "{5C87F357-DF5A-4AEC-9663-ED55C0E4904D}" |
|
9 |
EndProject |
|
10 |
Global |
|
11 |
GlobalSection(SolutionConfigurationPlatforms) = preSolution |
|
12 |
Debug|Any CPU = Debug|Any CPU |
|
13 |
Release|Any CPU = Release|Any CPU |
|
14 |
EndGlobalSection |
|
15 |
GlobalSection(ProjectConfigurationPlatforms) = postSolution |
|
16 |
{A6E319ED-E59B-4FAA-A143-1E1E653FD0BC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
|
17 |
{A6E319ED-E59B-4FAA-A143-1E1E653FD0BC}.Debug|Any CPU.Build.0 = Debug|Any CPU |
|
18 |
{A6E319ED-E59B-4FAA-A143-1E1E653FD0BC}.Debug|Any CPU.Deploy.0 = Debug|Any CPU |
|
19 |
{A6E319ED-E59B-4FAA-A143-1E1E653FD0BC}.Release|Any CPU.ActiveCfg = Release|Any CPU |
|
20 |
{A6E319ED-E59B-4FAA-A143-1E1E653FD0BC}.Release|Any CPU.Build.0 = Release|Any CPU |
|
21 |
{A6E319ED-E59B-4FAA-A143-1E1E653FD0BC}.Release|Any CPU.Deploy.0 = Release|Any CPU |
|
22 |
{5C87F357-DF5A-4AEC-9663-ED55C0E4904D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
|
23 |
{5C87F357-DF5A-4AEC-9663-ED55C0E4904D}.Debug|Any CPU.Build.0 = Debug|Any CPU |
|
24 |
{5C87F357-DF5A-4AEC-9663-ED55C0E4904D}.Debug|Any CPU.Deploy.0 = Debug|Any CPU |
|
25 |
{5C87F357-DF5A-4AEC-9663-ED55C0E4904D}.Release|Any CPU.ActiveCfg = Release|Any CPU |
|
26 |
{5C87F357-DF5A-4AEC-9663-ED55C0E4904D}.Release|Any CPU.Build.0 = Release|Any CPU |
|
27 |
{5C87F357-DF5A-4AEC-9663-ED55C0E4904D}.Release|Any CPU.Deploy.0 = Release|Any CPU |
|
28 |
EndGlobalSection |
|
29 |
GlobalSection(SolutionProperties) = preSolution |
|
30 |
HideSolutionNode = FALSE |
|
31 |
EndGlobalSection |
|
32 |
GlobalSection(ExtensibilityGlobals) = postSolution |
|
33 |
SolutionGuid = {5962BE11-9ED3-4A22-B6CA-D8B4D3F98D54} |
|
34 |
EndGlobalSection |
|
35 |
EndGlobal |
Formats disponibles : Unified diff