07-09-2017 08:24 AM
i found the function ComRd() in manual.
int ComRd(int PortNumber,char buff[],size_t count)
my question is :
if the amount of characters in the input queue of the port is less than "count" specified in ComRd(),then how many
characters finally be read into buff[]?
Solved! Go to Solution.
07-09-2017 08:43 AM
Such a case could happen if a timeout or error occurs. Hence you should always check the number of bytes read which is the return value of the function. The manual also gives an example :
n = ComRd (1, buf, 100);
if (n != 100)
/* Timeout or error occurred before read completed. */;
07-09-2017 09:19 AM
if i set SetComTime(port,0) to disable timeout.
ComRd(port,buff,8)
and at the first time, MCU send "abcde"(five characters) to PC, i found nothing displayed on PC;
then MCU send "fghjk" to PC, i found "abcdefgh" displayed on PC;
then MCU send "opqrs" to PC, i found nothing displayed on PC;
then MCU send "tuvwx" to PC, i found "jkopqrst" displayed on PC,
and so on.
if i set SetComTime(port,0) to disable timeout.
ComRd(port,buff,2)
and at the first time, MCU send "abcde"(five characters) to PC, i found "ab$Hxhcd$Hxh" displayed on PC;
then MCU send "fghjk" to PC, i found "ef$Hxhgh$Hxhjk$Hxh" displayed on PC;
then MCU send "opqrs" to PC, i found "op$Hxhqr$Hxh" displayed on PC;
then MCU send "tuvwx" to PC, i found "st$Hxhuv$Hxhwx$Hxh" displayed on PC,
and so on.
why??