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
Post a Comment