В этот раз чисто поржать, не думаю, что этим всерьёз кто-то воспользуется.
#include <iostream.h>
#include <conio.h>
#include <process.h>
#include <stdio.h>
#include <fstream.h>
#include <windows.h>
HANDLE hCom;
HDC hDC;
int InitCom(const char *Comm, int Baud)
{
DCB dcb;
COMMTIMEOUTS TO;
BOOL fSuccess;
hCom = CreateFile(Comm, GENERIC_READ | GENERIC_WRITE,
0, // comm devices must be opened w/exclusive-access
NULL, // no security attrs
OPEN_EXISTING, // comm devices must use OPEN_EXISTING
0, // not overlapped I/O
NULL); // hTemplate must be NULL for comm devices
if (hCom == INVALID_HANDLE_VALUE) return 0;
GetCommState(hCom,&dcb);
dcb.BaudRate = Baud;
dcb.ByteSize = 8;
dcb.Parity = NOPARITY;
dcb.StopBits = ONESTOPBIT;
fSuccess = SetCommState( hCom, &dcb);
if(!fSuccess) return 0;
PurgeComm(hCom,PURGE_TXCLEAR|PURGE_RXCLEAR);
GetCommTimeouts( hCom,&TO);
TO.ReadIntervalTimeout=MAXDWORD; //This magic combiantion means "return received data only";
TO.ReadTotalTimeoutMultiplier=0;
TO.ReadTotalTimeoutConstant=0;
SetCommTimeouts( hCom,&TO);
return 1;
}
int Pos=0;
int Val=0;
#define HSIZE 800
#define VSIZE 600
BOOL UpdatePixel (char Pixel)
{
if (!Pixel || Pos==HSIZE) Val=Pos=0; //sorta null-term
else if (Pixel&0x80)
{
if (Val)
{
int Y = (Val&0x7F)+(Pixel&0x7F)*128;
Val=0;
Y=min(Y,VSIZE-1);
SetPixel (hDC, Pos, Y, 0xFFFFFF);
if (Y>0) SetPixel (hDC, Pos, Y-1, 0x808080);
if (Y<VSIZE-1) SetPixel (hDC, Pos, Y+1, 0x808080);
Pos++;
} else Val=Pixel;
} else return TRUE;
return FALSE;
}
void main (int argc, char *argv[])
{
char i,o,name[]="COM1";
unsigned long ret;
int speed=115200;
SetConsoleTitle ("NickDoom's GraphTerm");
Sleep (100);
hDC=GetDC(FindWindow (NULL, "NickDoom's GraphTerm"));
if (argc == 2) speed = atoi (argv[1]);
for (name[3]='9';name[3]>'0';name[3]--) if (InitCom (name, speed))
{
cout<<"COMM Port found on "<<name<<endl;
break;
}
for (;;)
{
if (kbhit())
{
i=getch();
WriteFile(hCom,&i,1,&ret,NULL);
}
ReadFile(hCom,&o,1,&ret,NULL);
if (ret) if (UpdatePixel(o)) cout<<o;
flushall();
}
ReleaseDC(0,hDC);
}
-
- классика минимализма, красиво написано - Mahagam(11.02.2016 22:31)