Ahojte, pisem program v Boland C++ a posielanie dat na port vzdy zlyha. Neviem, co robim zle, a taktiez neviem, ako zistim, ze preco to vzdy zlyha. Vyhodnocujem len navratovu hodnotu funkcie WriteFile, ktora je BOOL, cize o tom, aka chyba nastala, mi nepovie. Posielaju sa tieto chyby niekam na standartdny chybovy vystup?Ako ho zobrazim? Alebo ich musim hladat niekde inde? Pouzivam Builder C++ 0.0.4.212.
Ukazka kodu:
HANDLE hCOM=CreateFile("COM3", GENERIC_WRITE|GENERIC_READ, 0,NULL,OPEN_EXISTING,
FILE_FLAG_OVERLAPPED,NULL);
if (hCOM!=INVALID_HANDLE_VALUE)
{
Label2->Caption="Open Successfull";
DWORD dwBytesRead ;
DWORD numbytes, numbytes_ok, temp;
COMSTAT ComState;
OVERLAPPED Overlap;
char buf_in[6] = "Hello!";
numbytes = 6;
ClearCommError(hCOM, &temp, &ComState); // if temp is not null, the port is in the error state
if(temp) Label2->Caption="Port is in error state";
else if (!temp){
Label2->Caption="Port is OK";
if( WriteFile(hCOM, buf_in, numbytes, &numbytes_ok, NULL)==FALSE)
Label3->Caption="Write Failed";
}
CloseHandle(hCOM);
}
else
{
Label2->Caption="Error Open";
}
Kde moze byt problem? Vopred dakujem.
Borland C++ zapis dat na COM port
priznam sa necital som to cele ale pomoc by si mohol najst tu
http://www.kar.elf.stuba.sk/predmety/ap/blok3.php
http://www.kar.elf.stuba.sk/predmety/ap/blok3.php