Перейти к содержанию
    

Incoming data from USB (CY7C68013)

Необходимо получать данные (а конкретно видео) через USB. использую Cypress 68013.

Прочитал Guide по CyAPI, на примере написал простенькую програмку:

//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
CCyUSBDevice *USBDevice;
char buf[512];
string s;
USB_DEVICE_DESCRIPTOR descr;
USBDevice = new CCyUSBDevice(NULL);   // Create an instance of CCyUSBDevice
GroupBox1->Caption = "device count " + AnsiString(USBDevice->DeviceCount());
if (USBDevice->DeviceCount())
for (int c=0; c < USBDevice->DeviceCount(); c++)
  {
   if (USBDevice->Open(c))
    {          
     Memo1->Clear();
     int vID = USBDevice->VendorID;
     int pID  = USBDevice->ProductID;
     Label[0]->Caption = "VendorID: " + AnsiString(IntToHex(vID,4));
     Label[1]->Caption = "ProductID: " + AnsiString(IntToHex(pID,4));
     CCyUSBConfig cfg = USBDevice->GetUSBConfig(c);
     USBDevice->GetDeviceDescriptor(&descr);
     Label[2]->Caption = "bLength 0x" + AnsiString(IntToHex(descr.bLength,2));
     Label[3]->Caption = "bDescriptorType 0x" + AnsiString(IntToHex(descr.bDescriptorType,2));
     Label[4]->Caption = "bcdUSB 0x" + AnsiString(IntToHex(descr.bcdUSB,4));
     Label[5]->Caption = "bDeviceClass 0x" + AnsiString(IntToHex(descr.bDeviceClass,2));
     Label[6]->Caption = "bDeviceProtocol 0x" + AnsiString(IntToHex(descr.bDeviceProtocol,2));
     Label[7]->Caption = "bMaxPacketSize0 0x" + AnsiString(IntToHex(descr.bMaxPacketSize0,2));
     Label[8]->Caption = "idVendor 0x" + AnsiString(IntToHex(descr.idVendor,4));
     Label[9]->Caption = "idProduct 0x" + AnsiString(IntToHex(descr.idProduct,4));
     Label[10]->Caption = "bcdDevice 0x" + AnsiString(IntToHex(descr.bcdDevice,4));
     Label[11]->Caption = "iManufacturer 0x" + AnsiString(IntToHex(descr.iManufacturer,2));
     Label[12]->Caption = "iProduct 0x" + AnsiString(IntToHex(descr.iProduct,2));
     Label[13]->Caption = "iSerialNumber 0x" + AnsiString(IntToHex(descr.iSerialNumber,2));
     Label[14]->Caption = "bNumConfigurations 0x" + AnsiString(IntToHex(descr.bNumConfigurations,2));
  //          USBDevice->Close();
     for   (int  i=0; i<cfg.AltInterfaces; i++)
        {
         CCyUSBInterface  *ifc = cfg.Interfaces[i];
         Memo1->Lines->Add("Interface  Descriptor:");
         Memo1->Lines->Add("----------------------");
         Memo1->Lines->Add("bLength  0x" + AnsiString(IntToHex(ifc->bLength,4)));
         Memo1->Lines->Add("bDescriptorType  0x" + AnsiString(IntToHex(ifc->bDescriptorType,4)));
         Memo1->Lines->Add("bInterfaceNumber  0x" + AnsiString(IntToHex(ifc->bInterfaceNumber,4)));
         Memo1->Lines->Add("bAlternateSetting  0x" + AnsiString(IntToHex(ifc->bAlternateSetting,4)));
         Memo1->Lines->Add("bNumEndpoints  0x" + AnsiString(IntToHex(ifc->bNumEndpoints,4)));
         Memo1->Lines->Add("bInterfaceClass  0x" + AnsiString(IntToHex(ifc->bInterfaceClass,4)));
         Memo1->Lines->Add("********************************************************************");

         for   (int  e=0; e<ifc->bNumEndpoints; e++)
           {
            CCyUSBEndPoint  *ept = ifc->EndPoints[e+1];
            Memo1->Lines->Add("EndPoint  Descriptor" + AnsiString(e+1) + ":");
            Memo1->Lines->Add("----------------------");
            Memo1->Lines->Add("bLength  0x" + AnsiString(IntToHex(ept->DscLen, 4)));
            Memo1->Lines->Add("bDescriptorType  0x" + AnsiString(IntToHex(ept->DscType, 4)));
            Memo1->Lines->Add("bEndpointAddress  0x" + AnsiString(IntToHex(ept->Address, 4)));
            Memo1->Lines->Add("bmAttributes  0x" + AnsiString(IntToHex(ept->Attributes, 4)));
            Memo1->Lines->Add("wMaxPacketSize  0x" + AnsiString(IntToHex(ept->MaxPktSize,4)));
            Memo1->Lines->Add("bInterval  0x" + AnsiString(IntToHex(ept->Interval, 4)));
            Memo1->Lines->Add("********************************************************************");
           }
        }
    }
    else
      {
        GroupBox1->Caption = "No device found";
      }
  }
else
  {
     Label[0]->Caption = "VendorID: ";
     Label[1]->Caption = "ProductID: ";
     Label[2]->Caption = "bLength ";
     Label[3]->Caption = "bDescriptorType ";
     Label[4]->Caption = "bcdUSB ";
     Label[5]->Caption = "bDeviceClass ";
     Label[6]->Caption = "bDeviceProtocol ";
     Label[7]->Caption = "bMaxPacketSize0 ";
     Label[8]->Caption = "idVendor ";
     Label[9]->Caption = "idProduct ";
     Label[10]->Caption = "bcdDevice ";
     Label[11]->Caption = "iManufacturer ";
     Label[12]->Caption = "iProduct ";
     Label[13]->Caption = "iSerialNumber ";
     Label[14]->Caption = "bNumConfigurations ";
     Memo1->Text = "No device";
  }
    //USBDevice->GetDeviceDescriptor(&descr);
USBDevice->Close();
//_getch();
}
//---------------------------------------------------------------------------

 

С помощью:

CCyBulkEndPoint *BulkInEpt = NULL;
CCyBulkEndPoint  *BulkOutEpt = NULL;
CCyUSBDevice  *USBDevice = new  CCyUSBDevice(NULL);
if (USBDevice->DeviceCount())
  for (int c=0; c < USBDevice->DeviceCount(); c++)
    if (USBDevice->Open(c))
     {
      int  eptCount = USBDevice->EndPointCount();
      for  (int  i=1; i<eptCount;  i++)
       {
        bool  bIn = ((USBDevice->EndPoints[i]->Address  & 0x80)==0x80);
        bool  bBulk =  (USBDevice->EndPoints[i]->Attributes == 2);
        if (bBulk  && bIn) BulkInEpt = (CCyBulkEndPoint *) USBDevice->EndPoints[i];
        if  (bBulk && !bIn) BulkOutEpt = (CCyBulkEndPoint *) USBDevice->EndPoints[i];
       }
      USBDevice->Close();
     }

получаю Endpoint'ы.

А вот как осуществлять прием не могу разобраться. Объясните на каком-то примере, пожалуйста.

Поделиться сообщением


Ссылка на сообщение
Поделиться на другие сайты

Присоединяйтесь к обсуждению

Вы можете написать сейчас и зарегистрироваться позже. Если у вас есть аккаунт, авторизуйтесь, чтобы опубликовать от имени своего аккаунта.

Гость
Ответить в этой теме...

×   Вставлено с форматированием.   Вставить как обычный текст

  Разрешено использовать не более 75 эмодзи.

×   Ваша ссылка была автоматически встроена.   Отображать как обычную ссылку

×   Ваш предыдущий контент был восстановлен.   Очистить редактор

×   Вы не можете вставлять изображения напрямую. Загружайте или вставляйте изображения по ссылке.

×
×
  • Создать...