Ejemplo n.º 1
0
int main() {
    // Setup the variables we will need.
    int r = 0; // For checking return values
    HANDLE devHandle = 0;
    BYTE sendBuffer[CONFIGU6_COMMAND_LENGTH], recBuffer[CONFIGU6_RESPONSE_LENGTH];

    // Open the U6
    devHandle = LJUSB_OpenDevice(1, 0, U6_PRODUCT_ID);
    
    if( devHandle == NULL ) {
        printf("Couldn't open U6. Please connect one and try again.\n");
        exit(-1);
    }

    // Builds the ConfigU6 command
    buildConfigU6Bytes(sendBuffer);
    
    // Write the command to the device.
    // LJUSB_Write( handle, sendBuffer, length of sendBuffer )
    r = LJUSB_Write( devHandle, sendBuffer, CONFIGU6_COMMAND_LENGTH );
    
    if( r != CONFIGU6_COMMAND_LENGTH ) {
        printf("An error occurred when trying to write the buffer. The error was: %d\n", errno);
        // *Always* close the device when you error out.
        LJUSB_CloseDevice(devHandle);
        exit(-1);
    }
    
    // Read the result from the device.
    // LJUSB_Read( handle, recBuffer, number of bytes to read)
    r = LJUSB_Read( devHandle, recBuffer, CONFIGU6_RESPONSE_LENGTH );
    
    if( r != CONFIGU6_RESPONSE_LENGTH ) {
        printf("An error occurred when trying to read from the U6. The error was: %d\n", errno);
        LJUSB_CloseDevice(devHandle);
        exit(-1);
    }
    
    // Check the command for errors
    if( checkResponseForErrors(recBuffer) != 0 ){
        LJUSB_CloseDevice(devHandle);
        exit(-1);
    }
    
    // Parse the response into something useful
    parseConfigU6Bytes(recBuffer);
    
    //Close the device.
    LJUSB_CloseDevice(devHandle);
    
    return 0;
}
Ejemplo n.º 2
0
HANDLE openUSBConnection(int localID)
{
    BYTE sendBuffer[26], recBuffer[38];
    uint16 checksumTotal = 0;
    HANDLE hDevice = 0;
    uint32 numDevices = 0;
    uint32 dev;
    int i;

    numDevices = LJUSB_GetDevCount(U6_PRODUCT_ID);
    if(numDevices == 0)
    {
        printf("Open error: No U6 devices could be found\n");
        return NULL;
    }

    for(dev = 1;  dev <= numDevices; dev++)
    {
        hDevice = LJUSB_OpenDevice(dev, 0, U6_PRODUCT_ID);
        if(hDevice != NULL)
        {
            if(localID < 0)
            {
                return hDevice;
            }
            else
            {
                checksumTotal = 0;

                //setting up a U6Config
                sendBuffer[1] = (uint8)(0xF8);
                sendBuffer[2] = (uint8)(0x0A);
                sendBuffer[3] = (uint8)(0x08);

                for(i = 6; i < 26; i++)
                    sendBuffer[i] = (uint8)(0x00);

                extendedChecksum(sendBuffer, 26);

                if(LJUSB_BulkWrite(hDevice, U6_PIPE_EP1_OUT, sendBuffer, 26) != 26)
                    goto locid_error;

                if(LJUSB_BulkRead(hDevice, U6_PIPE_EP2_IN, recBuffer, 38) != 38)
                    goto locid_error;

                checksumTotal = extendedChecksum16(recBuffer, 38);
                if( (uint8)((checksumTotal / 256) & 0xff) != recBuffer[5])
                    goto locid_error;

                if( (uint8)(checksumTotal & 0xff) != recBuffer[4])
                    goto locid_error;

                if( extendedChecksum8(recBuffer) != recBuffer[0])
                    goto locid_error;

                if( recBuffer[1] != (uint8)(0xF8) || recBuffer[2] != (uint8)(0x10) ||
                    recBuffer[3] != (uint8)(0x08) )
                    goto locid_error;

                if( recBuffer[6] != 0)
                    goto locid_error;

                if( (int)recBuffer[21] == localID)
                    return hDevice;
                else
                    LJUSB_CloseDevice(hDevice);
            } //else localID >= 0 end
        } //if hDevice != NULL end
    } //for end

    printf("Open error: could not find a U6 with a local ID of %d\n", localID);
    return NULL;

locid_error:
    printf("Open error: problem when checking local ID\n");
    return NULL;
}
Ejemplo n.º 3
0
HANDLE openUSBConnection(int localID)
{
  BYTE buffer[38];
  uint16 checksumTotal = 0;
  HANDLE hDevice = 0;
  uint32 numDevices = 0;
  uint32 dev;
  int i;

  numDevices = LJUSB_GetDevCount(UE9_PRODUCT_ID);
  if(numDevices == 0) 
  {
    printf("Open error: No UE9 devices could be found\n");
    return NULL;
  }

  for(dev = 1;  dev <= numDevices; dev++) 
  {
    hDevice = LJUSB_OpenDevice(dev, 0, UE9_PRODUCT_ID);
    if(hDevice != NULL)
    {
      if(localID < 0)
      {
        return hDevice;
      }
      else
      {
        checksumTotal = 0;

        //setting up a CommConfig command
        buffer[1] = (BYTE)(0x78);
        buffer[2] = (BYTE)(0x10);
        buffer[3] = (BYTE)(0x01);

        for(i = 6; i < 38; i++)
          buffer[i] = (BYTE)(0x00);

        extendedChecksum(buffer,38);

        if(LJUSB_BulkWrite(hDevice, UE9_PIPE_EP1_OUT, buffer, 38) != 38)
          goto locid_error;

        for(i = 0; i < 38; i++)
          buffer[i] = 0;

        if(LJUSB_BulkRead(hDevice, UE9_PIPE_EP1_IN, buffer, 38) != 38)
          goto locid_error;

        checksumTotal = extendedChecksum16(buffer, 38);
        if( (BYTE)((checksumTotal / 256) & 0xff) != buffer[5])
          goto locid_error;

        if( (BYTE)(checksumTotal & 0xff) != buffer[4])
          goto locid_error;

        if( extendedChecksum8(buffer) != buffer[0])
          goto locid_error;

        if( buffer[1] != (BYTE)(0x78) || buffer[2] != (BYTE)(0x10) || buffer[3] != (BYTE)(0x01) )
          goto locid_error;

        if( (int)buffer[8] == localID)
          return hDevice;
        else 
          LJUSB_CloseDevice(hDevice);

      } //else localID >= 0 end
    }  //if hDevice != NULL end
  } //for end

  printf("Open error: could not find a UE9 with a local ID of %d\n", localID);
  return NULL;

locid_error:
  printf("Open error: problem when checking local ID\n");
  return NULL;
}
Ejemplo n.º 4
0
HANDLE openUSBConnection(int localID)
{
    BYTE buffer[38];
    uint16 checksumTotal = 0;
    uint32 numDevices = 0;
    uint32 dev;
    int i, serial;
    HANDLE hDevice = 0;

    numDevices = LJUSB_GetDevCount(UE9_PRODUCT_ID);
    if( numDevices == 0 ) 
    {
        printf("Open error: No UE9 devices could be found\n");
        return NULL;
    }

    for( dev = 1;  dev <= numDevices; dev++ )
    {
        hDevice = LJUSB_OpenDevice(dev, 0, UE9_PRODUCT_ID);
        if( hDevice != NULL )
        {
            if( localID < 0 )
            {
                return hDevice;
            }
            else
            {
                checksumTotal = 0;

                //Setting up a CommConfig command
                buffer[1] = (BYTE)(0x78);
                buffer[2] = (BYTE)(0x10);
                buffer[3] = (BYTE)(0x01);

                for( i = 6; i < 38; i++ )
                    buffer[i] = (BYTE)(0x00);

                extendedChecksum(buffer,38);

                if( LJUSB_Write(hDevice, buffer, 38) != 38 )
                    goto locid_error;

                for( i = 0; i < 38; i++ )
                    buffer[i] = 0;

                if( LJUSB_Read(hDevice, buffer, 38) != 38 )
                    goto locid_error;

                checksumTotal = extendedChecksum16(buffer, 38);
                if( (BYTE)((checksumTotal / 256) & 0xFF) != buffer[5] )
                    goto locid_error;

                if( (BYTE)(checksumTotal & 0xFF) != buffer[4] )
                    goto locid_error;

                if( extendedChecksum8(buffer) != buffer[0] )
                    goto locid_error;

                if( buffer[1] != (BYTE)(0x78) || buffer[2] != (BYTE)(0x10) || buffer[3] != (BYTE)(0x01) )
                    goto locid_error;

                //Check local ID
                if( (int)buffer[8] == localID )
                    return hDevice;
                
                //Check serial number
                serial = buffer[28] + buffer[29]*256 + buffer[30]*65536 + 0x10000000;
                if( serial == localID )
                    return hDevice;

                //No matches.  Not our device.
                LJUSB_CloseDevice(hDevice);

            }  //else localID >= 0 end
        }  //if hDevice != NULL end
    }  //for end

    printf("Open error: could not find a UE9 with a local ID or serial number of %d\n", localID);
    return NULL;

locid_error:
    printf("Open error: problem when checking local ID and serial number\n");
    return NULL;
}