Here we go:
#include <stdio.h>
#include <ctype.h>
#include <windows.h>
void SetTimeOut(HANDLE Port, int sec)
{
COMMTIMEOUTS commtimeouts;
GetCommTimeouts(Port, &commtimeouts);
commtimeouts.ReadIntervalTimeout = 1000*sec;
commtimeouts.ReadTotalTimeoutMultiplier = 10;
commtimeouts.ReadTotalTimeoutConstant = 1000*sec;
SetCommTimeouts(Port, &commtimeouts);
}
int main(void)
{
DCB dcb;
HANDLE ComPort = CreateFile("COM1", GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
if(ComPort == INVALID_HANDLE_VALUE)
{
printf("Failed to open port!\\nHit enter to exit");
getchar();
}
GetCommState(ComPort, &dcb);
dcb.BaudRate = 9600;
dcb.ByteSize = 8;
dcb.fRtsControl = RTS_CONTROL_HANDSHAKE;
dcb.fOutxCtsFlow = 1;
SetCommState(ComPort, &dcb);
SetTimeOut(ComPort, 1);
while(1)
{
unsigned char Buffer[128];
DWORD Length, i;
ReadFile(ComPort, Buffer, 128, &Length, 0);
for(i = 0; i < Length; i++)
{
printf("%2X %3d %c", Buffer[ i ], Buffer[ i ], isprint(Buffer[ i ]) ? Buffer[ i ] : '.');
}
}
CloseHandle(ComPort);
return 0;
}
[Redigeret d. 05/08-05 20:45:52 af Bertel Brander]
Sorry men den registrer helder ingen tastetryk fra min remotcontroller... Hvad kan det være jeg gør galt.....?
SkypeR That\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'s ME
----------------------------------------------
%49%66%20%79%6F%75%27%76%65%20%74%72%61%
6E%73%6C%61%74%65%64%20%
74%68%69%73%2C%20%79%6F%75%20%6D%75%73%
74%20%62%65%20%62% 6F%72%65%64%2E%2E%2E