PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

ReadFile

i have problem with "ReadFile". i want to read 2 bytes (short Byte), but it failes.

Code:
// Loop for waiting for the data.
do
{
// Read the data from the serial port.
ReadFile (m_hCom, Byte, 1, &dwBytesTransferred;, 0);

if (dwBytesTransferred == 2)
{
//do something
}
} while (dwBytesTransferred < 2);
Here we go again... (there was a thread here recently about reading from the serial port).

You're telling it to only read one byte:

ReadFile (m_hCom, Byte, 1, &dwBytesTransferred, 0);

and dwBytesTransferred is filled for each read - it's not cumulative, so you're making an infinite loop...

(dwBytesTransferred will always be one because you're only asking for one).

Addendum:
http://forums.pocketmatrix.com/viewtopic.php?t=10086