Пример #1
0
        public override Task OnDisconnected(bool stopCalled)
        {
            // monitorThread?.StopMonitor();

            OnConnectionStatusChanged?.Invoke(stopCalled);
            return(base.OnDisconnected(stopCalled));
        }
Пример #2
0
        /// <summary>
        /// The connected hid device was disconnected
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnDisconnected(object sender, EventArgs e)
        {
            this.IsConnected = false;
            this.AxisCollection.Clear();
            this.Report.AxisStateCollection.Clear();

            OnConnectionStatusChanged?.Invoke(this, new ConnectionEventArgs(ConnectionEventArgs.EventType.ConnectionLost, null));
        }
Пример #3
0
        /// <summary>
        /// Change in the status of TWS connection state
        /// </summary>
        /// <returns>true = connected to TWS</returns>
        private static bool ConnectionStatusChanged()
        {
            bool status = ibclient.ClientSocket.IsConnected();

            // Inform any listeners of the new status
            OnConnectionStatusChanged?.Invoke(status);

            return(status);
        }
Пример #4
0
 private void SendFinishedCallback(Status status)
 {
     OnCheckFinished?.Invoke(status);
     if (status != LastStatus)
     {
         OnConnectionStatusChanged?.Invoke(status);
     }
     LastStatus = status;
 }
Пример #5
0
        public override Task OnConnected()
        {
            OnConnectionStatusChanged?.Invoke(true);

            //monitorThread = new MonitorThread();
            //monitorThread.StartMonitor();


            return(base.OnConnected());
        }
Пример #6
0
        private static void ConnectionStatusChanged(SteamNetConnectionStatusChangedCallback_t data)
        {
            //
            // This is a message from/to a listen socket
            //
            if (data.Nfo.listenSocket.Id > 0)
            {
                var iface = GetSocketManager(data.Nfo.listenSocket.Id);
                iface?.OnConnectionChanged(data.Conn, data.Nfo);
            }
            else
            {
                var iface = GetConnectionManager(data.Conn.Id);
                iface?.OnConnectionChanged(data.Nfo);
            }

            OnConnectionStatusChanged?.Invoke(data.Conn, data.Nfo);
        }
Пример #7
0
        //Close connection
        public void Disconnect()
        {
            if (IsConnected)
            {
#if !DEMO
                try
                {
                    _connection.Close();
                }
                catch (MySqlException ex)
                {
                    Status = ex.Message;
                }
#else
                _isConnected = false;
#endif
            }

            if (MbData != null)
            {
                lock (MbData)
                    MbData.Clear();
            }
            if (MbAlarm != null)
            {
                lock (MbAlarm)
                    MbAlarm.Clear();
            }
            if (LatestData != null)
            {
                lock (LatestData)
                    LatestData.Clear();
            }

            if (_isRetrieving != null)
            {
                _isRetrieving.Close();
            }

            EventAggregator.SignalIsRetrievingData("", false);
            OnConnectionStatusChanged?.Invoke(this, null);
        }
Пример #8
0
        public void Connect(string ipAddress, int port, string dbname, string username, string password)
        {
            Initialize(ipAddress, port, dbname, username, password);

            if (!IsConnected)
            {
#if !DEMO
                try
                {
                    _connection.Open();
                    _isRetrieving = new Semaphore(1, 1);
                }
                catch (MySqlException ex)
                {
                    //When handling errors, you can your application's response based
                    //on the error number.
                    //The two most common error numbers when connecting are as follows:
                    //0: Cannot connect to server.
                    //1045: Invalid user name and/or password.
                    switch (ex.Number)
                    {
                    case 0:
                        Status = resourceDictionary["M_Error4"] + "";
                        break;

                    case 1045:
                        Status = resourceDictionary["M_Error5"] + "";
                        break;
                    }
                }
#else
                _isConnected = true;
#endif
            }

            OnConnectionStatusChanged?.Invoke(this, null);
        }
Пример #9
0
 private void SocketClient_OnConnectionStatusChanged(object sender, ConnectionStatusChangedEventArgs e)
 {
     OnConnectionStatusChanged?.Invoke(this, e);
 }
