cancel
Showing results for 
Search instead for 
Did you mean: 

USB virtual COM port issue

Krenek.Steve
Associate III

I have an issue with the ST USB Virtual com port, on an STM32L152RC.

When I plug the device into my PC, the COM port appears as it should, and the Windows Device Manager indicates it is working properly.

I have a C# program on the PC which selects and opens this port.

However, in about 1 in 10 attempts, the PC program sticks on the port.open() command, and after about half a minute, returns with the error "The semaphore timeout period has expired".

I have written a tiny C# program that does nothing more than open the port. This still gives the behaviour noted.

   public partial class Form1 : Form
    {
 
        SerialPort port = new SerialPort();
        string portName = "COM1";  // give it a default to start with
 
 
        public Form1()
        {
            InitializeComponent();
 
            // Populate the com port selector combobox with available port names
            cmbPortSelect.Items.Clear();
 
            string[] activePorts = SerialPort.GetPortNames();
            foreach (string availablePort in activePorts)
            {
                cmbPortSelect.Items.Add(availablePort);
            }
 
            //declare the serial port
            port = new SerialPort(portName, 9600, Parity.None, 8, StopBits.One);
            port.ReadTimeout = 100;
 
        }
 
        private void cmbPortSelect_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbPortSelect.SelectedIndex != -1)
            {   // it will get set to -1 (ie no selection) in the catch below - we do't want this selected item change to do anything
                if (port.IsOpen) port.Close();
                port.PortName = (string)cmbPortSelect.SelectedItem;
                System.Threading.Thread.Sleep(50);
                try
                {
                    port.Open();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    cmbPortSelect.SelectedIndex = -1;  // clear the selected item box
                }
            }
 
        }
    }
}

The program hangs on the port.open() line.

If instead of using my C# program to open the port, I use the comms program PuTTY, it works every time.

In addition, if I plug in a device with an FDTI USB virtual com port, it also works every time.

I'm using Win7, with the STMicro VCP drivers ver 1.3.1, but the same behaviour occurs with Win10 and the generic Microsoft drivers, which STMicro recommend we use.

There is a version 1.5.1 drivers for Win7, but when I installed them, it reported that they had installed correctly, but the Device Manager still reported ver 1.3.1.

Has anyone noted any similar behaviour?

Thanks,

Steve

0 REPLIES 0