USB windows程序设计

来源:百度文库 编辑:超级军网 时间:2024/04/28 11:10:09
如题,windows下的,数据从fpga接cypress68013usb口出,usb线接到pc usb口。由pc读取,pc上位机软件设计。有搞过的人没有,经验是大大的重要。
本菜现在两个方案:EasyUSB dll   二,DeviceIoControl函数。 主要是要经验,各位老大啊。如题,windows下的,数据从fpga接cypress68013usb口出,usb线接到pc usb口。由pc读取,pc上位机软件设计。有搞过的人没有,经验是大大的重要。
本菜现在两个方案:EasyUSB dll   二,DeviceIoControl函数。 主要是要经验,各位老大啊。
建议致函微软询问
]]
楼上的傻逼老大,劳资忍你很久了。劳资问什么你都知道。说说devicecontrol读到buffer里就可以了吗?两边要交互信息什么的,控制信号什么的。不要说些劳资不懂的协议。奶奶的。
不会啊~~~~~~离偶的专业有点远~~~~~~~~~~~~:')
猪老大,你快出现啊。妈的,劳资搞的什么你都懂。你是哪的?短信息交流。
同志们啊,水区没老大啊。
原帖由 武大郎 于 2008-9-18 19:35 发表
楼上的傻逼老大,劳资忍你很久了。劳资问什么你都知道。说说devicecontrol读到buffer里就可以了吗?两边要交互信息什么的,控制信号什么的。不要说些劳资不懂的协议。奶奶的。

去微软的网站上看详细的说明啊,USB通信当然要按协议来走的,要不然你怎么测?(我是这么认为的,这个和USB的体系有关吧,不是很熟,还在摸索中……)
给你参考一下我的MassStorage下SCSI命令的发送方法(这个就必须需要一个PC端能够识别的设备,否则lpDeviceName这个设备名称的参数你得不到)
BOOL bResult;
        HANDLE hDevice;
hDevice = CreateFile(        lpDeviceName,
                                                        GENERIC_READ | GENERIC_WRITE,
                                                        FILE_SHARE_READ | FILE_SHARE_WRITE,
                                    NULL,
                                    OPEN_EXISTING,
                                                        NULL,
                            NULL);
        if(hDevice == INVALID_HANDLE_VALUE)       
        { return false; }

        SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER sptdwb;
(中间是按照协议填充不同的字段进去)
int iLength = sizeof(SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER);
        (DWORD)*lpBytesReturned = 0;
bResult = DeviceIoControl(hDevice, IOCTL_SCSI_PASS_THROUGH_DIRECT,
                &sptdwb, iLength, &sptdwb, iLength, lpBytesReturned, FALSE);
CloseHandle(hDevice);
推荐你一个PC端的工具软件,Bus Hound,可以抓到任何IO设备的通信数据。
昨晚下线睡觉去了……
cypress68013这个芯片应该会提供一些Demo的驱动吧,你按照他的技术文档做就行了,我没用过这个芯片。
关于DeviceIoControl函数的说明:
http://msdn.microsoft.com/en-us/library/aa363216(VS.85).
关于DeviceIoControl的用法可以参考微软提供的示例:
http://msdn.microsoft.com/en-us/library/aa363147(VS.85).aspx
/* The code of interest is in the subroutine GetDriveGeometry. The
   code in main shows how to interpret the results of the call. */

#include <windows.h>
#include <winioctl.h>
#include <stdio.h>

BOOL GetDriveGeometry(DISK_GEOMETRY *pdg)
{
  HANDLE hDevice;               // handle to the drive to be examined
  BOOL bResult;                 // results flag
  DWORD junk;                   // discard results

  hDevice = CreateFile(TEXT("\\\\.\\PhysicalDrive0"),  // drive
                    0,                // no access to the drive
                    FILE_SHARE_READ | // share mode
                    FILE_SHARE_WRITE,
                    NULL,             // default security attributes
                    OPEN_EXISTING,    // disposition
                    0,                // file attributes
                    NULL);            // do not copy file attributes

  if (hDevice == INVALID_HANDLE_VALUE) // cannot open the drive
  {
    return (FALSE);
  }

  bResult = DeviceIoControl(hDevice,  // device to be queried
      IOCTL_DISK_GET_DRIVE_GEOMETRY,  // operation to perform
                             NULL, 0, // no input buffer
                            pdg, sizeof(*pdg),     // output buffer
                            &junk,                 // # bytes returned
                            (LPOVERLAPPED) NULL);  // synchronous I/O

  CloseHandle(hDevice);

  return (bResult);
}

int main(int argc, char *argv[])
{
  DISK_GEOMETRY pdg;            // disk drive geometry structure
  BOOL bResult;                 // generic results flag
  ULONGLONG DiskSize;           // size of the drive, in bytes

  bResult = GetDriveGeometry (&pdg);

  if (bResult)
  {
    printf("Cylinders = %I64d\n", pdg.Cylinders);
    printf("Tracks/cylinder = %ld\n", (ULONG) pdg.TracksPerCylinder);
    printf("Sectors/track = %ld\n", (ULONG) pdg.SectorsPerTrack);
    printf("Bytes/sector = %ld\n", (ULONG) pdg.BytesPerSector);

    DiskSize = pdg.Cylinders.QuadPart * (ULONG)pdg.TracksPerCylinder *
      (ULONG)pdg.SectorsPerTrack * (ULONG)pdg.BytesPerSector;
    printf("Disk size = %I64d (Bytes) = %I64d (Gb)\n", DiskSize,
           DiskSize / (1024 * 1024 * 1024));
  }
  else
  {
    printf ("GetDriveGeometry failed. Error %ld.\n", GetLastError ());
  }

  return ((int)bResult);
}
]]
这个GetDeviceViaInterface()函数在管理员下应该是可以得到那个句柄的。
偶的疑问还有,windows ddk提供了驱动,那偶编程时只要把cypress的这个头文件加入就可以了吗?你说加入它的一个dll偶还好想点,一个头文件,对应的cpp都没有,加入了就用了个结构体就可以让windows驱动了吗?

现在有不少USB设备类使用Windows的标准驱动就可以的,你说的头文件添加的应该是当前你使用的USB设备的注册信息吧(我理解是用来区别设备的),里面是不是都是些GUID?
谢谢老大,老大是不是放逐的云的马甲。
呃,我不是马甲……:L