示例#1
0
VOID 
__cdecl 
wmain()
{
    HANDLE hDevice = INVALID_HANDLE_VALUE;
    BOOL echo = TRUE;
    LPWSTR devicePath = NULL;
    DWORD err = GetDevicePath((LPGUID)&BTHECHOSAMPLE_DEVICE_INTERFACE, &devicePath);

    if (ERROR_SUCCESS != err) {
        printf("Failed to find the BTHECHO device\n");
        exit(1);
    }

    hDevice = CreateFile(devicePath,
                         GENERIC_READ|GENERIC_WRITE,
                         FILE_SHARE_READ | FILE_SHARE_WRITE,
                         NULL,
                         OPEN_EXISTING,
                         0,
                         NULL );

    if (hDevice == INVALID_HANDLE_VALUE) {
        printf("Failed to open device. Error %d\n",GetLastError());
        LocalFree(devicePath);
        exit(1);
    } 

    printf("Opened device successfully\n");

    while (echo)
    {
        echo = DoEcho(hDevice);
    }
                
    if (INVALID_HANDLE_VALUE != hDevice) {
        CloseHandle(hDevice);
        printf("Closed device\n");
    }

    if (NULL != devicePath) {
        LocalFree(devicePath);
    }
}
示例#2
0
// Will create a connection to the device
HRESULT CSensorCommunication::Initialize()
{
    HRESULT hr = S_OK;
    WCHAR completeDeviceName[MAX_DEVPATH_LENGTH];

    if (nullptr != m_hDev)
    {
        // m_hDev should be null to start
        hr = E_FAIL;
    }

    if (SUCCEEDED(hr))
    {
        hr = GetDevicePath(
            (LPGUID) &GUID_DEVINTERFACE_GPS_RADIO_MANAGEMENT,
            completeDeviceName,
            MAX_DEVPATH_LENGTH
            );
    }

    if (SUCCEEDED(hr))
    {
        m_hDev = CreateFile(
            completeDeviceName,
            GENERIC_WRITE | GENERIC_READ,
            FILE_SHARE_WRITE | FILE_SHARE_READ,
            nullptr, // default security
            OPEN_EXISTING,
            FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
            nullptr
            );

        if (INVALID_HANDLE_VALUE == m_hDev)
        {
            hr = HRESULT_FROM_WIN32(GetLastError());
            m_hDev = nullptr;
        }
    }

    return hr;
}
示例#3
0
// エントリーポイント
int main(int ac, char **av)
{
    int sts = -1;
    char szDevicePath[256];
    HANDLE hDevice = INVALID_HANDLE_VALUE;
    BOOL doDisplay = FALSE;
    DWORD dwError;

    // 引数無しなら受信モード
    if (ac < 2) {
        doDisplay = TRUE;
    }
    // USB IR REMOCON のデバイスパスを得る
    dwError = GetDevicePath(szDevicePath, sizeof(szDevicePath));
    if (dwError != ERROR_SUCCESS) {
        fprintf(stderr, "failed to get device path: err=%u", dwError);
        goto DONE;
    }
    // データ送受信用にデバイスをオープン
    hDevice = CreateFile(szDevicePath, GENERIC_WRITE|GENERIC_READ,
            FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
    if (hDevice == INVALID_HANDLE_VALUE) {
        DWORD err = GetLastError();
        fprintf(stderr, "CreateFile: err=%u\n", err);
        goto DONE;
    }
    if (doDisplay) {
        sts = Display(hDevice); // 受信モードへ
    } else {
        sts = Transfer(hDevice, ac, av); // 送信モードへ
    }

DONE:
    if (hDevice != INVALID_HANDLE_VALUE) {
        CloseHandle(hDevice);
    }
    return sts;
}
BOOL CDevice::Init()
{
    PWCHAR DevicePath = NULL;
    if ((DevicePath = GetDevicePath((LPGUID)&GUID_DEVINTERFACE_BALLOON)) != NULL) {
        m_hDevice = CreateFile(
                             DevicePath,
                             GENERIC_WRITE,
                             0,
                             NULL,
                             OPEN_EXISTING,
                             FILE_ATTRIBUTE_NORMAL,
                             NULL
                             );

        if (m_hDevice != INVALID_HANDLE_VALUE) {
            PrintMessage("Open balloon device");
            return TRUE;
        }

    }
    PrintMessage("Cannot find balloon device");
    return FALSE;
}
BOOL CDevice::Init(BOOL ovrl)
{
    PWCHAR DevicePath = NULL;
    if ((DevicePath = GetDevicePath((LPGUID)&GUID_VIOSERIAL_PORT)) != NULL)
    {
        m_hDevice = CreateFile(DevicePath,
                             GENERIC_WRITE | GENERIC_READ,
                             0,
                             NULL,
                             OPEN_EXISTING,
                             ovrl ? FILE_FLAG_OVERLAPPED : FILE_ATTRIBUTE_NORMAL,
                             NULL );

        if (m_hDevice != INVALID_HANDLE_VALUE)
        {
            printf("Open vioserial device  %S.\n", DevicePath);
            return TRUE;
        }

    }
    DWORD err = GetLastError();
    printf("Cannot find vioserial device. %S , error = %d\n", DevicePath, err );
    return FALSE;
}
EFI_STATUS
BBTestRouteConfigConformanceTestCheckpoint2 (
  IN EFI_STANDARD_TEST_LIBRARY_PROTOCOL    *StandardLib,
  IN EFI_HII_CONFIG_ROUTING_PROTOCOL       *HIIConfigRouting,
  IN EFI_HII_CONFIG_ACCESS_PROTOCOL        *HIIConfigAccess
  )
{
  EFI_STATUS            Status;
  EFI_TEST_ASSERTION    AssertionType;
  
  EFI_STRING            Config = NULL;
  EFI_STRING            MultiConfigAltResp = NULL;
  EFI_STRING            DevicePath = NULL;
  
  //init the Request 
  Status = HIIConfigRouting->ExportConfig(
                               HIIConfigRouting,
                               &MultiConfigAltResp
                               );
  if (EFI_ERROR(Status)) {
    return Status;
  }

  Status = GetDevicePath ( HIIConfigAccess, &DevicePath );
  if (EFI_ERROR(Status)) {
  	gtBS->FreePool(MultiConfigAltResp);
    return Status;
  }

  Config = (EFI_STRING) AllocateZeroPool( 2 * StrLen(MultiConfigAltResp) + 2 );
  if (Config == NULL) {
    gtBS->FreePool(MultiConfigAltResp);
	gtBS->FreePool(DevicePath);
	return EFI_OUT_OF_RESOURCES;
  }
  
  Status = GetCorrespondingResp (MultiConfigAltResp, DevicePath, Config);
  if (EFI_ERROR(Status)) {
  	gtBS->FreePool(MultiConfigAltResp);
	gtBS->FreePool(DevicePath);
	gtBS->FreePool(Config);
    return Status;
  }
  
  //
  // Call RouteConfig with Progress been NULL
  //
  Status = HIIConfigAccess->RouteConfig (
                              HIIConfigAccess,
                              Config,
                              NULL
                              );
  
  if ( EFI_INVALID_PARAMETER != Status ) {
    AssertionType = EFI_TEST_ASSERTION_FAILED;
  } else {
    AssertionType = EFI_TEST_ASSERTION_PASSED;
  }
  StandardLib->RecordAssertion (
                 StandardLib,
                 AssertionType,
                 gHIIConfigAccessBBTestConformanceAssertionGuid006,
                 L"HII_CONFIG_ACCESS_PROTOCOL.RouteConfig - RouteConfig() returns EFI_INVALID_PARAMETER with Progress been NULL.",
                 L"%a:%d: Status - %r",
                 __FILE__,
                 (UINTN)__LINE__,
                 Status
                 );

  gtBS->FreePool(MultiConfigAltResp);
  gtBS->FreePool(DevicePath);
  gtBS->FreePool(Config);

  return EFI_SUCCESS;
}