visual c++ - incomplete reading data serial port -


i want read 6 data sensors arduino vc++ "handshaking" methods, send "1" arduino device send data pc. data format is: &data0,data1,data2,data3,data4,data5%

but when read vc++ data incomplete, thought size of buffer enough data

here snapshot of vc++ program, put on timer event

    dword nbytes;     char buffer[24];      //read sensors      if(!writefile( hnd_serial, "1", 1, &nbytes, null )){killtimer(ctimer1);messagebox(l"write com port fail!");return;}     sleep(5);     if(!readfile( hnd_serial, buffer, 23, &nbytes, null )){killtimer(ctimer1);messagebox(l"read com port fail!");return;}     sleep(50); 

i have changed baud rate result still same. if reduce 1 data such data5 (become 5 sensors), data complete. have wrong program?

you can put readfile() function inside do-while loop.

do{     if(!readfile( hnd_serial, buffer, 23, &nbytes, null )){         //process error         break;     }     if (nbytes>= 6)     {         //put flag - or process here         break;     } }while(nbytes); 

the readfile() returns current buffer status, not wait receiving full of expected data


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -