- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!
Solved! Go to Solution.
- Labels:
-
PSOC5 LP MCU
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!
"Engineering is an Art. The Art of Compromise."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!
"Engineering is an Art. The Art of Compromise."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
many thanks! exactly what I needed!