Example #1
0
        protected override void WndProc(ref Message m)
        {
            try
            {
                if (m.Msg == ScpDevice.WM_DEVICECHANGE)
                {
                    String Path;
                    ScpDevice.DEV_BROADCAST_HDR hdr;
                    Int32 Type = m.WParam.ToInt32();

                    hdr = (ScpDevice.DEV_BROADCAST_HDR)Marshal.PtrToStructure(m.LParam, typeof(ScpDevice.DEV_BROADCAST_HDR));

                    if (hdr.dbch_devicetype == ScpDevice.DBT_DEVTYP_DEVICEINTERFACE)
                    {
                        ScpDevice.DEV_BROADCAST_DEVICEINTERFACE_M deviceInterface;

                        deviceInterface = (ScpDevice.DEV_BROADCAST_DEVICEINTERFACE_M)Marshal.PtrToStructure(m.LParam, typeof(ScpDevice.DEV_BROADCAST_DEVICEINTERFACE_M));

                        Path = new String(deviceInterface.dbcc_name);
                        Path = Path.Substring(0, Path.IndexOf('\0')).ToUpper();

                        switch (Type)
                        {
                            case ScpDevice.DBT_DEVICEARRIVAL:

                                if (usbDevice.State != DsState.Connected)
                                {
                                    usbDevice.Close();
                                    usbDevice = new UsbDs3();

                                    if (usbDevice.Open(Path)) usbDevice.Start();
                                }
                                break;

                            case ScpDevice.DBT_DEVICEREMOVECOMPLETE:

                                if (Path == usbDevice.Path && usbDevice.State == DsState.Connected)
                                {
                                    usbDevice.Close();
                                }

                                break;
                        }
                    }
                }
            }
            catch { }

            base.WndProc(ref m);
        }
Example #2
0
        public override Boolean Start()
        {
            m_Started = true;

            Byte Index = 0;

            for (Byte Instance = 0; Instance < Device.Length && Index < Device.Length; Instance++)
            {
                try
                {
                    UsbDevice Current = new UsbDs3();
                    Current.PadId = (DsPadId)Index;

                    if (Current.Open(Instance))
                    {
                        if (LogArrival(Current))
                        {
                            Current.Debug  += new EventHandler <DebugEventArgs> (On_Debug);
                            Current.Report += new EventHandler <ReportEventArgs>(On_Report);

                            Device[Index++] = Current;
                        }
                        else
                        {
                            Current.Close();
                        }
                    }
                    else
                    {
                        Current.Close();
                    }
                }
                catch { break; }
            }

            try
            {
                for (Index = 0; Index < Device.Length; Index++)
                {
                    if (Device[Index].State == DsState.Reserved)
                    {
                        Device[Index].Start();
                    }
                }
            }
            catch { }

            return(base.Start());
        }
Example #3
0
        public override Boolean Start()
        {
            m_Started = true;

            Byte Index = 0;

            // enumerate DS4 devices
            for (Byte instance = 0; instance < _device.Length && Index < _device.Length; instance++)
            {
                try
                {
                    UsbDevice current = new UsbDs4();
                    current.PadId = (DsPadId)Index;

                    if (current.Open(instance))
                    {
                        if (LogArrival(current))
                        {
                            current.HidReportReceived += new EventHandler<ReportEventArgs>(On_Report);

                            _device[Index++] = current;
                        }
                        else current.Close();
                    }
                    else current.Close();
                }
                catch (Exception ex)
                {
                    Log.ErrorFormat("Unexpected error: {0}", ex);
                    break;
                }
            }

            // enumerate DS3 devices
            for (Byte instance = 0; instance < _device.Length && Index < _device.Length; instance++)
            {
                try
                {
                    UsbDevice current = new UsbDs3();
                    current.PadId = (DsPadId)Index;

                    if (current.Open(instance))
                    {
                        if (LogArrival(current))
                        {
                            current.HidReportReceived += new EventHandler<ReportEventArgs>(On_Report);

                            _device[Index++] = current;
                        }
                        else current.Close();
                    }
                    else current.Close();
                }
                catch (Exception ex)
                {
                    Log.ErrorFormat("Unexpected error: {0}", ex);
                    break;
                }
            }

            try
            {
                for (Index = 0; Index < _device.Length; Index++)
                {
                    if (_device[Index].State == DsState.Reserved)
                    {
                        _device[Index].Start();
                    }
                }
            }
            catch (Exception ex)
            {
                Log.ErrorFormat("Unexpected error: {0}", ex);
            }

            return base.Start();
        }
Example #4
0
        public override Boolean Start()
        {
            m_Started = true;

            Byte Index = 0;

            // enumerate DS4 devices
            for (Byte instance = 0; instance < _device.Length && Index < _device.Length; instance++)
            {
                try
                {
                    UsbDevice current = new UsbDs4();
                    current.PadId = (DsPadId)Index;

                    if (current.Open(instance))
                    {
                        if (LogArrival(current))
                        {
                            current.Report += new EventHandler <ReportEventArgs>(On_Report);

                            _device[Index++] = current;
                        }
                        else
                        {
                            current.Close();
                        }
                    }
                    else
                    {
                        current.Close();
                    }
                }
                catch (Exception ex)
                {
                    Log.ErrorFormat("Unexpected error: {0}", ex);
                    break;
                }
            }

            // enumerate DS3 devices
            for (Byte instance = 0; instance < _device.Length && Index < _device.Length; instance++)
            {
                try
                {
                    UsbDevice current = new UsbDs3();
                    current.PadId = (DsPadId)Index;

                    if (current.Open(instance))
                    {
                        if (LogArrival(current))
                        {
                            current.Report += new EventHandler <ReportEventArgs>(On_Report);

                            _device[Index++] = current;
                        }
                        else
                        {
                            current.Close();
                        }
                    }
                    else
                    {
                        current.Close();
                    }
                }
                catch (Exception ex)
                {
                    Log.ErrorFormat("Unexpected error: {0}", ex);
                    break;
                }
            }

            try
            {
                for (Index = 0; Index < _device.Length; Index++)
                {
                    if (_device[Index].State == DsState.Reserved)
                    {
                        _device[Index].Start();
                    }
                }
            }
            catch (Exception ex)
            {
                Log.ErrorFormat("Unexpected error: {0}", ex);
            }

            return(base.Start());
        }