Also:
Source Code:
#include <windows.h>
#include <stdio.h>
int main(int argc,char** argv)
{
DCB dcb;
COMMTIMEOUTS CTO;
COMMCONFIG CC;
ZeroMemory (&dcb, sizeof(dcb));
HANDLE hFile = NULL;
hFile = CreateFile("COM1",GENERIC_READ|GENERIC_WRITE,0,0,OPEN_EXISTING,0,NULL);
if(hFile == NULL)
{
MessageBox(0,"Error CreateFile","Test",MB_OK);
}
if(!GetCommState(hFile, &dcb))
{
MessageBox(0,"Error GetCommState","Test",MB_OK);
}
dcb.DCBlength = sizeof(DCB);
dcb.BaudRate = CBR_19200;
dcb.ByteSize = (BYTE)8;
dcb.StopBits = (BYTE)2;
dcb.fBinary = TRUE;
dcb.fParity = FALSE;
dcb.fOutxCtsFlow = FALSE;
dcb.fOutxDsrFlow = FALSE;
dcb.fDtrControl = DTR_CONTROL_ENABLE;
dcb.fDsrSensitivity = FALSE;
dcb.fTXContinueOnXoff = TRUE;
dcb.fOutX = FALSE;
dcb.fInX = FALSE;
dcb.fErrorChar = FALSE;
dcb.fNull = FALSE;
dcb.fRtsControl = RTS_CONTROL_DISABLE;
dcb.fAbortOnError = FALSE;
dcb.wReserved = 0;
CTO.ReadIntervalTimeout = 500;
CTO.ReadTotalTimeoutConstant = 500;
CTO.ReadTotalTimeoutMultiplier = 500;
CTO.WriteTotalTimeoutConstant = 500;
CTO.WriteTotalTimeoutMultiplier = 500;
if(!SetCommTimeouts(hFile,&CTO))
{
MessageBox(0,"Error CommTimeouts","Test",MB_OK);
}
if(!SetCommState(hFile,&dcb))
{
DWORD error = GetLastError();
char cerr[64];
char cerr2[16];
itoa((int)error,cerr2,10);
strcpy(cerr,"Error SetCommState: ");
strcat(cerr,cerr2);
MessageBox(0,cerr,"Test",MB_OK);
}
if(!SetDefaultCommConfig("COM1",&CC,sizeof(CC)))
{
MessageBox(0,"Error SetDefaultCommConfig","Test",MB_OK);
}
if(hFile == INVALID_HANDLE_VALUE)
MessageBox(0, "Fehler 1", "", 0);
char helper[6];
// sprintf(helper,"%c%d%c%c%c",27,1,80,13,10);
strcpy(helper,"\27");
strcat(helper,"\3F8");
strcat(helper,"V");
strcat(helper,"\13");
strcat(helper,"\10");
int written;
WriteFile(hFile,&helper,strlen(helper),(LPDWORD)&written,NULL);
DWORD dlength = 0;
char sBuffer[1024];
do
{
ReadFile(hFile,&sBuffer,25,&dlength,NULL);
printf("%s %d\n",sBuffer,dlength);
}
while(dlength);
char c;
scanf("%c",&c);
return 0;
}
Ausgabe:
1
0
0
0
0
0
0
0
0
usw.