QHYCCD

Examples for low-level USB protocol on Windows 7?

Examples for low-level USB protocol on Windows 7?
« on: August 10, 2017, 12:54:08 AM »
Hello -- I am interested in using the low-level USB driver on Windows 7.  I understand I should use the cyusb driver.  I have had some trouble finding a good, simple way to install this driver.  I also do not have any experience with low-level USB operations, and so the whole thing seems very complicated, just to talk to the camera.

Is there an example program that runs on Windows that I could see, showing how to connect to the camera with USB, and then send and receive commands?

Thank you!

- donl

LCH

Re: Examples for low-level USB protocol on Windows 7?
« Reply #1 on: August 10, 2017, 10:34:43 AM »
Hello
    I am a developer in QHYCCD and recently i am doing stuff like connecting the camera by using low-level protocol.You can simply use a C compiler running the code and don't forget to include the library of cyusb(download here:  http://www.cypress.com/?app=sdc ,  choose EZ-USB FX)
    I am not in the company now and I will put some examples of the low-level protocol communication between PC and camera tomorrow.

best regards
Li Chenghan

LCH

Re: Examples for low-level USB protocol on Windows 7?
« Reply #2 on: August 10, 2017, 09:26:02 PM »
#include <windows.h>
#include "stdafx.h"
#include <iostream>
#include <string>
#include <stdio.h>
#include "CyAPI.h"
#include<stdlib.h>
int  main()
{
   CCyUSBDevice* pUSB = new CCyUSBDevice;
   int  nDeviceCount = pUSB->DeviceCount();
   for (int nIdx = 0; nIdx < pUSB->DeviceCount(); nIdx++)
   {
      pUSB->Open(nIdx);
      printf("Device name is""%s\n", pUSB->DeviceName);
   }                                                                                       //opening the device and print the name
   printf("DeviceCount ""%d\n", nDeviceCount);                         //Count the number of devices
   int  vID, pID;
   vID = pUSB->VendorID;
   pID = pUSB->ProductID;
   printf("the Vid of the device is ""%04X\n", vID);
   printf("the Pid of the device is ""%04X\n", pID);
   int epts = pUSB->EndPointCount();
   printf("EndPointCount  ""%d\n", epts);                                     //Count the number of endpoint
   //  Just for typing efficiency
   CCyControlEndPoint  *ept = pUSB->ControlEndPt;                  //define Control endpoint
   ept->Target = TGT_DEVICE;
   ept->ReqType = REQ_VENDOR;                               //use vendrequest
   ept->ReqCode = 0xD1;                                     //0xD1 direction is OUT.Host computer will send 16bytes data in this vendrequest to the camera
   ept->Value = 0;
   ept->Index = 0;                                          //no use here
   PUCHAR buf = new UCHAR[15];
   LONG bytesToSend = 16;
   buf[0] = 0xA0;
   buf[1] = 0x01;
   buf[2] = 0x00;
   buf[3] = 0x01;
   buf[4] = 0x00;
   buf[5] = 0x01;
   int i;
   for (i = 5; i < 15; i++)
   {
      buf = 0x00;
   }                                                      //input the initialization command(ccc is 0xA0)with single-frame mode(ccp1 is 0x01)
   ept->Write(buf, bytesToSend);                          //send vendrequest to the camera
   printf("device initialized\n");
   ept->ReqCode = 0XD2;                                   //0xD2 direction is IN. Host computer will read 64bytes data of camera current status information in this vendrequest from camera
   ept->Value = 0;
   ept->Index = 0;
   PUCHAR buf1 = new UCHAR[64];
   long buflen = 64;
   ept->Read(buf1, buflen);                               //read 64bytes data from the camera
   printf("print the data transfered\n");
   int j, k;
   for (j = 0; j < 63; j++)
   {
      k = buf1[j];
      printf("%x  ", k);
   }
}

LCH

Re: Examples for low-level USB protocol on Windows 7?
« Reply #3 on: August 10, 2017, 09:32:51 PM »
Above is an example of using vendrequest to connect.
Its function is initializing the camera and then read the information from camera.
Here is the result of this code.

LCH

Re: Examples for low-level USB protocol on Windows 7?
« Reply #4 on: August 10, 2017, 09:35:20 PM »
Above is an example of using vendrequest to connect.
Its function is initializing the camera and then read the information from camera.
Here is the result of this code.

LCH

Re: Examples for low-level USB protocol on Windows 7?
« Reply #5 on: August 10, 2017, 09:42:09 PM »
This is an example of QHY163,you can check the topic of QHY163 low-level protocol in the developer board and compare the result with it.
The low-level protocols of different types are similar,you can learn to use it by reading the structure of the protocol provided in the board