PICcoder.co.uk Forum  


::post new topic::
this loks like great site, but..
Date: 2006/05/10 18:41 By: Jarin Status: Visitor  
 
...until now I didn't know what to expect - just because of that weeks of silence on this page after first great article. I'm looking forward for new articles.

And one suggestion: should it be possible to port PC USB sotware from first article to Visual C++ (or just to sketch some helpful piece of code to talk to USB device)? I'm programmning MCU's for a few years, but I have very little experience on PC programming, just a few programs in VC++; and it's always better (for beginner especially) to start with something functional than to start from zero point.

Thanks
Jarin
reply | quote

Re:this loks like great site, but..
Date: 2006/05/10 21:03 By: Chips Status: User  
Karma: 2  
Posts: 17
graphgraph
Hallo,
Porting the code to Visual C++ is a piece of cake, speaking from experience, i've had the cake and eaten it, all of it! I just got stuck on the PIC stuff and thats because I jumped in at the deepend with a pair of rapidly deflating waterwings.. Anyway enough metaphor, the microchip USB library is just a DLL, so you can dynamically load it in Visual C++ using LoadDLL(), and then make the calls to it like you would any other DLL. The interface is published in the header file, example snippit below, but the other functions follow the same pattern

#include "_mpusbapi.h" // MPUSBAPI Header File

//Some declarations
typedef DWORD (* MPUSBGETDLLVERSION)(void);
typedef DWORD ( * MPUSBGETDEVICECOUNT)(PCHAR pVID_PID);
//... put the other ones here if you want to use them

//Own function pointer types ready to go..
MPUSBGETDLLVERSION pMPUSBGetDLLVersion = NULL;
MPUSBGETDEVICECOUNT pMPUSBGetDeviceCount = NULL;

//Probably overkill redefining the functions from the header

//////////////////////Some code that loads the DLL and calls some funcs

//Load DLL
HANDLE m_DLLModule = LoadLibrary((LPCSTR) "mpusbapi.dll");

if (m_DLLModule == NULL)
{
//Complain like hell - wheres that DLL mate!!
AfxMessageBox(" Could not find mpusbapi.dll ");

return;
}
//Get proc addresses of all functions want to use
pMPUSBGetDLLVersion = (MPUSBGETDLLVERSION) GetProcAddress(m_DLLModule,"_MPUSBGetDLLVersion");


//Quick check..
if ( pMPUSBGetDLLVersion!=NULL )
{
//Call one of the functions from the DLL
DWORD version = pMPUSBGetDLLVersion();
char message[MAX_PATH];
//Stick the version info into a string
sprintf(message , "MPUSBAPI Version: ", HIWORD(version) , LOWORD(version));
//Display the string in annoying popop box
AfxMessageBox(message);

}

This won't compile as is, as you'll probably see, but it should point you in the right direction.
Key point with DLLs they must be in the runtime path of the executable, so just keep it with the exe at all times.. if your debugging stick it in the working directory, (defaults to the project folder in VC++)

Hope this gets you started anyway, if you're new to VC++ you're as well to build some simple apps and get your head round making dialogs, running threads and the windows malarky etc before attempting the USB ride.

Chips
"There are no shortcuts to experience"
reply | quote

Re:this loks like great site, but..
Date: 2006/05/10 21:29 By: Mat Status: Admin  
Karma: 7  
Posts: 211
graph
Hey sorry for the quiet time!! As some of you know I was just taking my final exams (engineering at cambridge), however they are now over . All being well I should have 2 new articles on VB.Net and Visual C++ and using USB coming (code is up and working, just needs writing up!!). However im taking some time off until the weekend, to recover a bit. After that the site will start moving again!!

Thanks for waiting around!!

Mat
reply | quote

Re:this loks like great site, but..
Date: 2006/05/10 22:23 By: jarin Status: Visitor  
 
chips: yes, a piece of cake, for everyone but me
thank you for that code, even with helpful comments, I'll try to play with it, it's a good way to start with USB.
You also wrote about all the experiences i have to get (I'm now starting with threads) but it's very very new for me - I used to think in hard asm (only 35 instruction for 16F!) and low-level C, so switch to VC++ is switch to something quite new.
it's a long way for me.

Jarin
reply | quote

Re:this loks like great site, but..
Date: 2006/05/10 22:45 By: Jarin Status: User  
Karma: 1  
Posts: 3
graphgraph
Mat: Yes, great news (and congratulations to exams). Thank you again for you work and your effort in forum too.

Jarin (but now registered)
reply | quote

Re:this loks like great site, but..
Date: 2006/05/11 11:18 By: Chips Status: User  
Karma: 2  
Posts: 17
graphgraph
Jarin: He he like the icon.. picasso isnt it ?
Maybe should start a VC++ thread (messagey kind not the code kind) as this is probably the wrong place to be rambling on about C++ things.

Mat: Hello again and welcome back to your site
For months you will be waking up with that creeping feeling you should be revising for something.

Cheers
Chips
reply | quote

Re:this loks like great site, but..
Date: 2006/05/11 12:59 By: Jarin Status: User  
Karma: 1  
Posts: 3
graphgraph
Chips: no, it isn't Picasso, it's my friend's son, 10 years
I don't want to continue in off-topic conversation, so it may be better to close it.
Also I don't want to start new VC++ thread, I'll rather try to make everything on my own, that's the way I do it for a long time.
Thank you for help.
Jarin
reply | quote

Re:this loks like great site, but..
Date: 2006/05/11 13:51 By: Chips Status: User  
Karma: 2  
Posts: 17
graphgraph
Ok good luck!

What are you intending to build by the way? Seems to be a lot of folk here are wanting to use USB for ADC applications, myself included.

Chips
reply | quote

Re:this loks like great site, but..
Date: 2006/05/11 21:02 By: Mat Status: Admin  
Karma: 7  
Posts: 211
graph
Thanks guys, cant say i know that feeling, become somewhat of a pro at getting use to exams (being the first lot to go through AS, we have now done 7 years of external examinations back to back ) Ah well, now for some fun, still at home climbing, but ill back to work on to USB and ADC as of monday!!! (All being well working full time on it for the next 3 weeks so expect some movement!

Mat
reply | quote

Re:this loks like great site, but..
Date: 2006/05/14 20:13 By: Jarin Status: User  
Karma: 1  
Posts: 3
graphgraph
Chips: No just ADC, but something a bit complicated. I would like to enhance my "something-like-handheld-computer" it's a small system with MC68HC908AB32 (by Freescale) in core, 512KB NV RAM for data storage, 84*48 LCD display (salvaged from old nokia 3310), small keyboard (btw keyboard and display is connected thru PIC16F777, acting like converter from SPI to keyboard and LCD;it's a bit strange to use Freescale(Motorola) and Microchip product in one case, but I like it... ). It's only connection to outer world is RS232, but there is a problems with laptop (with no COM port, of course).
Btw I worked on this for about 2 years (and making it better, two years ago I started with 16F877 and 8KB SRAM; and just then, step by step I got into current state) and it's still not quite done, especially it's software could be done better, but I'm still working on it in my spare time... you may ask, what's the reason for doing something like this - for a such a long time, even when more perfect handheld computeras are available - it's just a hobby

Hope you understood my poor english...

Jarin
reply | quote

::post new topic::