Author Topic: Help Needed with USB Code  (Read 708 times)

Offline nrshida

  • Plutonium Member
  • *******
  • Posts: 8577
Help Needed with USB Code
« on: May 17, 2016, 04:23:27 AM »
Wondering if there’s anyone who could help me. I’m doing a project for University to do with vehicle interfaces. For my prototype I want to couple some custom switchgear not to the usual Arduino board but to my computer. In there I will have my switchgear control a simple graphic selection program.

I have a Leo Bodnar board which takes care of everything on the exterior side of the project. The bit I’m stuck with is how to register the switchgear input to the computer. I was told that it’s a simple USB joystick application, that I just have to write some code to pole the Bodnar board and that will handle the inputs via the USB. I’ve tried several tutorials but they all seem to have missing files or otherwise don’t work.

Does anyone know how to do this and especially have any sample code. As I say, simple digital on / off switches will suffice. Analogue input not needed at this stage.

Thanks in advance.
"If man were meant to fly, he'd have been given an MS Sidewinder"

Offline Skuzzy

  • Support Member
  • Administrator
  • *****
  • Posts: 31462
      • HiTech Creations Home Page
Re: Help Needed with USB Code
« Reply #1 on: May 17, 2016, 05:45:44 AM »
Have you looked at the DirectInput API?  It is pretty straight forward and will handle most of the mundane stuff for you.  If you use the DX9 version, it makes your program compatible across all flavors of Windows from Windows XP and up.
Roy "Skuzzy" Neese
support@hitechcreations.com

Offline nrshida

  • Plutonium Member
  • *******
  • Posts: 8577
Re: Help Needed with USB Code
« Reply #2 on: May 17, 2016, 06:27:04 AM »
That's a great idea. I've used OpenGL a fair bit in the past, in fact that's what I was hoping to write the graphics code in, are they compatible? Also how do you actually install the DirectInput API? With OpenGL I just put the OpenGL32.lib file and a GLUT32.lib file (I think) in the same directory as the executable. Is it the same business for DirectInput?

"If man were meant to fly, he'd have been given an MS Sidewinder"

Offline nrshida

  • Plutonium Member
  • *******
  • Posts: 8577
Re: Help Needed with USB Code
« Reply #3 on: May 17, 2016, 06:56:28 AM »
I can only find DirectX 9 on this website:

http://en.softonic.com/s/directx-9

Can I trust it? I currently use MSDEV 6.0 installed on a Windows XP partition. Was hoping to not have to download a whole new programming environment.

"If man were meant to fly, he'd have been given an MS Sidewinder"

Offline Skuzzy

  • Support Member
  • Administrator
  • *****
  • Posts: 31462
      • HiTech Creations Home Page
Re: Help Needed with USB Code
« Reply #4 on: May 17, 2016, 09:04:04 AM »
You install the DirectX SDK, and no I would not grab a DirectX SDK from anywhere except Microsoft.  You can grab the latest SDK from Microsoft as it still comes with the DX9 library as well.  Just include the correct library.

You do not need to use the DirectX graphics API in order to use DirectInput.
Roy "Skuzzy" Neese
support@hitechcreations.com

Offline nrshida

  • Plutonium Member
  • *******
  • Posts: 8577
Re: Help Needed with USB Code
« Reply #5 on: May 17, 2016, 10:11:26 AM »
Thank you very much for the help Skuzzy. I'll give it a try!

 :salute
"If man were meant to fly, he'd have been given an MS Sidewinder"

Offline nrshida

  • Plutonium Member
  • *******
  • Posts: 8577
Re: Help Needed with USB Code
« Reply #6 on: May 20, 2016, 06:00:30 AM »
Really stuck atm. Downloaded DirectX as advised and found the DirectInput header file, lib file and a tutorial but right now I'm stuck with a linking error: 'unresolved external symbol _IID_IDirectInput8A'.

I'm declaring

LPDIRECTINPUTDEVICE8 joystick;

