Author Topic: Read From Usb?  (Read 1453 times)

ulswin

  • Newbie
  • *
  • Posts: 2
    • View Profile
Read From Usb?
« on: March 29, 2010, 09:30:28 pm »
I am trying to read data comes from usb. There is an example but it is written in pascal (usbpipedemo). I want to use it with c++ (in c++ builder 6). I tried to rewrite it but there is errors, can you tell me what is the problem?
By the way component is awesome, thank you.

there is my code:
Code: [Select]
#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "nrclasses"
#pragma link "nrcommbox"
#pragma link "nrusb"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::nrDeviceBox1Change(TObject *Sender)
{
        int i;
        TnrUsbDevice *Dev;
        Dev = nrUSB1->UsbDevice;

ePipeIn->Clear();
ePipeOut->Clear();

        if(Dev != NULL)
        {

           for(int i = 0; i < Dev->Descriptors->Count; i++)  {
                  if(Dev->Pipes[i]->DirectionOut)
      ePipeOut->Items->AddObject(Dev->Pipes[i]->Description, Dev->Pipes[i]);
    if(Dev->Pipes[i]->DirectionIn)
      ePipeIn->Items->AddObject(Dev->Pipes[i]->Description, Dev->Pipes[i]);
           }

}

}

//---------------------------------------------------------------------------

void __fastcall TForm1::nrUSBPipePair1AfterReceive(TObject *Com,Pointer Buffer, DWORD Received)
{
    string s;
    int i;
    s='';
    for(i=0;i<Received-1;i++) {
        s=s+IntToHex(Byte(PChar(Buffer)[i],2) + "";
        Memo2->Lines->Add(s);
    }
}

//---------------------------------------------------------------------------

void __fastcall TForm1::CheckBox1Click(TObject *Sender)
{
  if(CheckBox1->Checked) {
    nrUSB1->Active=True;
    if(nrUSB1->Active) {
        nrUSBPipePair1->PipeIn=TnrUsbPipe(ePipeIn->Items->Objects[ePipeIn->ItemIndex])->Index;
        nrUSBPipePair1->PipeOut=TnrUsbPipe(ePipeOut->Items->Objects[ePipeOut->ItemIndex])->Index;       
    }
    nrUSBPipePair1->Active = True;
  } else if {
    nrUSBPipePair1->Active = False;
    nrUSB1->Active = False;
  } else {
    nrUSB1->Active = False;
    nrUSBPipePair1->Active = False;
    CheckBox1->Checked = nrUSB1->Active and nrUSBPipePair1->Active;
  }

}

//---------------------------------------------------------------------------
« Last Edit: March 29, 2010, 09:32:40 pm by ulswin »