Révision c32a628f

Voir les différences:

TestXamConnections/TestXamConnections.Android/Connection/InternConnectionService.cs
12 12
using TestXamConnections.Models;
13 13
using TestXamConnections.Connection;
14 14
using TestXamConnections.Droid.Receivers;
15
using TestXamConnections.Helper;
15
using TestXamConnections.Device.RFID.Agrident;
16 16

  
17 17
namespace TestXamConnections.Droid.Connection
18 18
{
......
82 82
                    DataReceivedEvent.Invoke(this, Encoding.ASCII.GetBytes(AgridentConstants.ACTION_AGRIDENT_ERROR));
83 83
                    break;
84 84

  
85
                case AgridentConstants.ACTION_AGRIDENT_SERVICE_START:
86
                    DataReceivedEvent.Invoke(this, Encoding.ASCII.GetBytes(AgridentConstants.ACTION_AGRIDENT_SERVICE_START));
87
                    break;
88

  
89
                case AgridentConstants.ACTION_AGRIDENT_SERVICE_STOP:
90
                    DataReceivedEvent.Invoke(this, Encoding.ASCII.GetBytes(AgridentConstants.ACTION_AGRIDENT_SERVICE_STOP));
91
                    break;
92

  
93 85
                default:
94 86
                    break;
95 87
            }
TestXamConnections/TestXamConnections/Connection/ConnectionConstants.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Text;
4

  
5
namespace TestXamConnections.Connection
6
{
7
    /// <summary>
8
    /// Constantes de connexion à utiliser lors de l'utilisation 
9
    /// de la fonction Connect de IConnection Service
10
    /// </summary>
11
    public static class ConnectionConstants
12
    {
13
        public static readonly string MAC_ADDR_KEY = "mac_address";
14
        // public static readonly string LAUNCH_INTENT_KEY = "launch_intent";
15
        public static readonly string RECEIVABLE_INTENTS_KEY = "receivable_intents";
16

  
17
    }
18
}
TestXamConnections/TestXamConnections/Connection/IConnectionService.cs
2 2
using System.Collections.Generic;
3 3
using System.Text;
4 4
using System.Threading.Tasks;
5
using TestXamConnections.Helper;
6 5
using TestXamConnections.Models;
7 6

  
8 7
namespace TestXamConnections.Connection
......
20 19
        /// <summary>
21 20
        /// Fonction d'envoi de commande pour le bluetooth
22 21
        /// </summary>
23
        /// <param name="hexValues">Données à envoyer sous forme de tableau d'octets ou d'une chaine de caractère</param>
22
        /// <param name="hexValues">Données à envoyer sous forme de tableau d'octets</param>
24 23
        /// <returns>true si la commande s'est bien envoyée, false sinon.</returns>
25
        Task<bool> SendCommand(IConvertible hexValues);
24
        Task<bool> SendCommand(byte[] hexValues);
26 25

  
27 26
        /// <summary>
28 27
        /// Événement déclenché à la réception de données. Présente les donénes sous forme d’un tableau d’octets.
