diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-07-12 14:03:47 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-07-12 14:03:47 +0300 |
| commit | 856a23723afcc9d48c0f019dc33a259ac6c279ed (patch) | |
| tree | 6cc82030ee2d9c74bd7f841bfdc6a0c163def97d /Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs | |
| parent | 70fe7f13b519df86420f8c2b97cf8eb3ab67e9a5 (diff) | |
| download | Tango-856a23723afcc9d48c0f019dc33a259ac6c279ed.tar.gz Tango-856a23723afcc9d48c0f019dc33a259ac6c279ed.zip | |
Implemented continuous request timeouts.
Implemented continuous request abort exception.
Added log object for real time logs.
Some work on PPC & Machine Studio.
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs')
| -rw-r--r-- | Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs new file mode 100644 index 000000000..636a73d3c --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs @@ -0,0 +1,77 @@ +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.Core; +using Tango.Integration.Operation; +using Tango.PMR.Connection; +using Tango.Transport.Adapters; + +namespace Tango.PPC.Common.Connection +{ + public class DefaultMachineProvider : ExtendedObject, IMachineProvider + { + private bool _isInitialized; + + public event EventHandler<MachineOperatorChangedEventArgs> MachineOperatorChanged; + + private Machine _machine; + public Machine Machine + { + get + { + return _machine; + } + private set + { + _machine = value; + RaisePropertyChangedAuto(); + } + } + + private IMachineOperator _machineOperator; + public IMachineOperator MachineOperator + { + get + { + return _machineOperator; + } + private set + { + var oldOperator = _machineOperator; + _machineOperator = value; + OnMachineOperatorChanged(oldOperator, _machineOperator); + RaisePropertyChangedAuto(); + } + } + + protected virtual void OnMachineOperatorChanged(IMachineOperator oldOperator, IMachineOperator newOperator) + { + MachineOperatorChanged?.Invoke(this, new MachineOperatorChangedEventArgs(oldOperator, newOperator)); + } + + public void Init() + { + if (!_isInitialized) + { + _isInitialized = true; + + Machine = ObservablesEntitiesAdapter.Instance.Machines.FirstOrDefault(); + ConnectToMachine(); + } + } + + private async void ConnectToMachine() + { + Transport.Discovery.UsbCommunicationScanner<ConnectRequest, ConnectResponse> scanner = new Transport.Discovery.UsbCommunicationScanner<ConnectRequest, ConnectResponse>(UsbSerialBaudRates.BR_9600); + var response = await scanner.Scan(new ConnectRequest() { Password = "1234" }, TimeSpan.FromSeconds(10)); + + var machine = new MachineOperator(response.Adapter); + await machine.Connect(); + MachineOperator = machine; + } + } +} |
