多个USB到RS485 FTDI设备ID

Multiple USB to RS485 FTDI Device ID

本文关键字:设备 ID FTDI RS485 USB 多个      更新时间:2023-10-16

我需要一些帮助。我正在编程C /CX中的Win 10应用程序。我将两个USB用于RS485设备,这两种设备都具有相同的VID号。在过去的日子里,我可以写一些软件,并使用良好的旧粘液等连接到端口等。

我现在正在关注此处的示例串行示例,该样本使用该方法收集设备信息,因此在寻找连接的设备时,我在可用设备列表中看到的内容如下。

? 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用户指南。