TestXamConnections/TestXamConnections/Connection/IConnectionServiceProvider.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Text;
4
using System.Threading.Tasks;
5
using TestXamConnections.Connection;
6

  
7
namespace TestXamConnections.Connection
8
{
9
    /// <summary>
10
    /// Type de connection service à demander.
11
    /// </summary>
12
    public enum ConnectionType
13
    {
14
        Bluetooth,
15
        Intern,
16
        Wifi
17
    }
18

  
19
    public interface IConnectionServiceProvider
20
    {
21
        IConnectionService GetConnectionServiceInstance(ConnectionType ct);
22
    }
23
}
TestXamConnections/TestXamConnections/Device/Balance/IBalance.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 static TestXamConnections.Device.Balance.Teo.TeoConstants;
8

  
9
namespace TestXamConnections.Device.Balance
10
{
11
    public interface IBalance : IDevice
12
    {
13
        /// <summary>
14
        /// Événement déclenché à la reception d'une pesée de la part du Teo.
15
        /// </summary>
16
        EventHandler<ReponsePesee> PeseeReceivedEvent { get; set; }
17

  
18
        /// <summary>
19
        /// Permet d’établir une connection bluetooth avec une balance. 
20
        /// Important : le bluetooth doit être activé, la balance allumée et les appareils doivent déjà être appairés.
21
        /// </summary>
22
        /// <returns>true si la connection a réussi, false sinon.</returns>
23
        Task<bool> ConnectToBalanceAsync();
24

  
25
        // <summary>
26
        /// Envoie d'une commande à la balance.
27
        /// </summary>
28
        /// <param name="commandType">La commande à envoyer.</param>
29
        /// <returns></returns>
30
        Task<bool> SendCommandAsync(TeoCommandType cmd);
31

  
32
    }
33
}
TestXamConnections/TestXamConnections/Device/Balance/Teo/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.Device.Balance;
8
using TestXamConnections.Models;
9
using Xamarin.Forms;
10
using static TestXamConnections.Device.Balance.Teo.TeoConstants;
11

  
12
namespace TestXamConnections.Device.Balance.Teo
13
{
14
    public class TeoBalance : IBalance
15
    {
16
        public DeviceInfo Device { get; set; }
17
        public IConnectionService ConnectionService { get; set; }
18
        public EventHandler<ReponsePesee> PeseeReceivedEvent { get; set; }
19

  
20
        public TeoBalance(DeviceInfo device)
21
        {
22
            Device.Name = device.Name;
23
            Device.MACAddress = device.MACAddress;
24
            ConnectionService = DependencyService.Get<IConnectionServiceProvider>().GetConnectionServiceInstance(ConnectionType.Bluetooth);
25
            ConnectionService.DataReceivedEvent += TeoDataReceived;
26
        }
27

  
28
        ~TeoBalance()
29
        {
30
            ConnectionService.DataReceivedEvent -= TeoDataReceived;
31
        }
32

  
33
        /* 
34
         * Fonction déclenchée à la reception de données par le ConnectionService
35
         * Trigger l'evenement TeoDataReceivedEvent ou TeoPeseeReceivedEvent.
36
         * 
37
         * IMPORTANT: Les trames du Teo peuvent arriver découpées,
38
         * Donc les données sont gardées dans un buffer d'envoi
39
         * nommé _bufferedData
40
         */
41
        private string _bufferedData;
42
        private void TeoDataReceived(object sender, byte[] buffer)
43
        {
44
            // Si le premier character est 2 (ASCII: STX)
45
            // Alors c'est le début de la trame.
46
            if (buffer[0] == 2)
47
            {
48
                _bufferedData = "";
49
                // Si character seul on quitte
50
                if (buffer.Length == 1)
51
                {
52
                    return;
53
                }
54
                // On enlève STX
55
                buffer = buffer.Skip(1).ToArray();
56
                // On mets le début de la trame dans buffer d'envoi
57
                _bufferedData += Encoding.ASCII.GetString(buffer);
58
            }
59

  
60
            // Si le dernier character est 13 (ASCII: CR)
61
            // Alors la trame est terminée
62
            if (buffer[^1] == 13)
63
            {
64
                // On enlève CR
65
                buffer = buffer.SkipLast(1).ToArray();
66
                // Conversion en chaîne de caractères
67
                // Et on complète le buffer d'envoi
68
                _bufferedData += Encoding.ASCII.GetString(buffer);
69
                
70
                // Trigger evènement en fonction de la trame
71
                if (_bufferedData.Length == 12)
72
                {
73
                    PeseeReceivedEvent.Invoke(this, new ReponsePesee(_bufferedData));
74
                }
75
                else if (_bufferedData[2] == '6')
76
                {
77
                    PeseeReceivedEvent.Invoke(this, new ReponsePesee("err"));
78
                } 
79
                else
80
                {
81
                    PeseeReceivedEvent.Invoke(this, new ReponsePesee("err"));
82
                }
83
            }
84
        }
85

  
86
        /// <summary>
87
        /// Permet d’établir une connection bluetooth avec la balance Teo. 
88
        /// Important : le bluetooth doit être activé, la balance allumée et les appareils doivent déjà être appairés.
89
        /// </summary>
90
        /// <returns>true si la connection a réussi, false sinon.</returns>
91
        public async Task<bool> ConnectToBalanceAsync()
92
        {
93
            Dictionary<string, string> param = new Dictionary<string, string>()
94
            {
95
                { ConnectionConstants.MAC_ADDR_KEY, Device.MACAddress }
96
            };
97
            return await ConnectionService.Connect(param);
98
        }
99

  
100
        /// <summary>
101
        /// Envoi d'une commande au Teo.
102
        /// </summary>
103
        /// <param name="commandType">La commande à envoyer.</param>
104
        /// <returns></returns>
105
        public async Task<bool> SendCommandAsync(TeoCommandType cmd)
106
        {
107
            byte[] commandValue = TeoCommandValues.GetValueOrDefault(cmd);
108
            return await ConnectionService.SendCommand(commandValue);
109
        }
110
    }
111
}
TestXamConnections/TestXamConnections/Device/Balance/Teo/TeoConstants.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Text;
4

  
5
namespace TestXamConnections.Device.Balance.Teo
6
{
7
    public static class TeoConstants
8
    {
9
        /// <summary>
10
        /// Liste des commandes disponibles pour la balance Teo, pour le programme INRAE.
11
        /// </summary>
12
        public enum TeoCommandType
13
        {
14
            // Voir documentation TEO INRAE 
15
            // Codes ASCII
16
            ModeOrdre,
17
            SortieOrdre,
18
            EmissionPoids,
19
            ModePeseeSimple,
20
            SortiePeseeSimple
21
        }
22

  
23
        public static readonly Dictionary<TeoCommandType, string> TeoCommandNames = new Dictionary<TeoCommandType, string>()
24
        {
25
            { TeoCommandType.ModeOrdre,         "Mode attente ordre"        },
26
            { TeoCommandType.SortieOrdre,       "Sortie mode ordre"         },
27
            { TeoCommandType.EmissionPoids,     "Emission poids"            },
28
            { TeoCommandType.ModePeseeSimple,   "Mode simple pesage"        },
29
            { TeoCommandType.SortiePeseeSimple, "Sortie mode simple pesage" }
30

  
31
        };
32

  
33
        public static readonly Dictionary<TeoCommandType, byte[]> TeoCommandValues = new Dictionary<TeoCommandType, byte[]>()
34
        {
35
            { TeoCommandType.ModeOrdre,         new byte[] { 0x02, 0x61, 0x0D } },
36
            { TeoCommandType.SortieOrdre,       new byte[] { 0x02, 0x6B, 0x0D } },
37
            { TeoCommandType.EmissionPoids,     new byte[] { 0x02, 0x63, 0x0D } },
38
            { TeoCommandType.ModePeseeSimple,   new byte[] { 0x02, 0x62, 0x0D } },
39
            { TeoCommandType.SortiePeseeSimple, new byte[] { 0x02, 0x65, 0x0D } }
40
        };
41
    }
42
}
TestXamConnections/TestXamConnections/Device/Barcode/Honeywell/BarcodeInternReader.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Text;
4

  
5
namespace TestXamConnections.Device.Barcode.Honeywell
6

  
7
    public class HoneywellInternReader
8
    {
9
        // TODO
10
    }
11
}
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 Device { 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<byte[]> BarcodeDataReceivedEvent { get; set; }
18

  
19
        public HoneywellBTReader(DeviceInfo device)
20
        {
21
            Device.Name = device.Name;
22
            Device.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
            BarcodeDataReceivedEvent.Invoke(this, e);
30
        }
31

  
32
        public async Task<bool> ConnectToBTReaderAsync()
33
        {
34
            Dictionary<string, string> param = new Dictionary<string, string>()
35
            {
36
                { ConnectionConstants.MAC_ADDR_KEY, Device.MACAddress }
37
            };
38
            bool ret = await ConnectionService.Connect(param);
39
            return ret;
40
        }
41
    }
