Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

PSoC™ 5, 3 & 1 Forum Discussions

Anonymous
Not applicable

Dear All;

As a complete beginner I am following this guide: Cypress CyUsb3.sys Programmer's Reference.

I have completed all the steps for Modifying CyUSB3.INF section.

I deduce that from figure below because in the guide I have been following it is mentioned that If the displayed driver file is CYUSB3.SYS

Windows has already matched the device to this driver and you should click OK and Cancel . If not, proceed with the remaining steps.

Capture.PNG

I can also transfer data using Cypress USB Console. To do this I; first change the CYUSB.sys to CYUSB3.sys as in the figure below.

Capture.PNG

When I change into CYUSB3.sys my device appears in USB Address 1.

Also in the cyusb3.inf file I have this line : CYUSB3.GUID="{BC65166E-F256-45C6-A61F-0712F462B635}" which matches with the number above.

Now I can send the data OUT as you can see in the figure below:

Capture.PNG

However, when I try to detect the same device in the C++/Visual Studio 2015 environment, I face the following problem.

I assign a handle and check it afterwards.

InitializeComponent();

CCyUSBDevice *USBDevice = new CCyUSBDevice();

HANDLE hDevice = USBDevice->DeviceHandle();

if (hDevice == INVALID_HANDLE_VALUE) {

textBox1->Text = textBox1->Text + "INVALID_HANDLE_VALUE \r";

}

if (hDevice != INVALID_HANDLE_VALUE) {

textBox1->Text = textBox1->Text + "VALID_HANDLE_VALUE \r";

}

Then I check number of devices which are attached by the following line

int devices;

devices = USBDevice->DeviceCount();

textBox1->Text = textBox1->Text + "\r\n";

textBox1->Text = textBox1->Text + "Number of devices : \r";

textBox1->Text = textBox1->Text + System::Convert::ToString(devices);

When I execute the code I see the following:

Capture.PNG

So the handle is valid but number of devices are 0 which means the device attached is VISIBLE in the Cypress USB Console but now in the C++ code.

So can you help me about that problem?

How can I make it visible and use it in my C++ code?

You can find the full code at the end.

Looking forward for your reply...

----------------------FULL CODE-----------------------

#pragma once

#include <stdio.h>

#include <wtypes.h>

#include <dbt.h>

#include "CyAPI.h"

#include <SetupAPI.h>

#include <CyUSB30_def.h>

#include <Mswmdm.h>

#include <windows.h>

#include <winioctl.h>

#include <iostream>

#include <vector>

#include <array>

#include <stddef.h>

#include <wchar.h>

#include <locale.h>

#include <fstream>

#include <cyioctl.h>

namespace CyPressDataYollama {

using namespace System;

using namespace System::ComponentModel;

using namespace System::Collections;

using namespace System::Windows::Forms;

using namespace System::Data;

using namespace System::Drawing;

/// <summary>

/// Summary for MyForm

/// </summary>

public ref class MyForm : public System::Windows::Forms::Form

{

public:

private: System::Windows::Forms::TextBox^  textBox1;

private: System::Windows::Forms::ListBox^  listBox1;

public:

MyForm(void)

{

// Get the handle.

InitializeComponent();

CCyUSBDevice *USBDevice = new CCyUSBDevice();

HANDLE hDevice = USBDevice->DeviceHandle();

if (hDevice == INVALID_HANDLE_VALUE) {

textBox1->Text = textBox1->Text + "INVALID_HANDLE_VALUE \r";

}

if (hDevice != INVALID_HANDLE_VALUE) {

textBox1->Text = textBox1->Text + "VALID_HANDLE_VALUE \r";

}

int devices;

devices = USBDevice->DeviceCount();

textBox1->Text = textBox1->Text + "\r\n";

textBox1->Text = textBox1->Text + "Number of devices : \r";

textBox1->Text = textBox1->Text + System::Convert::ToString(devices);

/*

textBox1->Text = textBox1->Text + "\r\n";

textBox1->Text = textBox1->Text + "USB Handle : \r";

textBox1->Text = textBox1->Text + System::Convert::ToString(Handle);

textBox1->Text = textBox1->Text + "\r\n";

textBox1->Text = textBox1->Text + "Number of Devices : \r";

textBox1->Text = textBox1->Text + System::Convert::ToString(devices);

*/

}

protected:

/// <summary>

/// Clean up any resources being used.

/// </summary>

~MyForm()

{

if (components)

{

delete components;

}

}

private:

/// <summary>

/// Required designer variable.

/// </summary>

System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

void InitializeComponent(void)

{

this->textBox1 = (gcnew System::Windows::Forms::TextBox());

this->listBox1 = (gcnew System::Windows::Forms::ListBox());

this->SuspendLayout();

//

// textBox1

//

this->textBox1->Location = System::Drawing::Point(12, 12);

this->textBox1->Multiline = true;

this->textBox1->Name = L"textBox1";

this->textBox1->Size = System::Drawing::Size(642, 317);

this->textBox1->TabIndex = 0;

//

// listBox1

//

this->listBox1->FormattingEnabled = true;

this->listBox1->ItemHeight = 16;

this->listBox1->Location = System::Drawing::Point(759, 181);

this->listBox1->Name = L"listBox1";

this->listBox1->Size = System::Drawing::Size(120, 84);

this->listBox1->TabIndex = 1;

//

// MyForm

//

this->AutoScaleDimensions = System::Drawing::SizeF(8, 16);

this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;

this->ClientSize = System::Drawing::Size(1025, 544);

this->Controls->Add(this->listBox1);

this->Controls->Add(this->textBox1);

this->Name = L"MyForm";

this->Text = L"MyForm";

this->ResumeLayout(false);

this->PerformLayout();

}

#pragma endregion

};

}

0 Likes
1 Solution
Anonymous
Not applicable

Thanks for the swift reply.

I just solved the problem. It was about the GUID. To be more specific the GUID in the "cyusb3.inf" has to be the same with the one in the "cyAPI.h"

View solution in original post

0 Likes
2 Replies
Anonymous
Not applicable

Thanks for the swift reply.

I just solved the problem. It was about the GUID. To be more specific the GUID in the "cyusb3.inf" has to be the same with the one in the "cyAPI.h"

0 Likes