Write File Probleme

maksi

Grünschnabel
Hallo,
ich bekomme bald die Krise und zwar hab ich ein Win CE 5
und möchte auf COM1 auf den PC schreiben aber nix nur
der Cursor blinkt wild rum.
Vielleicht kann mir einer von Euch helfen hier der CODE:

///////////////////////////////////////////////
Funktion zum Schreiben auf die Com Schnittstelle
static int Rs232SendBlk(HANDLE hPort,LPSTR lpcData,int nSize)
{
int nLen = 0;
DWORD dwWrite;

Rs232SetLastError(ERROR_SUCCESS);

while ( ( nLen < nSize ) && !l_bRs232ReqAbort )
{
if ( !WriteFile(hPort,lpcData+nLen,nSize-nLen,&dwWrite,0) )
{

#ifdef DEBUG_FAILURES
{
TCHAR szMsg[MAX_PATH];
TEXTSPRINTF(szMsg,TEXT("!!Rs232SendBlk: WriteFile error = %.8X"),l_dwLastError);
OutputDebugString(szMsg);
}
#endif

dwWrite = 0;
}

if ( dwWrite == 0 )
{
break;
}

nLen += dwWrite;
}

return(nLen);
}
///////////////////////////////////////////////////////
Comport öffnen
static Rs232Open(void)
{
DCB PortDCB;
HANDLE hPort;

BOOL bReady = FALSE;

COMMTIMEOUTS CommTimeouts;
DWORD dwResult;

PortDCB.DCBlength = sizeof(DCB);




hPort = CreateFile(TEXT("COM1:"),
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL);

if ( hPort == INVALID_HANDLE_VALUE )
{

printf("ERROR");

return(NULL);
}


SetupComm(hPort,INQUEUESIZE,OUTQUEUESIZE);
GetCommState(hPort,&PortDCB);

PortDCB.BaudRate = 115000;
PortDCB.fDtrControl = DTR_CONTROL_DISABLE;
PortDCB.ByteSize = 8;
PortDCB.Parity = NOPARITY;
PortDCB.StopBits = ONESTOPBIT;


SetCommState(hPort,&PortDCB);




dwResult = GetCommTimeouts(hPort,&CommTimeouts);

CommTimeouts.ReadIntervalTimeout = MAXDWORD;
CommTimeouts.ReadTotalTimeoutMultiplier = 0;
CommTimeouts.ReadTotalTimeoutConstant = 0;

CommTimeouts.WriteTotalTimeoutMultiplier = 0;
CommTimeouts.WriteTotalTimeoutConstant = 3000;

dwResult = SetCommTimeouts(hPort,&CommTimeouts);

return hPort;



}


//////////////////////////////////////////
////////////Aufruf/////////////////////
globale Variablen
HANDLE x_hPort;



x_hPort=Rs232Open();
rec=XFER_ACK;
Rs232SendBlk(x_hPort,&rec,1);


/////////////////////////////////////////
Definitive wird die Write Funktion ausgeführt und es gibt kein Error bei öffnen des Ports

:(
 
Hallo,

bitte editiere deinen Beitrag und setzt deinen Sourcecode zwischen [code=cpp] ... [/code]

Das Öffnen des Ports sollte so erfolgen:
C++:
hPort = CreateFile(TEXT("COM1"), ... );
also ohne den Doppelpunkt am Ende.

Gruß
MCoder
 
Zurück