As per my understanding you need to check when the Port is open in order to receive data, meanwhile you do not want the code to be suck in the while loop so as to carry on other functionalities.
In such a case you can try setting a flag inside the an if condition such as:
You need to check for this flag before transmitting any data and transmit the data only if the flag is set to 0.
This will prevent the code from getting stuck in a loop.
Please feel free to correct me if my understanding is not clear.
Also could you provide more details about your application?
Thank you. You method works if you have implemented a non-blocking task structure.
As it turns out, I've created a routine that works in a blocking mode or non-blocking mode depending on which you select.
See this link for the solution: PSoC5LP : USBUART component detects port close
The solution uses the SysTick timer @ 1ms to detect if the host is non-responsive within less than 2ms. If non-responsive, the routine kicks out and drops the transmitted bytes just as it would if it were a true UART.