42
}
TestXamConnections/TestXamConnections/Device/Barcode/IBarcodeReader.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Text;
4
using System.Threading.Tasks;
5

  
6
namespace TestXamConnections.Device.Barcode
7
{
8
    public interface IBarcodeReader : IDevice
9
    {
10
        /// <summary>
11
        /// Événement déclenché à la reception de données par le lecteur de code barre.
12
        /// </summary>
13
        public EventHandler<byte[]> BarcodeDataReceivedEvent { get; set; }
14

  
15
        Task<bool> ConnectToBTReaderAsync();
16
    }
17
}
TestXamConnections/TestXamConnections/Device/DeviceInfo.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Text;
4

  
5
namespace TestXamConnections.Device
6
{
7
    /// <summary>
8
    /// Représente un appareil caractérisé par un nom et une adresse MAC.
9
    /// </summary>
10
    public class DeviceInfo
11
    {
12
        /// <summary>
13
        /// Le nom de l'appareil.
14
        /// </summary>
15
        public string Name { get; set; }
16

  
17
        /// <summary>
18
        /// L'adresse MAC de l'appareil
19
        /// </summary>
20
        public string MACAddress { get; set; }
21

  
22
        public override string ToString()
23
        {
24
            return Name + ":" + MACAddress;
25
        }
26
    }
27
}
TestXamConnections/TestXamConnections/Device/IDevice.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Text;
4
using TestXamConnections.Connection;
5

  
6
namespace TestXamConnections.Device
7
{
8
    public interface IDevice
9
    {
10
        DeviceInfo Device { get; set; }
11
        IConnectionService ConnectionService { get; set; }
12
    }
13
}
TestXamConnections/TestXamConnections/Device/RFID/Agrident/AgridentConstants.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Text;
4

  
5
namespace TestXamConnections.Device.RFID.Agrident
6
{
7
    /// <summary>
8
    /// Constantes utilisées pour la communication avec le module Agrident Wedge.
9
    /// </summary>
10
    public class AgridentConstants
11
    {
12
        public const string ACTION_AGRIDENT_SUCCESS = "fr.coppernic.intent.agridentsuccess";
13
        public const string ACTION_AGRIDENT_ERROR = "fr.coppernic.intent.agridentfailed";
14
        public const string ACTION_AGRIDENT_SERVICE_STOP = "fr.coppernic.intent.action.stop.agrident.service";
15
        public const string ACTION_AGRIDENT_SERVICE_START = "fr.coppernic.intent.action.start.agrident.service";
16
        public const string ACTION_AGRIDENT_READ = "fr.coppernic.tools.agrident.wedge.READ";
17
        public const string KEY_BARCODE_DATA = "BarcodeData";
18
        public const string AGRIDENT_WEDGE = "fr.coppernic.tools.cpcagridentwedge";
19
    }
20
}
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 Xamarin.Forms;
7

  
8
namespace TestXamConnections.Device.RFID.Agrident
9
{
10
    /// <summary>
11
    /// Important: Cette classe est utilisable avec le lecteur agrident interne au C-One.
12
    /// </summary>
13
    public class AgridentInternReader : IRFIDReader
14
    {
15
        public DeviceInfo Device { get; set; }
16
        public IConnectionService ConnectionService { get; set; }
17
        /// <summary>
18
        /// Événement déclenché à la reception de données par le lecteur RFID Agrident.
19
        /// </summary>
20
        public EventHandler<string> RFIDDataReceivedEvent { get; set; }
21

  
22
        public AgridentInternReader()
23
        {
24
            ConnectionService = DependencyService.Get<IConnectionServiceProvider>().GetConnectionServiceInstance(ConnectionType.Intern);
25
            ConnectionService.DataReceivedEvent += InternDataReceived;
26
        }
27

  
28
        ~AgridentInternReader()
29
        {
30
            ConnectionService.DataReceivedEvent -= InternDataReceived;
31
        }
32

  
33
        /* Fonction déclenchée à la reception de données Agrident
34
         * Trigger l'évènement AgridentDataReceivedEvent
35
         */
36
        private void InternDataReceived(object sender, byte[] intent)
37
        {
38
            string data = Encoding.ASCII.GetString(intent);
39

  
40
            switch (data)
41
            {
42
                case AgridentConstants.ACTION_AGRIDENT_ERROR:
43
                    RFIDDataReceivedEvent.Invoke(this, "");
44
                    break;
45

  
46
                default:
47
                    RFIDDataReceivedEvent.Invoke(this, data);
48
                    break;
49
            }
50
        }
51

  
52
        /// <summary>
53
        /// Initialise la lecture de tag RFID avec lecteur interne Agrident.
54
        /// </summary>
55
        /// <returns>true la connexion a réussi, false sinon.</returns>
56
        public async Task<bool> EnableServiceAsync()
57
        {
58
            bool ret;
59
            // Enregistrement des intents recevable par Agrident
60
            List<string> intentsList = new List<string>()
61
            {
62
                AgridentConstants.ACTION_AGRIDENT_SUCCESS,
63
                AgridentConstants.ACTION_AGRIDENT_ERROR
64
            };
65
            string intents = string.Join(',', intentsList);
66

  
67
            // Encapuslation des intents recevables pour envoyer au service de connexion
68
            Dictionary<string, string> param = new Dictionary<string, string>()
69
            {
70
                { ConnectionConstants.RECEIVABLE_INTENTS_KEY, intents }
71
            };
72

  
73
            ret = await ConnectionService.Connect(param);
74
            return ret;
75
        }
76

  
77
        /// <summary>
78
        /// Lance un scan de tag RFID avec le lecteur Agrident interne.
79
        /// </summary>
80
        /// <returns>true si le scan s'est lancé correctement, false sinon.</returns>
81
        public async Task<bool> StartScanAsync()
82
        {
83
            return await ConnectionService.SendCommand(AgridentConstants.AGRIDENT_WEDGE);
84
        }
85

  
86
    }
87
}
TestXamConnections/TestXamConnections/Device/RFID/IRFIDReader.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Text;
4
using System.Threading.Tasks;
5

  
6
namespace TestXamConnections.Device.RFID
7
{
8
    public interface IRFIDReader : IDevice
9
    {
10
        /// <summary>
11
        /// Événement déclenché à la reception de données par le lecteur RFID.
12
        /// </summary>
13
        public EventHandler<string> RFIDDataReceivedEvent { get; set; }
14

  
15
        /// <summary>
16
        /// Initialise la lecture de tag RFID.
17
        /// </summary>
18
        /// <returns>true la connexion a réussi, false sinon.</returns>
19
        Task<bool> EnableServiceAsync();
20

  
21
        /// <summary>
22
        /// Lance un scan de tag RFID.
23
        /// </summary>
24
        /// <returns>true si le scan s'est lancé correctement, false sinon.</returns>
25
        Task<bool> StartScanAsync();
26
    }
27
}
TestXamConnections/TestXamConnections/Helper/ConnectionConstants.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Text;
4

  
5
namespace TestXamConnections.Helper
6
{
7
    /// <summary>
8
    /// Constantes de connexion à utiliser lors de l'utilisation 
9
    /// de la fonction Connect de IConnection Service
10
    /// </summary>
11
    public static class ConnectionConstants
12
    {
13
        public static readonly string MAC_ADDR_KEY = "mac_address";
14
        // public static readonly string LAUNCH_INTENT_KEY = "launch_intent";
15
        public static readonly string RECEIVABLE_INTENTS_KEY = "receivable_intents";
16

  
17
    }
18
}
TestXamConnections/TestXamConnections/Helper/IConnectionServiceProvider.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Text;
4
using System.Threading.Tasks;
5
using TestXamConnections.Connection;
6

  
7
namespace TestXamConnections.Helper
8
{
9
    /// <summary>
10
    /// Type de connection service à demander.
11
    /// </summary>
12
    public enum ConnectionType
13
    {
14
        Bluetooth,
15
        Intern,
16
        Wifi
17
    }
18

  
19
    public interface IConnectionServiceProvider
20
    {
21
        IConnectionService GetConnectionServiceInstance(ConnectionType ct);
22
    }
23
}
TestXamConnections/TestXamConnections/Models/AgridentReader.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.Helper;
7
using Xamarin.Forms;
8

  
9
namespace TestXamConnections.Models
10
{
11
    /// <summary>
12
    /// Constantes utilisées pour la communication avec le module Agrident Wedge.
13
    /// </summary>
14
    public class AgridentConstants
15
    {
16
        public const string ACTION_AGRIDENT_SUCCESS = "fr.coppernic.intent.agridentsuccess";
17
        public const string ACTION_AGRIDENT_ERROR = "fr.coppernic.intent.agridentfailed";
18
        public const string ACTION_AGRIDENT_SERVICE_STOP = "fr.coppernic.intent.action.stop.agrident.service";
19
        public const string ACTION_AGRIDENT_SERVICE_START = "fr.coppernic.intent.action.start.agrident.service";
20
        public const string ACTION_AGRIDENT_READ = "fr.coppernic.tools.agrident.wedge.READ";
21
        public const string KEY_BARCODE_DATA = "BarcodeData";
22
        public const string AGRIDENT_WEDGE = "fr.coppernic.tools.cpcagridentwedge";
23
    }
24

  
25
    public class AgridentReader
26
    {
27
        private IConnectionService ConnectionService { get; set; }
28

  
29
        /// <summary>
30
        /// Événement déclenché à la reception de données par le lecteur RFID.
31
        /// </summary>
32
        public EventHandler<string> AgridentDataReceivedEvent { get; set; }
33

  
34
        /// <summary>
35
        /// Événement déclenché lorsque le scan de tag RFID a échoué.
36
        /// </summary>
37
        public EventHandler AgridentNORFIDEvent { get; set; }
38

  
39
        /// <summary>
40
        /// Ne marche pas pour l'instant
41
        /// </summary>
42
        public EventHandler<bool> AgridentScanStatusChangedEvent { get; set; }
43

  
44
        public AgridentReader()
45
        {
46
            ConnectionService = DependencyService.Get<IConnectionServiceProvider>().GetConnectionServiceInstance(ConnectionType.Intern);
47
            ConnectionService.DataReceivedEvent += InternDataReceived;
48
        }
49

  
50
        ~AgridentReader()
51
        {
52
            ConnectionService.DataReceivedEvent -= InternDataReceived;
53
        }
54

  
55
        /* Fonction déclenchée à la reception de données Agrident
56
         * Trigger l'évènement AgridentDataReceivedEvent
57
         */
58
        private void InternDataReceived(object sender, byte[] intent)
59
        {
60
            string data = Encoding.ASCII.GetString(intent);
61

  
62
            switch (data)
63
            {
64
                case AgridentConstants.ACTION_AGRIDENT_ERROR:
65
                    AgridentNORFIDEvent.Invoke(this, null);
66
                    break;
67

  
68
                case AgridentConstants.ACTION_AGRIDENT_SERVICE_START:
69
                    AgridentScanStatusChangedEvent.Invoke(this, true);
70
                    break;
71

  
72
                case AgridentConstants.ACTION_AGRIDENT_SERVICE_STOP:
73
                    AgridentScanStatusChangedEvent.Invoke(this, false);
74
                    break;
75

  
76
                default:
77
                    AgridentDataReceivedEvent.Invoke(this, data);
78
                    break;
79
            }
80
        }
81

  
82
        /// <summary>
83
        /// Initialise la lecture de tag RFID.
84
        /// </summary>
85
        /// <returns>true la connexion a réussi, false sinon.</returns>
86
        public async Task<bool> EnableServiceAsync()
87
        {
88
            bool ret;
89
            // Enregistrement des intents recevable par Agrident
90
            List<string> intentsList = new List<string>()
91
            {
92
                AgridentConstants.ACTION_AGRIDENT_SUCCESS,
93
                AgridentConstants.ACTION_AGRIDENT_ERROR,
94
                AgridentConstants.ACTION_AGRIDENT_SERVICE_START,
95
                AgridentConstants.ACTION_AGRIDENT_SERVICE_STOP
96
            };
97
            string intents = string.Join(',', intentsList);
98

  
99
            // Encapuslation des intents recevables pour envoyer au service de connexion
100
            Dictionary<string, string> param = new Dictionary<string, string>()
101
            {
102
                { ConnectionConstants.RECEIVABLE_INTENTS_KEY, intents }
103
            };
104

  
105
            ret = await ConnectionService.Connect(param);
106
            return ret;
107
        }
108

  
109
        /// <summary>
110
        /// Lance un scan de tag RFID.
111
        /// </summary>
112
        /// <returns>true si le scan s'est lancé correctement, false sinon.</returns>
113
        public async Task<bool> StartScanAsync()
114
        {
115
            return await ConnectionService.SendCommand(AgridentConstants.AGRIDENT_WEDGE);
116
        }
117

  
118
    }
119
}
TestXamConnections/TestXamConnections/Models/BluetoothReader.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.Helper;
7
using Xamarin.Forms;
8

  
9
namespace TestXamConnections.Models
10
{
11
    public class BluetoothReader : Device
12
    {
13
        private IConnectionService ConnectionService { get; set; }
14
        public EventHandler<byte[]> BluetoothDataReceivedEvent { get; set; }
15

  
16
        public BluetoothReader(Device device)
17
        {
18
            Name = device.Name;
19
            MACAddress = device.MACAddress;
20
            ConnectionService = DependencyService.Get<IConnectionServiceProvider>().GetConnectionServiceInstance(ConnectionType.Bluetooth);
21
            ConnectionService.DataReceivedEvent += BluetoothDataReceived;
22
        }
23

  
24
        private void BluetoothDataReceived(object sender, byte[] e)
25
        {
26
            BluetoothDataReceivedEvent.Invoke(this, e);
27
        }
28

  
29
        public async Task<bool> ConnectToBTReaderAsync()
30
        {
31
            Dictionary<string, string> param = new Dictionary<string, string>()
32
            {
33
                { ConnectionConstants.MAC_ADDR_KEY, MACAddress }
34
            };
35
            bool ret = await ConnectionService.Connect(param);
36
            return ret;
37
        }
38
    }
39
}
TestXamConnections/TestXamConnections/Models/Device.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Text;
4

  
5
namespace TestXamConnections.Models
6
{
7
    /// <summary>
8
    /// Représente un appareil caractérisé par un nom et une adresse MAC.
9
    /// </summary>
10
    public class Device
11
    {
12
        /// <summary>
13
        /// Le nom de l'appareil.
14
        /// </summary>
15
        public string Name { get; set; }
16

  
17
        /// <summary>
18
        /// L'adresse MAC de l'appareil
19
        /// </summary>
20
        public string MACAddress { get; set; }
21

  
22
        public override string ToString()
23
        {
24
            return Name + ":" + MACAddress;
25
        }
26
    }
27
}
TestXamConnections/TestXamConnections/Models/ReponsePesee.cs
7 7
{
8 8
    public class ReponsePesee
9 9
    {
10

  
11
        private bool err;
12
        /// <summary>
13
        /// Indicateur si erreur de pesée
14
        /// </summary>
15
        public bool Err
16
        {
17
            get { return err; }
18
            set { err = value; }
19
        }
20

  
21

  
10 22
        private int numPlateau;
11 23
        /// <summary>
12 24
        /// Le numéro du plateau.
......
49 61

  
50 62
        public ReponsePesee(string data)
51 63
        {
52
            // Voir doc Balance Teo INRAE
53
            NumPlateau = int.Parse(data[0].ToString());
54
            TypePlateau = int.Parse(data[1].ToString());
55
            IsNegative = data[4] == '-';
56
            PoidsMesure = new string(data.Skip(5).ToArray()).Trim();
64
            if (data == "err")
65
            { 
66
                Err = true;
67
            } else
68
            {
69
                // Voir doc Balance Teo INRAE
70
                NumPlateau = int.Parse(data[0].ToString());
71
                TypePlateau = int.Parse(data[1].ToString());
72
                IsNegative = data[4] == '-';
73
                PoidsMesure = new string(data.Skip(5).ToArray()).Trim();
74

  
75
            }
57 76
        }
58 77
    }
59 78
}
TestXamConnections/TestXamConnections/Models/ReponseRFID.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Text;
4

  
5
namespace TestXamConnections.Models
6
{
7
    public class ReponseRFID
8
    {
9
        // TODO (doc JF Bompa)
10
    }
11
}
TestXamConnections/TestXamConnections/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
    /// <summary>
