PICcoder.co.uk Forum  


::post new topic::
PC waiting for PIC message incomming problem
Date: 2007/10/17 09:19 By: mdundek Status: Visitor  
 
Hi folks,

I have been struggling with a PIC18F4550 demo board to PC communication problem when using MPUSBAPI.DLL and C# and I really need some help from you folks. I want to be able (on my PC code side) to wake up when the PIC sends me some data and process it then.
I found two threads on this forum on this particular subject, but none of them could give me a working solution to this.
I got the basic idea of having a separate thread running in my application that waits for incomings. So naively I thought that all I need to do in this thread is set a high timeout value to my _MPUSBRead method call (like 10000 for example) and the method call would wait 10 seconds before it abandoned the read attempt if nothing comes in and loop on this indefinitely until a message does come in.
Unfortunately the timeout time doesn’t seem to have any affect and jumps right out of the _MPUSBRead call (does not wait for 10 seconds) with no return data.
Here is the C# code that runs on this separate thread to illustrate this:

Code:

 private void USBListener(){                     DWORD receiveLength 64;     bytereceive_buf stackalloc byte[64];          while(myInPipe != INVALID_HANDLE_VALUE && isConnected){         uint receiveDelay 10000;             if(_MPUSBRead(myInPipe, (DWORD)receive_bufreceiveLength, &receiveLengthreceiveDelay) == 1)         {                                 Notify("Incomming on usb"1);         }     } }



What am I doing wrong? Any suggestions please are more than welcome.

Thanks
reply | quote

Re:PC waiting for PIC message incomming problem
Date: 2007/11/23 11:45 By: dariog Status: User  
Karma: 6  
Posts: 107
graphgraph
It should work: I used similar approach in C++ and ReadFile()...

But I've not used that Microchip's library: are you sure that there are no flags/options to setup in order to make it use the delay?
reply | quote

::post new topic::