C++ Serielle Schnittstelle einbinden
-
Hi
ich habe ein Problem mit dem Öffnen der seriellen Schnittstelle. programmiere auf Visual Studio 2005. soll ne win32 Konsolen Anwendung werden für nen projekt an der fh, also ganz einfach.
egal welche COM-Schnittstelle ich auswähle, es würd immer gesagt das der Port nicht geöffnet werden
Hier mal nen teil des Codes den ich zum öffnen der COM schnittstelle nutze:bool CCOMPort::Init(int iPort, int iBaud, int iSize, int iParity, int stopbit, int fRtsControl, int iTimeout, int iTotalTimeout) { CString strPort(""); strPort.Format(_T("COM%d"), iPort); // iPort = 2 m_hPort = CreateFile( strPort, // Pointer to the name of the port GENERIC_READ | GENERIC_WRITE, // Access (read-write) mode 0, // Share mode NULL, // Pointer to the security attribute OPEN_EXISTING, // How to open the serial port FILE_ATTRIBUTE_NORMAL, // Port attributes NULL); // Handle to port with attribute to copy if((int)this->m_hPort == -1) // wenn COM? nicht vorhanden (-1) this->m_hPort=0; if(this->m_hPort !=0)
wenn einer nen fehler sieht und berichtigt wäre das nett!!
-
Was sagt GetLastError() nach CreateFile(...)??
Probier mal als Portname: "\\\.\\COM1"
("COM1" ist nämlich nur ein Shortcut.)Edit: Möchtest Du dein Port Handle nicht auf INVALID_HANDLE_VALUE testen?
(Wäre generischer als -1.)Edit2: Schau hier: http://www.c-plusplus.net/forum/viewtopic-var-p-is-84212.html
Simon
-
hi danke für die hilfe das mit den portname scheint es schon gewesen zu sein, funzt jetzt super danke
mfg dk