USB Connection

Hello Everyone,

I have a device which connects through USB. I was wondering if any one can provide a code how to connect to USB and open channel for any data Transfer........

Any help, highly appreciated...

Thanks,

Harsimrat



Answer this question

USB Connection

  • Konstantin Kosinsky

    hey man,

    try this article out. Theres C# Code to download with it too. Should really help

    http://weblogs.asp.net/israelio/archive/2005/08/15/422637.aspx



  • Nirbho

    The problem was, this is a Blackberry which I'm trying to connect to, they provided a sample code which in C++ and I was trying to run from C#...When you open the connection you have to pass some events of the device, which is defined as HANDLE in C++ and I found no way, to convert that in C#...So i thought is a good idea, to maybe write something myself which can talk...and have no clue how USB communication works...any suggestions or some sample code highly appreciated.......

    If you want I can provide with that C++ sample code, if you have any idea how we can use HANDLE in C#....

    Thanks,

    Harsimrat


  • gunn

    does the devide get a Drive Letter assigned to it

    It should, and you can use System.IO Namespace to traverse the directory and get the directory and file structure.

    HTH



  • Dwain Douglas

    I have a different post, where i posted this.....
  • Dan Clash

    Really Appreciate,

    Its nothing Blackberry specific it is just talking to USB.....Do you have any idea how we can change this piece of code to C#, will solve lot of my issues......

    I have a device which connects using USB and had the sample code which in C++, I thought is a good idea to move it to C#. You have already helped me in calling the COM function from C#.

    When I try to open the channel, using

    _channel = d.OpenChannel(Channel, eve);

    where IChannel _channel;

    string Channel = "Client";

    The only problem here is (eve) which is events...i.e IChannelEvents eve; and when I do that it is null....

    But in the C Code....it does something like this....

    enum { READ_EVENT, CLOSE_EVENT, NUM_EVENTS };

    then in the int run() // something along these lines......

    {

    //create some events for listening for notifications from the device

    _events[READ_EVENT] = CreateEvent(NULL, FALSE, FALSE, NULL); //unnamed

    _events[CLOSE_EVENT] = CreateEvent(NULL, TRUE, FALSE, NULL); //unnamed

    if( _events[READ_EVENT] == INVALID_HANDLE_VALUE || _events[CLOSE_EVENT] == INVALID_HANDLE_VALUE ) {

    return false;

    }

    private :

    ULONG _refcount;

    HANDLE _events[NUM_EVENTS];

    ublic:

    //implementation of the IChannelEvents interface

    virtual HRESULT STDMETHODCALLTYPE QueryInterface( REFIID riid, void **ppvObject )

    {

    if ( riid == IID_IChannelEvents || riid == IID_IUnknown) {

    *ppvObject = (IChannelEvents*)this;

    AddRef();

    return 0;

    }

    return E_NOINTERFACE;

    }

    virtual ULONG STDMETHODCALLTYPE AddRef()

    {

    return ++_refcount;

    }

    virtual ULONG STDMETHODCALLTYPE Release()

    {

    ULONG count = --_refcount;

    if ( count == 0 )

    {

    delete this;

    }

    return count;

    }

    .........................................................

    Now all the question starts is how can I incorporate this HANDLE into my IChannelEvents, so that its not null.....thats is the reason its throwing me exceptions..........

    If I can convert this piece of code to C# will solve my problems...

    Do you have any idea.....


  • AMasson

    This link is about how to PUSH Html to a blackberry, but it's all i could find about C# and blackberry's. Unfortunately i know nothing about Blackberry's so i can't help, but maybe this project has a class library that allows access to a blackberry or some useful code in it you can look at.

    http://www.codeproject.com/cs/webservices/MdsBlackberryPush.asp

    HTH,



  • USB Connection