LPT-Problem



  • Hallo,

    ich nutze die CreateFile-funktion um auf den Druckerport zuzugreifen. Bekomme das Handel erfolgreich von Windows geliefert, aber wenn ich mit WriteFile auf den Port eine LED ansteuern will, funzt sie nicht. Angeschlossen ist alles richtig da ich mit _outp(0x378, 1) die LED zum leuchten bringen kann. Die Fehlermeldung die mir GetLastError liert ist folgende "The device is not ready" woran kann das liegen weis das vieleicht jemand ?

    Danke schon mal

    m_pCommPort->Send(1);
    int err = GetLastError();        // liefert Error-Code 21
    _outp(0x378, 1);                 // LED an
    _outp(0x378, 0);                 // LED aus
    
    BOOL CCommPort::Send(int nByte)
    {
    DWORD nf;
    
    // Daten senden
    BOOL bWriteStatus = 0;
    
    bWriteStatus = WriteFile(m_hCom, &nByte, 1, &nf, NULL);
    m_nTmpByte = nByte;
    
    if(bWriteStatus == TRUE)
     return 1;
    else
     return 0;
    }
    


  • das ist noch meine ConfigRoutine für den Port:

    BOOL CCommPort::CommConfig(int CommTimeOut)
    {
    	CString str = "COM";
    	DCB dcb;
    	COMMTIMEOUTS comtimeout;
    
    	// Schnittstelle konfigurieren
    	HANDLE handle	= CreateFile(m_strPort, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL , NULL); 
    
    	if(handle != INVALID_HANDLE_VALUE)
    	{
    		m_hCom = handle;
    		BOOL bStatus = GetCommState(m_hCom, &dcb);		// Werte des Ports holen (vorinitialisieren)
    
    		if(!bStatus)
    		{
    			// Fehlerursache abfragen
    			int error = GetLastError();
    			CString IntToStr, str;
    			IntToStr.Format("%d", error);
    			str = "Zugriff auf Kommunikationsport fehlgeschlagen. \nErrorcode: "+IntToStr+"*"+"\n\n\n* (nur wichtig für den SW-Entwickler)";
    			MessageBox(str, "Kommunikationsport Zugriffsverweigerung", MB_ICONERROR);
    		}	
    
    		else
    		{	
    				// Timeout-Zeit für Schnittstelle einstellen
    			GetCommTimeouts(m_hCom, &comtimeout);				
    			comtimeout.ReadIntervalTimeout = MAXDWORD;	
    			comtimeout.ReadTotalTimeoutConstant = CommTimeOut;		
    			comtimeout.ReadTotalTimeoutMultiplier = 10;
    			comtimeout.WriteTotalTimeoutConstant = CommTimeOut;   //1000;
    			comtimeout.WriteTotalTimeoutMultiplier = 10;
    
    			// prüfen ob die Port-Timeoutzeit erfolgreich konfiguriert wurde	
    			BOOL bSetComSt = SetCommTimeouts (m_hCom, &comtimeout);
    
    			if (!bSetComSt)
    			{
    				int error = GetLastError();
    				CString IntToStr, str;
    				IntToStr.Format("%d", error);
    				str = "Zugriff auf Kommunikationsport fehlgeschlagen. \nErrorcode: "+IntToStr;
    				MessageBox(str, "Kommunikationsport Zugriffsverweigerung", MB_ICONERROR); 
    			}
    
    			CString strTmp = m_strPort;
    			int length = strTmp.GetLength();
    			strTmp.Delete(3, length-3);
    
    			if(strTmp.Compare(str) == 0)
    			{
    				dcb.BaudRate	 = CBR_9600;
    				dcb.ByteSize	 = 8;
    				dcb.Parity				= NOPARITY;
    				dcb.StopBits	 = ONESTOPBIT;
    
    				if(BOOL bComState = SetCommState(m_hCom, &dcb) == FALSE)		// neue Werte übergeben
    				{
    					// Fehlerursache abfragen
    					int error = GetLastError();
    					CString IntToStr, str;
    					IntToStr.Format("%d", error);
    					str = "Zugriff auf COM-Port fehlgeschlagen. \nErrorcode: "+IntToStr;
    					MessageBox(str, "COM-Port Zugriffsverweigerung", MB_ICONERROR); 
    				}
    			}
    		}
    	}
    
    // Vergleich ob der HANDLE Gültigkeit aufweist
    if(m_hCom == INVALID_HANDLE_VALUE)
    	return 0;
    else
    	return 1;
    }
    

Anmelden zum Antworten