13
    /// Liste des commandes disponibles pour la balance Teo, pour le programme INRAE.
14
    /// </summary>
15
    public enum TeoCommandType
16
    {
17
        // Voir documentation TEO INRAE 
18
        // Codes ASCII
19
        ModeOrdre,
20
        EmissionPoids,
21
        SortieOrdreGardeBluetooth,
22
        SortieOrdreEtBluetooth,
23
        ModePeseeSimple,
24
        SortiePeseeSimple,
25
        PeseeStabilisee,
26
        InterrompPS,
27
        TareP1,
28
        TareP2,
29
        ZeroP1,
30
        ZeroP2,
31
        InfosMetrologie,
32
    }
33

  
34
    public class TeoBalance : Device
35
    {
36
        private IConnectionService ConnectionService { get; set; }
37

  
38
        /// <summary>
39
        /// Événement déclenché à la réception d'une donnée de la part du Teo, autre qu'une pesée.
40
        /// </summary>
41
        public EventHandler<string> TeoDataReceivedEvent { get; set; }
42
        /// <summary>
43
        /// Événement déclenché à la reception d'une pesée de la part du Teo.
44
        /// </summary>
45
        public EventHandler<ReponsePesee> TeoPeseeReceivedEvent { get; set; }
46

  
47
        public TeoBalance(Device device)
48
        {
49
            Name = device.Name;
50
            MACAddress = device.MACAddress;
51
            ConnectionService = DependencyService.Get<IConnectionServiceProvider>().GetConnectionServiceInstance(ConnectionType.Bluetooth);
52
            ConnectionService.DataReceivedEvent += TeoDataReceived;
53
        }
54

  
55
        ~TeoBalance()
56
        {
57
            ConnectionService.DataReceivedEvent -= TeoDataReceived;
58
        }
59

  
60
        /* 
61
         * Fonction déclenchée à la reception de données par le ConnectionService
62
         * Trigger l'evenement TeoDataReceivedEvent ou TeoPeseeReceivedEvent.
63
         * 
64
         * IMPORTANT: Les trames du Teo peuvent arriver découpées,
65
         * Donc les données sont gardées dans un buffer d'envoi
66
         * nommé _bufferedData
67
         */
68
        private string _bufferedData;
69
        private void TeoDataReceived(object sender, byte[] buffer)
70
        {
71
            // Si le premier character est 2 (ASCII: STX)
72
            // Alors c'est le début de la trame.
73
            if (buffer[0] == 2)
74
            {
75
                _bufferedData = "";
76
                // Si character seul on quitte
77
                if (buffer.Length == 1)
78
                {
79
                    return;
80
                }
81
                // On enlève STX
82
                buffer = buffer.Skip(1).ToArray();
83
                // On mets le début de la trame dans buffer d'envoi
84
                _bufferedData += Encoding.ASCII.GetString(buffer);
85
            }
86

  
87
            // Si le dernier character est 13 (ASCII: CR)
88
            // Alors la trame est terminée
89
            if (buffer[^1] == 13)
90
            {
91
                // On enlève CR
92
                buffer = buffer.SkipLast(1).ToArray();
93
                // Conversion en chaîne de caractères
94
                // Et on complète le buffer d'envoi
95
                _bufferedData += Encoding.ASCII.GetString(buffer);
96
                
97
                // Trigger evènement en fonction de la trame
98
                if (_bufferedData.Length == 12)
99
                {
100
                    TeoPeseeReceivedEvent.Invoke(this, new ReponsePesee(_bufferedData));
101
                }
102
                else if (_bufferedData[2] == '6')
103
                {
104
                    TeoDataReceivedEvent.Invoke(this, "Erreur pesée");
105
                } 
106
                else
107
                {
108
                    TeoDataReceivedEvent.Invoke(this, _bufferedData);
109
                }
110
            }
111
        }
112

  
113
        /// <summary>
114
        /// Permet d’établir une connection bluetooth avec la balance Teo. 
115
        /// Important : le bluetooth doit être activé, la balance allumée et les appareils doivent déjà être appairés.
116
        /// </summary>
117
        /// <returns>true si la connection a réussi, false sinon.</returns>
118
        public async Task<bool> ConnectToTeoAsync()
119
        {
120
            Dictionary<string, string> param = new Dictionary<string, string>()
121
            {
122
                { ConnectionConstants.MAC_ADDR_KEY, MACAddress }
123
            };
124
            _ = await ConnectionService.Connect(param);
125
            return true;
126
        }
127

  
128
        /// <summary>
129
        /// Envoie d'une commande au Teo.
130
        /// </summary>
131
        /// <param name="commandType">La commande à envoyer.</param>
132
        /// <returns></returns>
133
        public async Task<bool> SendTeoCommandAsync(TeoCommandType commandType)
134
        {
135
            return await ConnectionService.SendCommand(GetCommandCode(commandType));
136
        }
137

  
138
        /// <summary>
139
        /// Récupère le code hexadécimal d'une commande donnée.
140
        /// </summary>
141
        /// <param name="commandType">La commande dont on souhaite le code hexa.</param>
142
        /// <returns>Le code héxadécimal de la command sur forme de tableau d'octet.</returns>
143
        public static byte[] GetCommandCode(TeoCommandType commandType)
144
        {
145
            // Les commandes envoyées sont sur 3 octets
146
            byte[] ret = new byte[3];
147
            // STX
148
            ret[0] = 0x02;
149
            // CR
150
            ret[2] = 0x0D;
151

  
152
            // Commande
153
            switch (commandType)
154
            {
155
                case TeoCommandType.ModeOrdre:
156
                    ret[1] = 0x61;
157
                    break;
158

  
159
                case TeoCommandType.SortieOrdreGardeBluetooth:
160
                    ret[1] = 0x6B;
161
                    break;
162

  
163
                case TeoCommandType.SortieOrdreEtBluetooth:
164
                    ret[1] = 0x67;
165
                    break;
166

  
167
                case TeoCommandType.ModePeseeSimple:
168
                    ret[1] = 0x62;
169
                    break;
170

  
171
                case TeoCommandType.SortiePeseeSimple:
172
                    ret[1] = 0x65;
173
                    break;
174

  
175
                case TeoCommandType.TareP1:
176
                    ret[1] = 0x74;
177
                    break;
178

  
179
                case TeoCommandType.TareP2:
180
                    ret[1] = 0x6A;
181
                    break;
182

  
183
                case TeoCommandType.ZeroP1:
184
                    ret[1] = 0x7A;
185
                    break;
186

  
187
                case TeoCommandType.ZeroP2:
188
                    ret[1] = 0x64;
189
                    break;
190

  
191
                case TeoCommandType.InfosMetrologie:
192
                    ret[1] = 0x73;
193
                    break;
194

  
195
                case TeoCommandType.EmissionPoids:
196
                    ret[1] = 0x63;
197
                    break;
198
                // TODO
199
                case TeoCommandType.PeseeStabilisee:
200
                    break;
201

  
202
                case TeoCommandType.InterrompPS:
203
                    break;
204

  
205
                default:
206
                    break;
207
            }
208
            return ret;
209
        }
210

  
211
        /// <summary>
212
        /// Recupère le nom d'une commande donnée.
213
        /// </summary>
214
        /// <param name="commandType">La commande dont on souhaite le nom.</param>
215
        /// <returns>Le nom de la commande.</returns>
216
        public static string GetCommandName(TeoCommandType commandType)
217
        {
218
            // Les commandes envoyées sont sur 3 octets
219
            string ret = "";
220

  
221
            // Commande
222
            switch (commandType)
223
            {
224
                case TeoCommandType.ModeOrdre:
225
                    ret = "Mode attente ordre";
226
                    break;
227

  
228
                case TeoCommandType.SortieOrdreGardeBluetooth:
229
                    ret = "Sortie mode ordre";
230
                    break;
231

  
232
                case TeoCommandType.SortieOrdreEtBluetooth:
233
                    ret = "Sortie mode ordre & couper bluetooth";
234
                    break;
235

  
236
                case TeoCommandType.ModePeseeSimple:
237
                    ret = "Mode simple pesage";
238
                    break;
239

  
240
                case TeoCommandType.SortiePeseeSimple:
241
                    ret = "Sortie mode simple pesage";
242
                    break;
243

  
244
                case TeoCommandType.TareP1:
245
                    ret = "Tare plateau 1";
246
                    break;
247

  
248
                case TeoCommandType.TareP2:
249
                    ret = "Tare plateau 2";
250
                    break;
251

  
252
                case TeoCommandType.ZeroP1:
253
                    ret = "Zero plateau 1";
254
                    break;
255

  
256
                case TeoCommandType.ZeroP2:
257
                    ret = "Zero plateau 2";
258
                    break;
259

  
260
                case TeoCommandType.InfosMetrologie:
261
                    ret = "Informations métrologie";
262
                    break;
263

  
264
                case TeoCommandType.EmissionPoids:
265
                    ret = "Emission poids";
266
                    break;
267
                // TODO
268
                case TeoCommandType.PeseeStabilisee:
269
                    ret = "Pesée stabilisée - NON implémenté";
270
                    break;
271

  
272
                case TeoCommandType.InterrompPS:
273
                    ret = "STOP Pesée stabilisée - NON implémenté";
274
                    break;
275

  
276
                default:
277
                    break;
278
            }
279
            return ret;
280
        }
281

  
282
    }
