简体   繁体   English

多个USB转RS485 FTDI设备ID

[英]Multiple USB to RS485 FTDI Device ID

I need some help. 我需要协助。 I'm programming a Win 10 App in C++/CX. 我正在使用C ++ / CX编写Win 10应用程序。 I am using two USB to RS485 devices, both of which have the same VID number. 我使用两个USB到RS485设备,两者都有相同的VID号码。 In days of old, I could write a bit software and connect to ports using good old COMx etc. 在旧的日子里,我可以编写一些软件并使用旧的COMx等连接到端口。

I'm now following the example here Serial Sample which uses the approach gathering the device info so when looking for connected devices, what I see in the list of available devices is the following. 我现在按照此处的示例串行样本使用收集设备信息的方法,因此在查找连接的设备时,我在可用设备列表中看到的内容如下。

\\?\\FTDIBUS#VID_0403+PID_6001 \\?\\ FTDIBUS#VID_0403 + PID_6001

Both devices have the same VID and PID. 两个设备都具有相同的VID和PID。 This leads to the problem of me being cable to connect to the correct USB device. 这导致我有线连接到正确的USB设备的问题。 I think my app is trying to connect to both devices at the same time? 我想我的应用程序试图同时连接到这两个设备? Does anyone have any ideas about how I can resolve this hitch? 有没有人对如何解决这个障碍有任何想法?

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 is a free EEPROM programming utility for use with FTDI devices. FT_PROG是一个免费的EEPROM编程实用程序,用于FTDI设备。 It is used for modifying EEPROM contents that store the FTDI device descriptors to customize designs. 它用于修改存储FTDI设备描述符的EEPROM内容以定制设计。

The full FT_PROG User Guide can be downloaded here . 可以在此处下载完整的FT_PROG用户指南。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM