aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Integration/Services/ExternalBridgeUsbClient.cs
blob: 4edf78bae4fac71029dbc47bbab4bbc1ac565858 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.BL;
using Tango.BL.Entities;
using Tango.Integration.Operation;
using Tango.PMR.Integration;
using Tango.Settings;
using Tango.Transport.Adapters;
using Tango.Transport.Transporters;

namespace Tango.Integration.Services
{
    /// <summary>
    /// Represents an external bridge USB client.
    /// </summary>
    /// <remarks>
    /// This isn't really an external bridge client, but merely a transporter for communicating with a Tango machine embedded device.
    /// </remarks>
    /// <seealso cref="Tango.Transport.Transporters.BasicTransporter" />
    /// <seealso cref="Tango.Integration.Services.IExternalBridgeClient" />
    public class ExternalBridgeUsbClient : MachineOperator, IExternalBridgeClient
    {
        private Machine _machine;
        /// <summary>
        /// Gets the machine database entity.
        /// </summary>
        public Machine Machine
        {
            get
            {
                return _machine;
            }
        }

        private String _serialNumber;
        /// <summary>
        /// Gets the machine serial number.
        /// </summary>
        public String SerialNumber
        {
            get { return _serialNumber; }
            set
            {
                _serialNumber = value;
                RaisePropertyChangedAuto();

                _machine = ObservablesEntitiesAdapter.Instance.Machines.SingleOrDefault(x => x.SerialNumber == _serialNumber);
                RaisePropertyChanged(nameof(Machine));
            }
        }

        private String _comPort;
        /// <summary>
        /// Gets or sets the serial COM port.
        /// </summary>
        public String ComPort
        {
            get { return _comPort; }
            set { _comPort = value; RaisePropertyChangedAuto(); }
        }

        private String _Device;
        /// <summary>
        /// Gets or sets the USB device name.
        /// </summary>
        public String Device
        {
            get { return _Device; }
            set { _Device = value; RaisePropertyChangedAuto(); }
        }

        /// <summary>
        /// Connects the transport component.
        /// </summary>
        /// <returns></returns>
        public override async Task Connect()
        {
            await Disconnect();
            Adapter = new UsbTransportAdapter(ComPort);
            await base.Connect();
        }

        /// <summary>
        /// Gets a value indicating whether this client requires authentication.
        /// </summary>
        public bool RequiresAuthentication => false;

        /// <summary>
        /// Initializes a new instance of the <see cref="ExternalBridgeUsbClient"/> class.
        /// </summary>
        /// <param name="comPort">The COM port.</param>
        /// <param name="device">The device.</param>
        public ExternalBridgeUsbClient(String comPort, String device)
        {
            ComPort = comPort;
            Device = device;
            UseKeepAlive = false;
            EnableDiagnostics = true;
        }

        /// <summary>
        /// Returns a <see cref="System.String" /> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String" /> that represents this instance.
        /// </returns>
        public override string ToString()
        {
            return Device;
        }
    }
}