private void ConnectClient()
 {
     try
     {
         VJoy = new vJoy();
         if (!VJoy.vJoyEnabled())
         {
             Connection.LogSDMessage("vJoy driver not enabled: Failed Getting vJoy attributes.");
             Logger.Instance.LogMessage(TracingLevel.ERROR, "vJoy driver not enabled: Failed Getting vJoy attributes.");
         }
         else
         {
             Connection.LogSDMessage($"Vendor: {VJoy.GetvJoyManufacturerString()}\nProduct :{VJoy.GetvJoyProductString()}\nVersion Number:{VJoy.GetvJoySerialNumberString()}\n");
             Logger.Instance.LogMessage(TracingLevel.INFO, $"Vendor: {VJoy.GetvJoyManufacturerString()}\nProduct :{VJoy.GetvJoyProductString()}\nVersion Number:{VJoy.GetvJoySerialNumberString()}\n");
         }
         if (!VJoy.AcquireVJD(JoystickId))
         {
             Connection.ShowAlert().Start();
         }
         else
         {
             VJoy.ResetAll();
         }
     }
     catch (ArgumentException ex)
     {
         Connection.LogSDMessage($"{ex.Message}");
         Logger.Instance.LogMessage(TracingLevel.ERROR, $"{ex.Message}");
     }
 }
Esempio n. 2
0
        private void Start()
        {
            _joystick = new vJoy();

            if (!CheckVJoy())
            {
                return;
            }

            if (!OpenSerialPort())
            {
                return;
            }

            _joystick.ResetAll();

            MainLoop();
        }
Esempio n. 3
0
        /// <summary>
        /// Checking VJoy - copied from documentation
        /// </summary>
        /// <returns></returns>
        public void CheckVJoy()
        {
            if (!_joystick.vJoyEnabled())
            {
                throw new Exception("vJoy driver not enabled: Failed Getting vJoy attributes.");
            }

            // Get the state of the requested device
            VjdStat status = _joystick.GetVJDStatus(_deviceId);

            switch (status)
            {
            case VjdStat.VJD_STAT_OWN:
                break;

            case VjdStat.VJD_STAT_FREE:
                break;

            case VjdStat.VJD_STAT_BUSY:
                throw new Exception(string.Format("vJoy Device {0} is already owned by another feeder. Cannot continue.", _deviceId));

            case VjdStat.VJD_STAT_MISS:
                throw new Exception(string.Format("vJoy Device {0} is not installed or disabled. Cannot continue.", _deviceId));

            default:
                throw new Exception(string.Format("vJoy Device {0} general error. Cannot continue.", _deviceId));
            }

            UInt32 dllVer = 0, drvVer = 0;

            _joystick.DriverMatch(ref dllVer, ref drvVer);


            // Acquire the target
            if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!_joystick.AcquireVJD(_deviceId))))
            {
                throw new Exception(string.Format("Failed to acquire vJoy device number {0}.", _deviceId));
            }

            _joystick.ResetAll();
        }
Esempio n. 4
0
        /**
         * Code is just reference from vJoy.
         */
        public void setupVjoy()
        {
            // Create one joystick object and a position structure.
            joystick = new vJoy();
            iReport  = new vJoy.JoystickState();


            // Device ID can only be in the range 1-16

            /*
             * if (args.Length > 0 && !String.IsNullOrEmpty(args[0]))
             *  id = Convert.ToUInt32(args[0]);
             * if (id <= 0 || id > 16)
             * {
             *  Console.WriteLine("Illegal device ID {0}\nExit!", id);
             *  return;
             * }
             */

            // Get the driver attributes (Vendor ID, Product ID, Version Number)
            if (!joystick.vJoyEnabled())
            {
                writeMessage(String.Format("vJoy driver not enabled: Failed Getting vJoy attributes."));
                return;
            }
            else
            {
                writeMessage(String.Format("Vendor: {0}\nProduct :{1}\nVersion Number:{2}\n", joystick.GetvJoyManufacturerString(), joystick.GetvJoyProductString(), joystick.GetvJoySerialNumberString()));
            }

            // Get the state of the requested device
            VjdStat status = joystick.GetVJDStatus(id);

            switch (status)
            {
            case VjdStat.VJD_STAT_OWN:
                writeMessage(String.Format("vJoy Device {0} is already owned by this feeder\n", id));
                break;

            case VjdStat.VJD_STAT_FREE:
                writeMessage(String.Format("vJoy Device {0} is free\n", id));
                break;

            case VjdStat.VJD_STAT_BUSY:
                writeMessage(String.Format("vJoy Device {0} is already owned by another feeder\nCannot continue", id));
                return;

            case VjdStat.VJD_STAT_MISS:
                writeMessage(String.Format("vJoy Device {0} is not installed or disabled\nCannot continue", id));
                return;

            default:
                writeMessage(String.Format("vJoy Device {0} general error\nCannot continue", id));
                return;
            }
            ;


            // Check which axes are supported
            bool AxisX  = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_X);
            bool AxisY  = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Y);
            bool AxisZ  = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_Z);
            bool AxisRX = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RX);
            bool AxisRZ = joystick.GetVJDAxisExist(id, HID_USAGES.HID_USAGE_RZ);

            // Get the number of buttons and POV Hat switchessupported by this vJoy device
            nButtons      = joystick.GetVJDButtonNumber(id);
            ContPovNumber = joystick.GetVJDContPovNumber(id);
            DiscPovNumber = joystick.GetVJDDiscPovNumber(id);

            // Print results

            /*
             * writeMessage(String.Format("vJoy Device {0} capabilities:", id));
             * writeMessage(String.Format("Numner of buttons\t\t{0}", nButtons));
             * writeMessage(String.Format("Numner of Continuous POVs\t{0}", ContPovNumber));
             * writeMessage(String.Format("Numner of Descrete POVs\t\t{0}", DiscPovNumber));
             * writeMessage(String.Format("Axis X\t\t{0}", AxisX ? "Yes" : "No"));
             * writeMessage(String.Format("Axis Y\t\t{0}", AxisX ? "Yes" : "No"));
             * writeMessage(String.Format("Axis Z\t\t{0}", AxisX ? "Yes" : "No"));
             * writeMessage(String.Format("Axis Rx\t\t{0}", AxisRX ? "Yes" : "No"));
             * writeMessage(String.Format("Axis Rz\t\t{0}", AxisRZ ? "Yes" : "No"));
             */
            // Test if DLL matches the driver
            UInt32 DllVer = 0, DrvVer = 0;
            bool   match = joystick.DriverMatch(ref DllVer, ref DrvVer);

            if (match)
            {
                Console.WriteLine("Version of Driver Matches DLL Version ({0:X})\n", DllVer);
            }
            else
            {
                Console.WriteLine("Version of Driver ({0:X}) does NOT match DLL Version ({1:X})\n", DrvVer, DllVer);
            }


            // Acquire the target
            if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!joystick.AcquireVJD(id))))
            {
                Console.WriteLine("Failed to acquire vJoy device number {0}.\n", id);
                return;
            }
            else
            {
                Console.WriteLine("Acquired: vJoy device number {0}.\n", id);
            }


            maxval = 0;

            joystick.GetVJDAxisMax(id, HID_USAGES.HID_USAGE_X, ref maxval);

            joystick.ResetAll();
        }