Пример #10
0
        /// <summary>
        /// Open the controller
        /// </summary>
        public bool OpenDevice()
        {
            int _reconn_counter = 0;

            this.IsConnected = false;

            while (true)
            {
                try
                {
                    _reconn_counter++;

                    if (_hid_device.Connect())
                    {
                        // Start the received task on the UI thread
                        OnConnectionStatusChanged?.Invoke(this, new ConnectionEventArgs(ConnectionEventArgs.EventType.ConnectionSuccess, null));

                        // start to read hid report from usb device in the background thread
                        ////_hid_device.StartRead();

                        // to realize the mechanism of timeout, save the time when the initialization process is started
                        DateTime _init_start_time = DateTime.Now;

                        // Wait the first report from HID device in order to get the 'TotalAxes'
                        do
                        {
                            // read hid report
                            byte[] report = _hid_device.Read();
                            if (report != null)
                            {
                                this.Report.ParseRawData(report);

                                this.TotalAxes = this.Report.TotalAxes;
                            }

                            // Don't check it so fast, the interval of two adjacent report is normally 20ms but not certain
                            Thread.Sleep(100);

                            // check whether the initialization process is timeout
                            if ((DateTime.Now - _init_start_time).TotalSeconds > 5)
                            {
                                this.LastError = "unable to get the total axes";
                                break;
                            }
                        } while (this.TotalAxes <= 0);

                        // TotalAxes <= 0 indicates that no axis was found within 5 seconds, exit initialization process
                        if (this.TotalAxes <= 0)
                        {
                            break;
                        }

                        // the total number of axes returned, generate the instance of each axis
                        this.Report.AxisStateCollection.Clear();

                        // create the axis collection according the TotalAxes property in the hid report
                        for (int i = 0; i < this.TotalAxes; i++)
                        {
                            // generate axis state object to the controller report class
                            this.Report.AxisStateCollection.Add(new AxisState()
                            {
                                AxisIndex = i
                            });

                            // generate axis control on the user window
                            this.AxisCollection.Add(new Axis()
                            {
                                // set the properties to the default value
                                MaxSteps          = 15000,
                                SoftCCWLS         = 0,
                                SoftCWLS          = 15000,
                                PosAfterHome      = 0,
                                MaxSpeed          = MAX_VELOCITY,
                                AccelerationSteps = ACC_DEC_STEPS
                            });
                        }

                        // start to read the hid report repeatedly
                        _hid_device.StartRead();


                        this.IsConnected = true;

                        // initialize this.Report property on UI thread
                        OnConnectionStatusChanged?.Invoke(this, new ConnectionEventArgs(ConnectionEventArgs.EventType.TotalAxesReturned, this.TotalAxes));
                        break;
                    }
                    else
                    {
                        // pass the try-times to UI thread
                        OnConnectionStatusChanged?.Invoke(this, new ConnectionEventArgs(ConnectionEventArgs.EventType.ConnectionRetried, _reconn_counter));
                        Thread.Sleep(500);

                        // check if reaches the max re-connect times
                        if (_reconn_counter > 10)
                        {
                            this.LastError = "the initialization process was timeout";
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    this.LastError = ex.Message;
                    break;
                }
            }

            return(IsConnected);
        }
Пример #11
0
 private void Dialer_StateChanged(object sender, StateChangedEventArgs e)
 {
     status = e.State.ToString();
     OnConnectionStatusChanged?.Invoke();
 }
Пример #12
0
 public static void SendConnectionStatusChange(object sender, MessageHubArgs e)
 {
     OnConnectionStatusChanged?.Invoke(sender, e);
 }
Пример #13
0
        /// <summary>
        /// Open the controller
        /// </summary>
        public bool Open()
        {
            this.IsConnected = false;

            try
            {
                OnConnectionStatusChanged?.Invoke(this, new ConnectionEventArgs(ConnectionEventArgs.EventType.Connecting));

                if (hidPort.ConnectDevice())
                {
                    // to realize the mechanism of timeout, save the time when the initialization process is started
                    DateTime _init_start_time = DateTime.Now;

                    // Wait the first report from HID device in order to get the 'TotalAxes'
                    do
                    {
                        Request(EnumCommand.REQ_SYSTEM_STATE, out byte[] buff);

                        if (buff != null)
                        {
                            HidReport.Parse(buff);
                            TotalAxes = HidReport.TotalAxes;
                        }

                        // Don't check it so fast, the interval of two adjacent report is normally 20ms but not certain
                        Thread.Sleep(100);

                        // check whether the initialization process is timeout
                        if ((DateTime.Now - _init_start_time).TotalSeconds > 5)
                        {
                            break;
                        }
                    } while (TotalAxes <= 0);

                    // TotalAxes <= 0 indicates that no axis was found within 5 seconds, exit initialization process
                    if (this.TotalAxes > 0)
                    {
                        // the total number of axes returned, generate the instance of each axis
                        this.HidReport.AxisStateCollection.Clear();

                        // create the axis collection according the TotalAxes property in the hid report
                        for (int i = 0; i < this.TotalAxes; i++)
                        {
                            // generate axis state object to the controller report class
                            this.HidReport.AxisStateCollection.Add(new AxisStateReport()
                            {
                                AxisIndex = i
                            });

                            // generate axis control on the user window
                            this.AxisCollection.Add(new Axis()
                            {
                                // set the properties to the default value
                                MaxSteps          = 0,
                                SoftCCWLS         = 0,
                                SoftCWLS          = 0,
                                PosAfterHome      = 0,
                                MaxSpeed          = MAX_VELOCITY,
                                AccelerationSteps = ACC_DEC_STEPS
                            });
                        }

                        // read the firmware info
                        if (ReadFWInfo())
                        {
                            // start to read the hid report repeatedly
                            StartObtainHidReport();

                            this.IsConnected = true;

                            // initialize this.HidReport property on UI thread
                            OnConnectionStatusChanged?.Invoke(this, new ConnectionEventArgs(ConnectionEventArgs.EventType.ConnectionSuccess));
                        }
                        else
                        {
                            Close();

                            lastError = "cannot get the firmware information";
                            OnConnectionStatusChanged?.Invoke(this, new ConnectionEventArgs(ConnectionEventArgs.EventType.ConnectionFailure, LastError));
                        }
                    }
                    else
                    {
                        LastError = "cannot get the total axes";
                        OnConnectionStatusChanged?.Invoke(this, new ConnectionEventArgs(ConnectionEventArgs.EventType.ConnectionFailure, LastError));
                    }
                }
                else
                {
                    this.LastError = "unable to open the usb port to connect to the controller";
                    OnConnectionStatusChanged?.Invoke(this, new ConnectionEventArgs(ConnectionEventArgs.EventType.ConnectionFailure, LastError));
                }
            }
            catch (Exception ex)
            {
                this.LastError = ex.Message;
            }

            return(IsConnected);
        }