USBFS_UART how to detect opening of USB Comm-port ?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
pacr_284376
Level 5
Level 5
100 replies posted 10 solutions authored 50 sign-ins

Hi there,

   

Is there a way to detect the opening/closing of the (virtual) comm-port from the PC side ?

   

I tried several USB variables but cannot figur out which one is the correct one to use, mainly because the reaction of the variables depend on which PC program I use.

   

For example, using TeraTerm give a configuration change on which I could trigger.

   

But unfortunately using Bray's Terminal or the following CSharp program does not (always) give a configuration change.

   

            SerialPort Dut=new SerialPort("COM7",115200);
            Debug.WriteLine("OPEN");
            Dut.Open();
            Thread.Sleep(1000);
            Debug.WriteLine("COMMAND");
            Dut.WriteLine("VAR LWR=1\r\n");
            Thread.Sleep(5000);
            Debug.WriteLine("CLOSE");
            Dut.Close();

   

 

   

Attached i have the basic USBFS_UART example, I made some changes to run it on my hardware (CY8CKIT-059) but, as said, it only registers changes in settings; not in opening/closing of the USB port.

   

Background :

   

- In my end-application I have a commandline-interface in which you can start/stop several timers and readout analog values. I want to reset the timers and maybe other stuff as soon as the USB port is closed.

   

Thanks

   

Patrick

0 Likes
1 Solution
pacr_284376
Level 5
Level 5
100 replies posted 10 solutions authored 50 sign-ins

Solved. I also need to set Dut.DtrEnable=true in the CSharp code. This is default false.

   

After doing this, the DTR can be checked in the embedded code to detect if the comport is opened or closed.

   

It works now, in Bray's Terminal the DTR switch must be set (once) manually to achieve the same.

   

I found this information in several forums of other manufacturers/libraries using USB-CDC such as LUFA so the problem is not related to PSOC5lp but to Windows/CSharp

   

Patrick

View solution in original post

0 Likes
1 Reply
pacr_284376
Level 5
Level 5
100 replies posted 10 solutions authored 50 sign-ins

Solved. I also need to set Dut.DtrEnable=true in the CSharp code. This is default false.

   

After doing this, the DTR can be checked in the embedded code to detect if the comport is opened or closed.

   

It works now, in Bray's Terminal the DTR switch must be set (once) manually to achieve the same.

   

I found this information in several forums of other manufacturers/libraries using USB-CDC such as LUFA so the problem is not related to PSOC5lp but to Windows/CSharp

   

Patrick

0 Likes