Esempio n. 5
0
        public void Start()
        {
            //WUP-028
            //VENDORID 0x57E
            //PRODUCT ID 0x337

            var USBFinder = new UsbDeviceFinder(0x057E, 0x0337);

            GCNAdapter = UsbDevice.OpenUsbDevice(USBFinder);

            if (GCNAdapter != null)
            {
                int transferLength;

                reader = GCNAdapter.OpenEndpointReader(ReadEndpointID.Ep01);
                writer = GCNAdapter.OpenEndpointWriter(WriteEndpointID.Ep02);

                //prompt controller to start sending
                writer.Write(Convert.ToByte((char)19), 10, out transferLength);

                try
                {
                    if (gcn1Enabled && !JoystickHelper.checkJoystick(ref vjoy, 1))
                    {
                        SystemHelper.CreateJoystick(1);
                    }
                    if (gcn2Enabled && !JoystickHelper.checkJoystick(ref vjoy, 2))
                    {
                        SystemHelper.CreateJoystick(2);
                    }
                    if (gcn3Enabled && !JoystickHelper.checkJoystick(ref vjoy, 3))
                    {
                        SystemHelper.CreateJoystick(3);
                    }
                    if (gcn4Enabled && !JoystickHelper.checkJoystick(ref vjoy, 4))
                    {
                        SystemHelper.CreateJoystick(4);
                    }

                    if (gcn1Enabled && vjoy.AcquireVJD(1))
                    {
                        gcn1ok = true;
                    }
                    if (gcn2Enabled && vjoy.AcquireVJD(2))
                    {
                        gcn2ok = true;
                    }
                    if (gcn3Enabled && vjoy.AcquireVJD(3))
                    {
                        gcn3ok = true;
                    }
                    if (gcn4Enabled && vjoy.AcquireVJD(4))
                    {
                        gcn4ok = true;
                    }

                    vjoy.ResetAll();
                    vjoy.FfbRegisterGenCB(FfbRecieved, IntPtr.Zero);
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("HRESULT: 0x8007000B"))
                    {
                        Log(null, new LogEventArgs("Error: vJoy driver mismatch. Did you install the wrong version (x86/x64)?"));
                        Driver.run = false;
                        return;
                    }
                }

                if (noEventMode)
                {
                    // PORT 1: bytes 02-09
                    // PORT 2: bytes 11-17
                    // PORT 3: bytes 20-27
                    // PORT 4: bytes 29-36l
                    byte[] ReadBuffer  = new byte[37]; // 32 (4 players x 8) bytes for input, 5 bytes for formatting
                    byte[] WriteBuffer = new byte[5];  // 1 for command, 4 for rumble state
                    WriteBuffer[0] = 0x11;
                    WriteBuffer[1] = 0;
                    Log(null, new LogEventArgs("Driver successfully started, entering input loop."));
                    run = true;
                    Stopwatch sw = Stopwatch.StartNew();
                    while (run)
                    {
                        var ec     = reader.Read(ReadBuffer, 10, out transferLength);
                        var input1 = GCNState.GetState(getFastInput1(ref ReadBuffer));
                        var input2 = GCNState.GetState(getFastInput2(ref ReadBuffer));
                        var input3 = GCNState.GetState(getFastInput3(ref ReadBuffer));
                        var input4 = GCNState.GetState(getFastInput4(ref ReadBuffer));

                        if (gcn1ok)
                        {
                            JoystickHelper.setJoystick(ref vjoy, input1, 1, gcn1DZ);
                        }
                        if (gcn2ok)
                        {
                            JoystickHelper.setJoystick(ref vjoy, input2, 2, gcn2DZ);
                        }
                        if (gcn3ok)
                        {
                            JoystickHelper.setJoystick(ref vjoy, input3, 3, gcn3DZ);
                        }
                        if (gcn4ok)
                        {
                            JoystickHelper.setJoystick(ref vjoy, input4, 4, gcn4DZ);
                        }

                        long elapsed = sw.ElapsedMilliseconds;
                        sw.Reset(); sw.Start();

                        if (Interlocked.Read(ref gcn1Ffb) > 0)
                        {
                            if (gcn1FfbInf == false)
                            {
                                Interlocked.Add(ref gcn1Ffb, -elapsed);
                            }
                            WriteBuffer[1] = (byte)(gcn1FfbActive ? 1 : 0);
                        }
                        else
                        {
                            WriteBuffer[1] = 0;
                        }
                        if (Interlocked.Read(ref gcn2Ffb) > 0)
                        {
                            if (gcn2FfbInf == false)
                            {
                                Interlocked.Add(ref gcn2Ffb, -elapsed);
                            }
                            WriteBuffer[2] = (byte)(gcn2FfbActive ? 1 : 0);
                        }
                        else
                        {
                            WriteBuffer[2] = 0;
                        }
                        if (Interlocked.Read(ref gcn3Ffb) > 0)
                        {
                            if (gcn3FfbInf == false)
                            {
                                Interlocked.Add(ref gcn3Ffb, -elapsed);
                            }
                            WriteBuffer[3] = (byte)(gcn3FfbActive ? 1 : 0);
                        }
                        else
                        {
                            WriteBuffer[3] = 0;
                        }
                        if (Interlocked.Read(ref gcn4Ffb) > 0)
                        {
                            if (gcn4FfbInf == false)
                            {
                                Interlocked.Add(ref gcn4Ffb, -elapsed);
                            }
                            WriteBuffer[4] = (byte)(gcn4FfbActive ? 1 : 0);
                        }
                        else
                        {
                            WriteBuffer[4] = 0;
                        }
                        writer.Write(WriteBuffer, 10, out transferLength);
                        System.Threading.Thread.Sleep(5);
                    }

                    WriteBuffer[1] = 0; WriteBuffer[2] = 0; WriteBuffer[3] = 0; WriteBuffer[4] = 0;
                    writer.Write(WriteBuffer, 10, out transferLength);

                    if (GCNAdapter != null)
                    {
                        if (GCNAdapter.IsOpen)
                        {
                            if (!ReferenceEquals(wholeGCNAdapter, null))
                            {
                                wholeGCNAdapter.ReleaseInterface(0);
                            }
                            GCNAdapter.Close();
                        }
                        GCNAdapter = null;
                        UsbDevice.Exit();
                        Log(null, new LogEventArgs("Closing driver thread..."));
                    }
                    Log(null, new LogEventArgs("Driver thread has been stopped."));
                }
                else
                {
                    Log(null, new LogEventArgs("Driver successfully started, entering input loop."));
                    //using  Interrupt request instead of looping behavior.
                    reader.DataReceivedEnabled = true;
                    reader.DataReceived       += reader_DataReceived;
                    reader.ReadBufferSize      = 37;
                    reader.ReadThreadPriority  = System.Threading.ThreadPriority.Highest;
                    run = true;
                }
            }
            else
            {
                Log(null, new LogEventArgs("GCN Adapter not detected."));
                Driver.run = false;
            }
        }
