N
Edit: Ich sehe gerade das das viel zu umständlich ist das mit den WinAPI Threads zu machen da ja Qt (worauf mein main Programm hauptsächlich basiert) eine eigene Klasse für Threads implementiert..
-------------------------------------------------------------------------------
tag hätte da kurz mal ne frage noch irgendwie haut das bei mir noch nicht so hin...
hier mal mein Code vielleicht findet ja jemand von euch den fehler oder kann mir sagen wo ich falsch gedacht hab..
DCB dcb;
unsigned long threadId;
struct setting
{
char baud[10];
char data[2];
char stop[2];
char port[5];
char con[40];
};
setting settingdat;
strncpy(settingdat.con,"",39);
ifstream quelle("connection.dat",ios::in);
quelle.getline(settingdat.baud,sizeof(settingdat.baud));
quelle.getline(settingdat.data,sizeof(settingdat.data));
quelle.getline(settingdat.stop,sizeof(settingdat.stop));
quelle.getline(settingdat.port,sizeof(settingdat.port));
quelle.close();
hComm = CreateFile(settingdat.port,GENERIC_READ | GENERIC_WRITE,0,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
if (hComm == INVALID_HANDLE_VALUE)
{
Error err("error opening port.");
err.exec();
}
FillMemory(&dcb, sizeof(dcb), 0);
dcb.DCBlength = sizeof(dcb);
strncat(settingdat.con,settingdat.baud,sizeof(settingdat.baud)-1);
strncat(settingdat.con,",",1);
strncat(settingdat.con,"n",1);
strncat(settingdat.con,",",1);
strncat(settingdat.con,settingdat.data,sizeof(settingdat.baud)-1);
strncat(settingdat.con,",",1);
strncat(settingdat.con,settingdat.stop,sizeof(settingdat.baud)-1);
if (!BuildCommDCB(settingdat.con, &dcb))
{
Error err("Couldn't build the DCB. Usually a problem with the communications specification string.");
err.exec();
return FALSE;
}
else
{
dcb.fRtsControl = RTS_CONTROL_DISABLE;
dcb.fDtrControl = DTR_CONTROL_DISABLE;
// Set new state.
if (!SetCommState(hComm, &dcb))
{
Error err("Error in SetCommState. Possibly a problem with the communications port handle or a problem with the DCB structure itself.");
err.exec();
}
}
threading = true;
HANDLE hThread = CreateThread(NULL,0,this->pi_read,1,0, &threadId);
return TRUE;
void *Port_Interface::pi_read(LPVOID lpvoid)
{
while(threading)
{
ReadFile(hComm,&lpBuf,1, &dwBytesRead,&ov);
WaitForSingleObject(hComm,INFINITE);
GetOverlappedResult(hComm,NULL,&dwBytesRead,FALSE);
}
}
Leider bekomme ich bein Compelieren beim initialisieren des Threads einen Fehler mit der Funktion und ich weiß leider nicht wieso
Kann mir da von euch jemand sagen was ich falsch mach?
wäre nett
gruß
Dominik