When you right click on your UART component you will see an option "find code example".
There is an API GetBufferSize() which reports how many bytes already received, use GetByte() API only when the value has been > 0.
Enter into a loop until you have got your values.
You can adopt the code from these examples for PSoC 4
(receiving/sending command string from terminal)
And similar for UDB mode