Esempio n. 6
0
        static public void Feed(double frequency)
        {
            //int nButtons = joystick.GetVJDButtonNumber(id);
            //int ContPovNumber = joystick.GetVJDContPovNumber(id);
            //int DiscPovNumber = joystick.GetVJDDiscPovNumber(id);

            //long maxval = 0;

            joystick.GetVJDAxisMax(id, HID_USAGES.HID_USAGE_X, ref maxval);

#if ROBUST
            //joystick.ResetButtons(id);
            joystick.ResetAll();
            //MOFO CONTROL PANEL
            switch (Convert.ToInt32(frequency))
            {
            //32 main notes:

/*E3*/ case 82: joystick.SetAxis(Y + 100, id, HID_USAGES.HID_USAGE_Y); stat = "Y+"; break;

/*F3*/ case 87: joystick.SetAxis(X + 100, id, HID_USAGES.HID_USAGE_X); stat = "X+"; break;

/*F#3*/ case 92: joystick.SetAxis(RZ + 100, id, HID_USAGES.HID_USAGE_RZ); stat = "RZ+"; break;

/*G3*/ case 98: joystick.SetAxis(Z + 100, id, HID_USAGES.HID_USAGE_Z); stat = "Z+"; break;

/*G#3*/ case 104: break;

/*A3*/ case 110: joystick.SetAxis(Y - 100, id, HID_USAGES.HID_USAGE_Y); stat = "Y-"; break;

/*A#3*/ case 117: joystick.SetAxis(X - 100, id, HID_USAGES.HID_USAGE_X); stat = "X-"; break;

/*B3*/ case 123: joystick.SetAxis(RZ - 100, id, HID_USAGES.HID_USAGE_RZ); stat = "RZ-"; break;

/*C4*/ case 131: joystick.SetAxis(Z - 100, id, HID_USAGES.HID_USAGE_Z); stat = "Z-"; break;

/*C#4*/ case 139: break;

/*D4*/ case 147: joystick.SetBtn(true, id, 1); stat = "1"; break;

/*D#4*/ case 156: joystick.SetBtn(true, id, 2); stat = "2"; break;

/*E4*/ case 165: joystick.SetBtn(true, id, 3); stat = "3"; break;

/*F4*/ case 175: joystick.SetBtn(true, id, 4); stat = "4"; break;

/*F#4*/ case 185: joystick.SetBtn(true, id, 5); stat = "5"; break;

/*G4*/ case 196: joystick.SetBtn(true, id, 6); stat = "6"; break;

/*G#4*/ case 208: joystick.SetBtn(true, id, 7); stat = "7"; break;

/*A4*/ case 220: joystick.SetBtn(true, id, 8); stat = "8"; break;

/*A#4*/ case 233: joystick.SetBtn(true, id, 9); stat = "9"; break;

/*B4*/ case 247: joystick.SetBtn(true, id, 10); stat = "10"; break;

/*C5*/ case 262: joystick.SetBtn(true, id, 11); stat = "11"; break;

/*C#5*/ case 277: joystick.SetBtn(true, id, 12); stat = "12"; break;

/*D5*/ case 294: joystick.SetBtn(true, id, 13); stat = "13"; break;

/*D#5*/ case 311: joystick.SetBtn(true, id, 14); stat = "14"; break;

/*E5*/ case 329: break;

/*F5*/ case 349: break;

/*F#5*/ case 370: break;

/*G5*/ case 392: break;

/*G#5*/ case 415: break;

/*A5*/ case 440: break;

/*A#5*/ case 466: break;

/*B5*/ case 494: break;

            //stab: joystick.SetBtn(false, id, 1);

            //13 additional notes:
/*C6*/ case 523: break;

/*C#6*/ case 554: break;

/*D6*/ case 587: break;

/*D#6*/ case 622: break;

/*E6*/ case 659: break;

/*F6*/ case 698: break;

/*F#6*/ case 740: break;

/*G6*/ case 784: break;

/*G#6*/ case 831: break;

/*A6*/ case 880: break;

/*A#6*/ case 932: break;

/*B6*/ case 988: break;

/*C7*/ case 1047: break;

            default: break;
            }

            /*
             *  // Feed the device in endless loop
             * while (true)
             * {
             *  // Set position of 4 axes
             *  res = joystick.SetAxis(X, id, HID_USAGES.HID_USAGE_X);
             *  res = joystick.SetAxis(Y, id, HID_USAGES.HID_USAGE_Y);
             *  res = joystick.SetAxis(Z, id, HID_USAGES.HID_USAGE_Z);
             *  res = joystick.SetAxis(XR, id, HID_USAGES.HID_USAGE_RX);
             *  res = joystick.SetAxis(ZR, id, HID_USAGES.HID_USAGE_RZ);
             *
             *  // Press/Release Buttons
             *  res = joystick.SetBtn(true, id, count / 50);
             *  res = joystick.SetBtn(false, id, 1 + count / 50);
             *
             *  // If Continuous POV hat switches installed - make them go round
             *  // For high values - put the switches in neutral state
             *  if (ContPovNumber>0)
             *  {
             *      if ((count * 70) < 30000)
             *      {
             *          res = joystick.SetContPov(((int)count * 70), id, 1);
             *          res = joystick.SetContPov(((int)count * 70) + 2000, id, 2);
             *          res = joystick.SetContPov(((int)count * 70) + 4000, id, 3);
             *          res = joystick.SetContPov(((int)count * 70) + 6000, id, 4);
             *      }
             *      else
             *      {
             *          res = joystick.SetContPov(-1, id, 1);
             *          res = joystick.SetContPov(-1, id, 2);
             *          res = joystick.SetContPov(-1, id, 3);
             *          res = joystick.SetContPov(-1, id, 4);
             *      };
             *  };
             *
             *  // If Discrete POV hat switches installed - make them go round
             *  // From time to time - put the switches in neutral state
             *  if (DiscPovNumber>0)
             *  {
             *      if (count < 550)
             *      {
             *          joystick.SetDiscPov((((int)count / 20) + 0) % 4, id, 1);
             *          joystick.SetDiscPov((((int)count / 20) + 1) % 4, id, 2);
             *          joystick.SetDiscPov((((int)count / 20) + 2) % 4, id, 3);
             *          joystick.SetDiscPov((((int)count / 20) + 3) % 4, id, 4);
             *      }
             *      else
             *      {
             *          joystick.SetDiscPov(-1, id, 1);
             *          joystick.SetDiscPov(-1, id, 2);
             *          joystick.SetDiscPov(-1, id, 3);
             *          joystick.SetDiscPov(-1, id, 4);
             *      };
             *  };
             *
             *  System.Threading.Thread.Sleep(20);
             *
             * } // While (Robust)
             */
#endif // ROBUST
#if EFFICIENT
            byte[] pov = new byte[4];

            while (true)
            {
                iReport.bDevice  = (byte)id;
                iReport.AxisX    = X;
                iReport.AxisY    = Y;
                iReport.AxisZ    = Z;
                iReport.AxisZRot = ZR;
                iReport.AxisXRot = XR;

                // Set buttons one by one
                iReport.Buttons = (uint)(0x1 << (int)(count / 20));

                if (ContPovNumber > 0)
                {
                    // Make Continuous POV Hat spin
                    iReport.bHats    = (count * 70);
                    iReport.bHatsEx1 = (count * 70) + 3000;
                    iReport.bHatsEx2 = (count * 70) + 5000;
                    iReport.bHatsEx3 = 15000 - (count * 70);
                    if ((count * 70) > 36000)
                    {
                        iReport.bHats    = 0xFFFFFFFF; // Neutral state
                        iReport.bHatsEx1 = 0xFFFFFFFF; // Neutral state
                        iReport.bHatsEx2 = 0xFFFFFFFF; // Neutral state
                        iReport.bHatsEx3 = 0xFFFFFFFF; // Neutral state
                    }
                    ;
                }
                else
                {
                    // Make 5-position POV Hat spin

                    pov[0] = (byte)(((count / 20) + 0) % 4);
                    pov[1] = (byte)(((count / 20) + 1) % 4);
                    pov[2] = (byte)(((count / 20) + 2) % 4);
                    pov[3] = (byte)(((count / 20) + 3) % 4);

                    iReport.bHats = (uint)(pov[3] << 12) | (uint)(pov[2] << 8) | (uint)(pov[1] << 4) | (uint)pov[0];
                    if ((count) > 550)
                    {
                        iReport.bHats = 0xFFFFFFFF;         // Neutral state
                    }
                };

                /*** Feed the driver with the position packet - is fails then wait for input then try to re-acquire device ***/
                if (!joystick.UpdateVJD(id, ref iReport))
                {
                    Console.WriteLine("Feeding vJoy device number {0} failed - try to enable device then press enter\n", id);
                    Console.ReadKey(true);
                    joystick.AcquireVJD(id);
                }

                System.Threading.Thread.Sleep(20);
                count++;
                if (count > 640)
                {
                    count = 0;
                }

                X += 150; if (X > maxval)
                {
                    X = 0;
                }
                Y += 250; if (Y > maxval)
                {
                    Y = 0;
                }
                Z += 350; if (Z > maxval)
                {
                    Z = 0;
                }
                XR += 220; if (XR > maxval)
                {
                    XR = 0;
                }
                ZR += 200; if (ZR > maxval)
                {
                    ZR = 0;
                }
            }
            ; // While
#endif // EFFICIENT
        } // Main