283
}
TestXamConnections/TestXamConnections/ViewModels/BluetoothReaderViewModel.cs
3 3
using System.Text;
4 4
using System.Threading.Tasks;
5 5
using System.Windows.Input;
6
using TestXamConnections.Device;
7
using TestXamConnections.Device.Barcode;
8
using TestXamConnections.Device.Barcode.Honeywell;
6 9
using TestXamConnections.Models;
7 10
using Xamarin.Forms;
8 11

  
......
10 13
{
11 14
    public class BluetoothReaderViewModel : ViewModelBase
12 15
    {
13
        private BluetoothReader btReader;
16
        private IBarcodeReader btReader;
14 17
        private bool isVisibleData;
15 18
        private string data;
16 19
        private string connectionIndicator;
......
40 43
            set => SetProperty(ref isVisibleData, value);
41 44
        }
42 45

  
43
        public BluetoothReader BTReader
46
        public IBarcodeReader BCReader
44 47
        {
45 48
            get => btReader;
46 49
            set => SetProperty(ref btReader, value);
......
48 51

  
49 52
        public async Task<bool> ConnectToDevice()
50 53
        {
51
            if (await BTReader.ConnectToBTReaderAsync())
54
            if (await BCReader.ConnectToBTReaderAsync())
52 55
            {
53 56
                ConnectionIndicator = "Connecté";
54 57
                CIColor = "Green";
......
64 67

  
65 68
        public ICommand ConnectToDeviceCommand { get; private set; }
66 69

  
67
        public BluetoothReaderViewModel(Models.Device device)
70
        public BluetoothReaderViewModel(DeviceInfo deviceI)
68 71
        {
69 72
            CIColor = "Red";
70 73
            ConnectionIndicator = "Non connecté";
71 74
            IsVisibleData = false;
72
            BTReader = new BluetoothReader(device);
75
            BCReader = new HoneywellBTReader(deviceI);
73 76
            ConnectToDeviceCommand = new Command(async () => await ConnectToDevice());
74
            BTReader.BluetoothDataReceivedEvent += DataReceived;
77
            BCReader.BarcodeDataReceivedEvent += DataReceived;
75 78
        }
76 79

  
77 80
        private void DataReceived(object sender, byte[] e)
TestXamConnections/TestXamConnections/ViewModels/CommandItemViewModel.cs
1
using System.Threading.Tasks;
1
using System.Collections.Generic;
2
using System.Threading.Tasks;
2 3
using System.Windows.Input;
3 4
using TestXamConnections.Connection;
4
using TestXamConnections.Helper;
5 5
using TestXamConnections.Models;
6 6
using TestXamConnections.Services;
7 7
using Xamarin.Forms;
8
using static TestXamConnections.Device.Balance.Teo.TeoConstants;
8 9

  
9 10
namespace TestXamConnections.ViewModels
10 11
{
......
35 36
        public CommandItemViewModel(TeoCommandType cmd)
36 37
        {
37 38
            ToSendCommand = cmd;
38
            Name = TeoBalance.GetCommandName(cmd);
39
            CommandBytes = string.Join("-", TeoBalance.GetCommandCode(cmd));
39
            Name = TeoCommandNames.GetValueOrDefault(cmd);
40
            CommandBytes = string.Join("-", TeoCommandValues.GetValueOrDefault(cmd));
40 41
        }
41 42

  
42 43
    }
TestXamConnections/TestXamConnections/ViewModels/DeviceItemViewModel.cs
4 4
using System.Text;
5 5
using System.Threading.Tasks;
6 6
using System.Windows.Input;
7
using TestXamConnections.Device;
7 8
using TestXamConnections.Models;
8 9
using TestXamConnections.Services;
9 10
using TestXamConnections.Views;
......
13 14
{
14 15
    public class DeviceItemViewModel : ViewModelBase
15 16
    {
16
        private Models.Device device;
17
        public Models.Device Device
17
        private DeviceInfo deviceI;
18
        public DeviceInfo DeviceI
18 19
        {
19 20

  
20
            get => device;
21
            get => deviceI;
21 22

  
22
            set => SetProperty(ref device, value);
23
            set => SetProperty(ref deviceI, value);
23 24
        }
24 25

  
25 26
        private async Task NavigateToDevice()
26 27
        {
27 28
            // Si c'est le teo du bureau
28
            if (Device.MACAddress == "60:A4:23:EB:FB:5C")
29
            if (DeviceI.MACAddress == "60:A4:23:EB:FB:5C")
29 30
            {
30
                await Application.Current.MainPage.Navigation.PushAsync(new TeoDeviceView(Device));
31
                await Application.Current.MainPage.Navigation.PushAsync(new TeoDeviceView(DeviceI));
31 32
            }
32 33
            // Si c'est le scanner HoneyWell
33
            else if (Device.MACAddress == "00:10:20:30:92:7D")
34
            else if (DeviceI.MACAddress == "00:10:20:30:92:7D" || DeviceI.MACAddress == "00:04:3E:54:A9:B8")
34 35
            {
35
                await Application.Current.MainPage.Navigation.PushAsync(new BluetoothReaderView(Device));
36
                await Application.Current.MainPage.Navigation.PushAsync(new BluetoothReaderView(DeviceI));
36 37
            }
37 38
        }
38 39

  
39 40
        public ICommand NavigateToDeviceViewCommand { private set; get; }
40 41

  
41
        public DeviceItemViewModel(Models.Device device)
42
        public DeviceItemViewModel(DeviceInfo deviceInfo)
42 43
        {
43
            Device = device;
44
            DeviceI = deviceInfo;
44 45
            NavigateToDeviceViewCommand = new Command(async () => await NavigateToDevice());
45 46
        }
46 47

  
47
        public void Update(Models.Device newDevice = null)
48
        public void Update(DeviceInfo newDevice = null)
48 49
        {
49 50
            if (newDevice != null)
50 51
            {
51
                Device = newDevice;
52
                DeviceI = newDevice;
52 53
            }
53 54
        }
54 55
    }
TestXamConnections/TestXamConnections/ViewModels/InternServiceViewModel.cs
13 13
        private bool isScanning;
14 14
        private bool showRFID;
15 15
        private bool showError;
16
        private readonly AgridentReader agridentReader;
16
        private readonly AgridentInternReader agridentReader;
17 17
        private string rfidResult;
18 18
        private string errorMessage;
19 19

  
......
65 65
            ShowError = false;
66 66
            RFIDResult = "";
67 67
            ErrorMessage = "";
68
            agridentReader = new AgridentReader();
68
            agridentReader = new AgridentInternReader();
69 69
            agridentReader.AgridentDataReceivedEvent += OnRFIDResultReceived;
70 70
            agridentReader.AgridentNORFIDEvent += OnNoRFIDReceived;
71 71
            agridentReader.AgridentScanStatusChangedEvent += OnScanStatusChanged;
TestXamConnections/TestXamConnections/ViewModels/TeoDeviceViewModel.cs
5 5
using System.Threading.Tasks;
6 6
using System.Windows.Input;
7 7
using TestXamConnections.Connection;
8
using TestXamConnections.Helper;
8
using TestXamConnections.Device;
9
using TestXamConnections.Device.Balance;
10
using TestXamConnections.Device.Balance.Teo;
9 11
using TestXamConnections.Models;
10 12
using TestXamConnections.Services;
11 13
using Xamarin.Forms;
12
using static TestXamConnections.Models.TeoBalance;
14
using static TestXamConnections.Device.Balance.Teo.TeoConstants;
13 15

  
14 16
namespace TestXamConnections.ViewModels
15 17
{
......
17 19
    {
18 20
        private bool isConnected;
19 21
        private string data;
20
        private TeoBalance teoScale;
22
        private IBalance teoScale;
21 23
        private bool isVisibleData;
22 24
        private bool showError;
23 25
        private string errorMessage;
......
34 36
            set { SetProperty(ref isConnected, value); }
35 37
        }
36 38

  
37
        public TeoBalance TeoScale
39
        public IBalance TeoScale
38 40
        {
39 41
            get { return teoScale; }
40 42
            set { SetProperty(ref teoScale, value); }
......
63 65
        public async Task<bool> ConnectToDevice()
64 66
        {
65 67
            ShowError = false;
66
            IsConnected = await teoScale.ConnectToTeoAsync();
68
            IsConnected = await teoScale.ConnectToBalanceAsync();
67 69
            return IsConnected;
68 70
        }
69 71

  
70
        public async Task<bool> SendValue(TeoCommandType cmd)
71
        {
72
            return await teoScale.SendTeoCommandAsync(cmd);
73
        }
74

  
75 72
        public ICommand ConnectToDeviceCommand { private set; get; }
76 73
        public ICommand SendValueCommand { private set; get; }
77 74

  
78
        public TeoDeviceViewModel(Models.Device device)
75
        public TeoDeviceViewModel(DeviceInfo device)
79 76
        {
80 77
            TeoScale = new TeoBalance(device);
81 78
            ShowError = false;
82 79
            IsConnected = false;
83 80
            IsVisibleData = false;
84 81
            ConnectToDeviceCommand = new Command(async () => await ConnectToDevice());
85
            SendValueCommand = new Command(async (cmd) => await teoScale.SendTeoCommandAsync((TeoCommandType)cmd));
86
            TeoScale.TeoDataReceivedEvent = DataReceived;
87
            TeoScale.TeoPeseeReceivedEvent = PeseeReceived;
82
            SendValueCommand = new Command(async (cmd) => await teoScale.SendCommandAsync((TeoCommandType)cmd));
83
            TeoScale.PeseeReceivedEvent = PeseeReceived;
88 84

  
89 85
            // Ajout manuel des commandes
90 86
            AvailableCommandsList = new ObservableCollection<CommandItemViewModel>();
......
94 90
            }
95 91
        }
96 92

  
97
        public void DataReceived(object sender, string args)
98
        {
99
            IsVisibleData = true;
100
            Data += args.Trim() + "\n";
101
        }
102

  
103 93
        public void PeseeReceived(object sender, ReponsePesee args)
104 94
        {
105
            Data = args.PoidsMesure;
95
            if (args.Err == false)
96
            {
97
                Data = args.PoidsMesure;
98
            } else
99
            {
100
                Data = "Erreur de lecture";
101
            }
106 102
        }
107 103
    }
108 104
}
TestXamConnections/TestXamConnections/Views/BluetoothReaderView.xaml.cs
3 3
using System.Linq;
4 4
using System.Text;
5 5
using System.Threading.Tasks;
6
using TestXamConnections.Device;
6 7
using TestXamConnections.ViewModels;
7 8
using Xamarin.Forms;
8 9
using Xamarin.Forms.Xaml;
......
12 13
    [XamlCompilation(XamlCompilationOptions.Compile)]
... Ce différentiel a été tronqué car il excède la taille maximale pouvant être affichée.

Formats disponibles : Unified diff