/// <summary> /// Initializes a new instance of the MainViewModel class. /// </summary> public MainViewModel() { instance = this; // this sets the static Instance property to this instance. Plugins = new ObservableCollection <PluginBase>(); Devices = new ObservableCollection <Device>(); Motors = new ObservableCollection <MotorViewModel>(); Plugins.CollectionChanged += Plugins_CollectionChanged; Controllers = new ObservableCollection <ControllerViewModel>(); Controllers.CollectionChanged += Controllers_CollectionChanged; Robot = new Robot(); // This lets us know what's going on with the Robot's internal Joint collection. Robot.Controllers.CollectionChanged += RobotControllers_CollectionChanged; //InputSignalRegistry = new ViewModel.SignalSinkRegistryViewModel(); InputSignalRegistry = new ObservableDictionary <string, string>(); Messenger.Default.Register <Messages.RemoveController>(this, (message) => { Controllers.Remove(message.ControllerToRemove); com = this.Robot.Com; } ); }
/// <summary> /// Initializes a new instance of the MainViewModel class. /// </summary> public MainViewModel() { instance = this; // this sets the static Instance property to this instance. Plugins = new ObservableCollection<PluginBase>(); Devices = new ObservableCollection<Device>(); Motors = new ObservableCollection<MotorViewModel>(); Plugins.CollectionChanged += Plugins_CollectionChanged; Controllers = new ObservableCollection<ControllerViewModel>(); Controllers.CollectionChanged += Controllers_CollectionChanged; Robot = new Robot(); // This lets us know what's going on with the Robot's internal Joint collection. Robot.Controllers.CollectionChanged += RobotControllers_CollectionChanged; //InputSignalRegistry = new ViewModel.SignalSinkRegistryViewModel(); InputSignalRegistry = new ObservableDictionary<string, string>(); Messenger.Default.Register<Messages.RemoveController>(this, (message) => { Controllers.Remove(message.ControllerToRemove); com = this.Robot.Com; } ); }
/// <summary> /// Создает новый объект API с указанным транспортом пакетов сообщений /// </summary> /// <param name="transport">Транспорт пакетов сообщений, например HttpPacketTransport</param> public SuatmmExchange(IPacketTransport transport) { if (transport == null) { throw new ArgumentNullException(nameof(transport)); } this.transport = transport; }
/// <summary> /// Retorna o transporte para a conexão atual. /// Se ainda não estiver conectado, tenta conectar no servidor. /// O estado desconctado é um estado terminal. /// Retorna uma excessão caso não consiga conectar no servidor. /// </summary> /// <param name="forceConnect">Força uma reconexão mesmo que esteja desconectado.</param> /// <returns>O transporte atualmente conectado.</returns> protected IPacketTransport InternalGetTransport(bool forceConnect) { if (m_State == ChannelState.Connected) { return(m_transport); } lock (m_transportInitializeLock) { if (m_State == ChannelState.Connected) { return(m_transport); } if (!forceConnect) { if (m_State != ChannelState.NotConnected) { SocketException sex = new SocketException((int)SocketError.NotConnected); throw sex; } } m_State = ChannelState.Connecting; TcpClient client = new TcpClient(); IPacketTransport transport = null; try { client.Connect(m_remoteHostName, m_remotePort); // TODO: Channel: implement multiple transport options transport = new PacketTransport(client); transport.SetReceiveAction(OnPacketReceived); transport.SetDisconnectAction(OnDisconnected); transport.Start(); m_transport = transport; m_State = ChannelState.Connected; return(m_transport); } catch (Exception) { m_State = ChannelState.NotConnected; client?.Close(); transport?.Dispose(); throw; } } }
/// <summary> /// Gets the LoadCommand. /// </summary> public void LoadData(string ConfigPath) { //robot.setpointTimer.Stop(); if (robot.Com != null) { robot.Com.SendData = true; } BinaryFormatter ser = new BinaryFormatter(); FileStream reader; com = this.Robot.Com; if (ConfigPath != null) { reader = new FileStream(ConfigPath, FileMode.Open); } else { reader = new FileStream("data.ControllerConfig", FileMode.Open); } ApplicationData appData = (ApplicationData)ser.Deserialize(reader); reader.Close(); this.Controllers = appData.Controllers; this.InputSignalRegistry = appData.InputSignalRegistry; // We have to manually create new plugin instances foreach (var plugin in appData.Plugins) { PluginBase newPlugin = plugin.GetPlugin(); newPlugin.PostLoadSetup(); // This function calls any user code that's specified Plugins.Add(newPlugin); //(PluginBase)Activator.CreateInstance(AppDomain.CurrentDomain, "RobotApp", plugin.TypeName); } foreach (var controllerVm in this.Controllers) { // In the future, ControllerViewModel should have a Robot property that propogates to its controllers and motors if (controllerVm.Controller != null) { //this.Controllers.Add(new ControllerViewModel(new Controller() { Robot = this.Robot, Id = controllerVm.Id, FriendlyName = controllerVm.FriendlyName })); //controllerVm.Controller = new Controller() { Robot = this.Robot, Id = controllerVm.Id, FriendlyName = controllerVm.FriendlyName }; controllerVm.Controller.Robot = Robot; this.Robot.Controllers.Add(controllerVm.Id, controllerVm.Controller); foreach (var motor in controllerVm.Motors) { motor.Controller = controllerVm.Controller; motor.Controller.Robot = Robot; if (motor.Motor.ControlMode != ControlMode.Reserved) { motor.Controller.SendNum++; } this.Motors.Add(motor); MainViewModel.Instance.Robot.Motors.Add(motor.Motor); motor.Motor.UpdateConfiguration(); motor.SetupMessenger(); } } } if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs("Controllers")); } //robot.setpointTimer.Start(); robot.Com_UpdateSetpoints(); }
/// <summary> /// Gets the LoadCommand. /// </summary> public void LoadData(string ConfigPath) { //robot.setpointTimer.Stop(); if(robot.Com != null) robot.Com.SendData = true; BinaryFormatter ser = new BinaryFormatter(); FileStream reader; com = this.Robot.Com; if(ConfigPath != null) reader = new FileStream(ConfigPath, FileMode.Open); else reader = new FileStream("data.ControllerConfig", FileMode.Open); ApplicationData appData = (ApplicationData)ser.Deserialize(reader); reader.Close(); this.Controllers = appData.Controllers; this.InputSignalRegistry = appData.InputSignalRegistry; // We have to manually create new plugin instances foreach(var plugin in appData.Plugins) { PluginBase newPlugin = plugin.GetPlugin(); newPlugin.PostLoadSetup(); // This function calls any user code that's specified Plugins.Add(newPlugin); //(PluginBase)Activator.CreateInstance(AppDomain.CurrentDomain, "RobotApp", plugin.TypeName); } foreach (var controllerVm in this.Controllers) { // In the future, ControllerViewModel should have a Robot property that propogates to its controllers and motors if (controllerVm.Controller != null) { //this.Controllers.Add(new ControllerViewModel(new Controller() { Robot = this.Robot, Id = controllerVm.Id, FriendlyName = controllerVm.FriendlyName })); //controllerVm.Controller = new Controller() { Robot = this.Robot, Id = controllerVm.Id, FriendlyName = controllerVm.FriendlyName }; controllerVm.Controller.Robot = Robot; this.Robot.Controllers.Add(controllerVm.Id, controllerVm.Controller); foreach (var motor in controllerVm.Motors) { motor.Controller = controllerVm.Controller; motor.Controller.Robot = Robot; if (motor.Motor.ControlMode != ControlMode.Reserved) motor.Controller.SendNum++; this.Motors.Add(motor); MainViewModel.Instance.Robot.Motors.Add(motor.Motor); motor.Motor.UpdateConfiguration(); motor.SetupMessenger(); } } } if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("Controllers")); //robot.setpointTimer.Start(); robot.Com_UpdateSetpoints(); }