Beispiel #1
0
BOOL CEnumSerial::Win9xListPorts(CArray<SSerInfo,SSerInfo&> &asi)
/* Information on communications ports is stored in various places in the registry under
 * the HKEY_LOCAL_MACHINE\ENUM key. The structure of the HKLM\ENUM key, where information
 * on all hw devices present on the system is stored, is as follows
 *
 * HKLM\ENUM
 *   |-LEVEL1
 *     |-LEVEL2
 *       |-LEVEL3
 *         · CLASS
 *
 * LEVEL1 keys indicate the type of technology (vg., "PCI", "BIOS", "SCSI"). LEVEL2
 * keys refer to the type of device. So, for instance, "*PNP0501" is for 16550A UARTs.
 * LEVEL3 keys enumerate actual devices installed on the system. The value "CLASS",
 * present in all LEVEL3 keys, informs about the type of driver. For our purposes, we must
 * pay attention to the Class "Ports", that includes serial as well as parallel ports.
 * In these cases, another two values, "PORTNAME" and "FRIENDLYNAME" are expected.
 * An example follows. Typically, COM1 is recognized as a PnP device by the system BIOS
 * and as such placed on the registry like this:
 *
 * HKLM\ENUM
 *   |-BIOS
 *     |-*PNP0501
 *       |-0D (or any other value, this is not important for us)
 *         · CLASS=        "Ports"
 *         · PORTNAME=     "COM1"
 *         · FRIENDLYNAME= "Communications Port (COM1)"
 *
 * Win9xListPorts() scans all LEVEL3 keys under HKLM\ENUM searching for the Class
 * for ports, and when this is found determines, by means of "PORTNAME", whether the
 * device is a serial port or not.
 */
{
    return ScanEnumTree(TEXT("ENUM"), asi);
}
Beispiel #2
0
int usb_open( t_usbInterface* usbInt )
{		
  //--------------------------------------- Mac-only -------------------------------
  #ifndef WIN32
  
  if( usbInt->deviceOpen )  //if it's already open, do nothing.
    return MC_ALREADY_OPEN;

  int result = FindUsbSerialDevice( &usbInt->deviceName, 0 );
  //if( result );  //should return 0 on success
  //return; 
		
  // now try to actually do something
  usbInt->deviceHandle = open( usbInt->deviceName, O_RDWR | O_NOCTTY | ( ( usbInt->blocking ) ? 0 : O_NDELAY ) );
  if ( usbInt->deviceHandle < 0 )
  {
    //post( "Could not open the port (Error %d)\n", usbInt->deviceHandle );
    return MC_NOT_OPEN;
  } else
  {
    usbInt->deviceOpen = true;
	usleep( 10000 ); //give it a moment after opening before trying to read/write
	//post( "USB opened at %s, deviceHandle = %d", usbInt->deviceName, usbInt->deviceHandle);
	post( "mc.usb opened." );
  }
  return MC_OK;
  #endif
		
  //--------------------------------------- Windows-only -------------------------------
  
#ifdef WIN32
  TCHAR* openPorts[32];
  int i;
  int foundOpen;

  if( usbInt->deviceOpen )  //if it's already open, do nothing.
    return MC_ALREADY_OPEN;

  foundOpen = ScanEnumTree( usbInt, TEXT("SYSTEM\\CURRENTCONTROLSET\\ENUM\\USB"), openPorts);
  //post( "Found %d ports open", foundOpen );

  for( i = 0; i < foundOpen; i++ )
  {
    if( openPorts[i] != NULL )
	{
	  if( openDevice( usbInt, openPorts[i] ) == 0 )
	  {
		post( "mc.usb opened at: %s", openPorts[i] );
		Sleep( 10 );  // wait after opening it before trying to read/write
		usbInt->deviceOpen = true;
		return MC_OK;
	  }
	}
  }
  //post( "mc.usb did not open." );
  return MC_NOT_OPEN;
  #endif
}
Beispiel #3
0
UsbSerial::UsbStatus UsbSerial::usbOpen( )
{
  QMutexLocker locker( &usbOpenMutex );
  
  // Linux Only
  #if (defined(Q_WS_LINUX))
	  printf( "OSC over USB not implemented in Linux\n" );
    return NOT_OPEN;
  #endif

  //Mac-only
	#ifdef Q_WS_MAC
		if( deviceOpen )  //if it's already open, do nothing.
		  return ALREADY_OPEN;

		kern_return_t kernResult;
		io_iterator_t iterator = 0;
		
		kernResult = getDevicePath( iterator, deviceFilePath, sizeof(deviceFilePath) );
		IOObjectRelease( iterator ); // clean up
		
		if (!deviceFilePath[0] )
    {
			//printf("Didn't find a Make Controller.\n");
			return NOT_OPEN;
    }
		
		// now try to actually do something
		deviceHandle = ::open( deviceFilePath, O_RDWR | O_NOCTTY | ( ( blocking ) ? 0 : O_NDELAY ) );
		if ( deviceHandle < 0 )
	  {
	    //printf( "Could not open the port (Error %d)\n", deviceHandle );
	    return NOT_OPEN;
	  } else
		{
	    deviceOpen = true;
			sleepMs( 10 ); //give it a moment after opening before trying to read/write
			// printf( "USB opened at %s\n", deviceFilePath );
			messageInterface->message( 1, "Usb> Make Controller connected.\n" );
	  }
	  return OK;
		
	#endif //Mac-only UsbSerial::open( )
	
  //Windows-only
	#ifdef Q_WS_WIN
		if( deviceOpen )  //if it's already open, do nothing.
		  return ALREADY_OPEN;
		TCHAR* openPorts[32];
		int foundOpen = ScanEnumTree( TEXT("SYSTEM\\CURRENTCONTROLSET\\ENUM\\USB"), openPorts);
		//messageInterface->message( 1, "Found open: %d\n", foundOpen );
		int i;
		for( i = 0; i < foundOpen; i++ )
		{
			if( openPorts[i] != NULL )
			{
				if( openDevice( openPorts[i] ) == 0 )
				{
					messageInterface->message( 1, "Usb> Make Controller connected at %ls\n", openPorts[i] );
					Sleep( 10 );  // wait after opening it before trying to read/write
					deviceOpen = true;
			 		// now set up to get called back when it's unplugged
					bool result;
					result = DoRegisterForNotification( &deviceNotificationHandle );
					
					return OK;
				}
				//else
				  //messageInterface->message( 1, "Found device but could not open: %ls\n", openPorts[i] );
			}
			//else
			  //messageInterface->message( 1, "Did not find any potential ports\n" );
		}
	  return NOT_OPEN;
	#endif //Windows-only UsbSerial::open( )
}