LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

question about ComRd()

Solved!
Go to solution

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[]?

0 Kudos
Message 1 of 3
(2,971 Views)
Solution
Accepted by winter1970

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 Smiley Wink:

n = ComRd (1, buf, 100);
if (n != 100)

/* Timeout or error occurred before read completed. */;

0 Kudos
Message 2 of 3
(2,962 Views)

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??

0 Kudos
Message 3 of 3
(2,949 Views)