Esempio n. 7
0
        public void Start()
        {
            var USBFinder = new UsbDeviceFinder(0x057E, 0x0337);

            GCNAdapter = UsbDevice.OpenUsbDevice(USBFinder);

            gcn1DZ = new ControllerDeadZones();

            if (GCNAdapter != null)
            {
                int transferLength;

                writer = GCNAdapter.OpenEndpointWriter(WriteEndpointID.Ep02);

                //prompt controller to start sending
                writer.Write(Convert.ToByte((char)19), 10, out transferLength);

                try
                {
                    if (!JoystickHelper.checkJoystick(ref gcn1, 1))
                    {
                        SystemHelper.CreateJoystick(1);
                    }

                    if (gcn1Enabled && gcn1.AcquireVJD(1))
                    {
                        gcn1ok = true;
                        gcn1.ResetAll();
                    }
                }
                catch (Exception ex)
                {
                    DriverLog(null, new Logging.LogEventArgs("Error: " + ex.ToString()));
                    if (ex.Message.Contains("HRESULT: 0x8007000B"))
                    {
                        DriverLog(null, new Logging.LogEventArgs("Error: vJoy driver mismatch. Did you install the wrong version (x86/x64)?"));
                        Driver.run = false;
                        return;
                    }
                }

                if (noEventMode)
                {
                    DriverLog(null, new Logging.LogEventArgs("Driver successfully started, entering input loop."));
                    run = true;

                    while (run)
                    {
                        if (gcn1ok)
                        {
                            JoystickHelper.setJoystick(ref gcn1, Bot.Instance.State, 1, gcn1DZ);
                        }
                    }

                    if (GCNAdapter != null)
                    {
                        if (GCNAdapter.IsOpen)
                        {
                            if (!ReferenceEquals(wholeGCNAdapter, null))
                            {
                                wholeGCNAdapter.ReleaseInterface(0);
                            }
                            GCNAdapter.Close();
                        }
                        GCNAdapter = null;
                        UsbDevice.Exit();
                        DriverLog(null, new Logging.LogEventArgs("Closing driver thread..."));
                    }
                    DriverLog(null, new Logging.LogEventArgs("Driver thread has been stopped."));
                }
                else
                {
                    DriverLog(null, new Logging.LogEventArgs("Driver successfully started, entering input loop."));
                    //using  Interrupt request instead of looping behavior.
                    reader.DataReceivedEnabled = true;
                    reader.DataReceived       += reader_DataReceived;
                    reader.ReadBufferSize      = 37;
                    reader.ReadThreadPriority  = System.Threading.ThreadPriority.Highest;
                    run = true;
                }
            }
            else
            {
                DriverLog(null, new Logging.LogEventArgs("GCN Adapter not detected."));
                Driver.run = false;
            }
        }