gpt4 book ai didi

c++ - 多个 USB 转 RS485 FTDI 设备 ID

转载 作者:太空宇宙 更新时间:2023-11-04 13:00:51 24 4
gpt4 key购买 nike

我需要一些帮助。我正在用 C++/CX 编写 Win 10 应用程序。我正在使用两个 USB 转 RS485 设备,它们都具有相同的 VID 号。在过去,我可以编写一些软件并使用良好的旧 COMx 等连接到端口。

我现在按照此处的示例 Serial Sample它使用收集设备信息的方法,因此在查找连接的设备时,我在可用设备列表中看到的如下。

\?\FTDIBUS#VID_0403+PID_6001

两个设备具有相同的 VID 和 PID。这导致我无法通过电缆连接到正确的 USB 设备。我认为我的应用正在尝试同时连接到两个设备?有没有人对我如何解决这个问题有任何想法?

void MainPage::Get_Serial_Devices() {

cancellationTokenSource_Port1 = new Concurrency::cancellation_token_source();
cancellationTokenSource_Port2 = new Concurrency::cancellation_token_source();

// THIS USES ASYNCRONOUS OPERATION. GET A LIST OF SERIAL DEVICES AND POPULATE THE COMBO BOX
Concurrency::create_task(ListAvailablePortsAsync()).then([this](DeviceInformationCollection^ serialDeviceCollectioin)
{

// serialDeviceCollection CONTAINS ALL SERIAL DEVICES FOUND, COPY INTO _deviceCollection
DeviceInformationCollection^ _deviceCollection = serialDeviceCollectioin;

// CLEAR EXISTING DEVICES FOR OUR OBJECT COLLECTION
_availableDevices->Clear();

// FOR EVERY DEVICE IN _deviceCollection
for (auto &&device : _deviceCollection) {

if (device->Name->Equals("USB-RS485 Cable")) {

// CREATE A NEW DEVICE TYPE AND APPEND TO OUR OBJECT COLLECTION
_availableDevices->Append(ref new Device(device->Id, device));

Total_Ports++;

this->DeviceLists->Items->Append(device->Id);


}

}

});





void MainPage::ConnectButton_Click(Object^ sender, RoutedEventArgs^ e) {



if (Port1_Connected == false) {

// CAST INDEX TO CORRELATING Device IN _availableDevices
Device^ selectedDevice = static_cast<Device^>(_availableDevices->GetAt(Port_1_ID));



// GET THE DEVICE INFO
DeviceInformation^ entry = selectedDevice->DeviceInfo;



Concurrency::create_task(ConnectToSerialDeviceAsync_Port1(entry, cancellationTokenSource_Port1->get_token())).then([this]( ) {

Get_Echo();
Waiting_For_Ack = true;


});

}


Concurrency::task<void> MainPage::ConnectToSerialDeviceAsync_Port1(DeviceInformation^ device, Concurrency::cancellation_token cancellationToken) {


// CREATE A LINKED TOKEN WHICH IS CANCELLED WHEN THE PROVIDED TOKEN IS CANCELLED
auto childTokenSource = Concurrency::cancellation_token_source::create_linked_source(cancellationToken);

// GET THE TOKEN
auto childToken = childTokenSource.get_token();


// CONNECT TO ARDUINO TASK
return Concurrency::create_task(SerialDevice::FromIdAsync(device->Id), childToken).then([this](SerialDevice^ serial_device) {

try {



_serialPort_Port1 = serial_device;

TimeSpan _timeOut; _timeOut.Duration = 10;

// CONFIGURE SERIAL PORT SETTINGS

_serialPort_Port1->WriteTimeout = _timeOut;
_serialPort_Port1->ReadTimeout = _timeOut;

_serialPort_Port1->BaudRate = 57600;

_serialPort_Port1->Parity = Windows::Devices::SerialCommunication::SerialParity::None;
_serialPort_Port1->StopBits = Windows::Devices::SerialCommunication::SerialStopBitCount::One;
_serialPort_Port1->DataBits = 8;
_serialPort_Port1->Handshake = Windows::Devices::SerialCommunication::SerialHandshake::None;



// CREATE OUR DATA READER OBJECT
_dataReaderObject_Port1 = ref new DataReader(_serialPort_Port1->InputStream);
_dataReaderObject_Port1->InputStreamOptions = InputStreamOptions::None;


// CREATE OUR DATA WRITE OBJECT
_dataWriterObject_Port1 = ref new DataWriter(_serialPort_Port1->OutputStream);


this->ConnectButton->IsEnabled = false;
this->DisconnectButton->IsEnabled = true;


// KICK OF THE SERIAL PORT LISTENING PROCESS
Listen_Port1();



}

catch (Platform::Exception^ ex) {

this->Error_Window->Text = (ex->Message);

CloseDevice(PORT_1);
}

});

最佳答案

FT_PROG是一个免费的 EEPROM 编程实用程序,用于 FTDI 设备。它用于修改存储 FTDI 设备描述符的 EEPROM 内容以定制设计。

可以下载完整的 FT_PROG 用户指南 here .

关于c++ - 多个 USB 转 RS485 FTDI 设备 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44280754/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com