and I can see LPDIRECTINPUTDEVICE8 in the dinput.h file which I've included in my actual project folder, along with the dinpult.lib file which came with the DirectX SDK.

There are now three copies of dxguid.lib, one in my C:\Program Files\Microsoft Visual Studio\VC98\Lib directory (must be the old one) and one each in C:\Program Files\Microsoft DirectX SDK (June 2010)\Lib\x86 and C:\Program Files\Microsoft DirectX SDK (June 2010)\Lib\x64. The latter two came with the DirectX SDK and are a lot larger, but when I try to put those libs in my project folder I get another error telling me to rebuild the module.

Exhausted online resources at this point. Just can't get a bog-basic joystick sample with DirectInput and I'm not a programming wizz kid. Any ideas?

"If man were meant to fly, he'd have been given an MS Sidewinder"

Offline nrshida

  • Plutonium Member
  • *******
  • Posts: 8577
Re: Help Needed with USB Code
« Reply #7 on: May 20, 2016, 06:05:09 AM »
Should also mention there are MS sample projects including DirectInput implimenting joysticks but they are MSDEV 2010 project workspaces and I only have MSDEV 6.0 so they aren't compatible.

"If man were meant to fly, he'd have been given an MS Sidewinder"

Offline Skuzzy

  • Support Member
  • Administrator
  • *****
  • Posts: 31462
      • HiTech Creations Home Page
Re: Help Needed with USB Code
« Reply #8 on: May 20, 2016, 09:51:35 AM »
Oh, that is going to be a big problem.  The latest DirectX SDK requires, at least, Visual Studio 2008.
Roy "Skuzzy" Neese
support@hitechcreations.com

Offline nrshida

  • Plutonium Member
  • *******
  • Posts: 8577
Re: Help Needed with USB Code
« Reply #9 on: May 20, 2016, 11:09:09 AM »
Oh, that is going to be a big problem.  The latest DirectX SDK requires, at least, Visual Studio 2008.

Oh cobblers. Alright thanks for letting me know Skuzzy. Time to get my lateral thinking shoes on. Will let you know  :banana:

"If man were meant to fly, he'd have been given an MS Sidewinder"

Offline Skuzzy

  • Support Member
  • Administrator
  • *****
  • Posts: 31462
      • HiTech Creations Home Page
Re: Help Needed with USB Code
« Reply #10 on: May 20, 2016, 11:11:29 AM »
Good luck with it.
Roy "Skuzzy" Neese
support@hitechcreations.com

Offline nrshida

  • Plutonium Member
  • *******
  • Posts: 8577
Re: Help Needed with USB Code
« Reply #11 on: May 22, 2016, 03:13:12 AM »
I got it working  :banana:

By 'it' I don't mean DirectInput. Wouldn't work with my macked-together old-fashioned system. In the very unlikely event any other AH forum member needs to do similar: there is a free OpenGL library called GLFW* which  joystick and gamepad, multiple monitors, keyboard and mouse support. Took a fair bit of fettlining but the precompiled 2010 lib and dll files worked with my MSDEV 6.0 installation and I just got the demo code working. Lateral thinking ftw!  :rock

Thanks again for your input Skuzzy. Oftentimes with this sort of work knowing something won't work is just as helpful. Will try DirectInput on a better system later. Can I do anything in return to help with your Cobra project?   :salute


*http://www.glfw.org
"If man were meant to fly, he'd have been given an MS Sidewinder"

Offline Skuzzy

  • Support Member
  • Administrator
  • *****
  • Posts: 31462
      • HiTech Creations Home Page
Re: Help Needed with USB Code
« Reply #12 on: May 22, 2016, 06:38:59 AM »
Appreciate the offer, but it is all pretty much a hands-on build right now.  Almost got the IRS done.  Decided to build new upper and lower control arms for the front suspension so I can alter the geometry a bit to complement the rear suspension geometry.

Recently plugged the frame into a finite element analysis program and have been playing with it as well.
Roy "Skuzzy" Neese
support@hitechcreations.com