USBUART: detect whether terminal is connected

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

cross mob
ricardoquesada
Level 4
Level 4
First solution authored 50 sign-ins 25 replies posted

Hi,

[context: Using PSoC 5LP]

I have the following scenario:

 I'm using USBUART for console, and writing to the console works great as long as a terminal is attached in the host.

If there are no terminal attached, it keeps waiting for ever in the "while" (see code):

```

void console_print(const char* msg) {

  // Loops forever if no terminal is attached

  while (!USBUART_CDCIsReady())
       ;

   USBFS_PutString(msg);

}

```

What I'd like to do detect is whether a terminal is connected...  something like:

```

void console_print(const char* msg) {

  // exit if no terminal is attached

  if (!terminal_is_attched())

      return;

  while (!USBUART_CDCIsReady())
       ;

   USBFS_PutString(msg);

}

```

 

How can I detect whether the terminal is attached? (or avoid waiting forever is CDCIsReady() if host doesn't have a terminal) ?

 

Many thanks!

0 Likes
1 Solution
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

ricardo,

I created a custom component that might help do what you want.

This component can be set to use the UART port interface OR the USBUART port interface.

The API interface uses the UART-style calls for simplicity and you can switch between UART types without changing the code.

Additionally, I "fixed" the terminal disconnected issue you are seeing.  Just like the UART port doesn't care if the terminal program at the other end is connected or not, the USBUART interface will continue without the while() hangup.

Here is a link to the "Code Sharing" forum thread with the component code.

Terminal-Support-Component-Library 

Enjoy!

Len
"Engineering is an Art. The Art of Compromise."

View solution in original post

2 Replies
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

ricardo,

I created a custom component that might help do what you want.

This component can be set to use the UART port interface OR the USBUART port interface.

The API interface uses the UART-style calls for simplicity and you can switch between UART types without changing the code.

Additionally, I "fixed" the terminal disconnected issue you are seeing.  Just like the UART port doesn't care if the terminal program at the other end is connected or not, the USBUART interface will continue without the while() hangup.

Here is a link to the "Code Sharing" forum thread with the component code.

Terminal-Support-Component-Library 

Enjoy!

Len
"Engineering is an Art. The Art of Compromise."

many thanks! exactly what I needed!

0 Likes