多个USB转RS485 FTDI设备ID

时间:2017-05-31 09:23:43

标签: c++ windows-10 ftdi

我需要一些帮助。我在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);
        }

    });

1 个答案:

答案 0 :(得分:0)

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

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