AlexG (21.11.2015 16:36, просмотров: 385) ответил Николай Коровин на OpenWatcom, а на что ватерклозет пожаловался?
Там целая пачка сообщений была - и хидеры он найти не смог, и cout тоже, и char* ему не подходит. После правки чтобы не было ругани исходник выглядит так: #include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <process.h>
#include <stdio.h>
#include <fstream>
#include <windows.h>
using std::cout;
using std::cin;
using std::endl;
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;
#define HSIZE 320
void UpdatePixel(char Pixel)
{
if (!Pixel) Pos = 0; //sorta null-term
else if (Pixel>127)
{
SetPixel(hDC, Pos%HSIZE, Pos / HSIZE, 0xFFFFFF * (Pixel & 1));
Pos++;
SetPixel(hDC, Pos%HSIZE, Pos / HSIZE, 0xFFFFFF * (Pixel >> 1 & 1));
Pos++;
SetPixel(hDC, Pos%HSIZE, Pos / HSIZE, 0xFFFFFF * (Pixel >> 2 & 1));
Pos++;
SetPixel(hDC, Pos%HSIZE, Pos / HSIZE, 0xFFFFFF * (Pixel >> 3 & 1));
Pos++;
SetPixel(hDC, Pos%HSIZE, Pos / HSIZE, 0xFFFFFF * (Pixel >> 4 & 1));
Pos++;
SetPixel(hDC, Pos%HSIZE, Pos / HSIZE, 0xFFFFFF * (Pixel >> 5 & 1));
Pos++;
SetPixel(hDC, Pos%HSIZE, Pos / HSIZE, 0xFFFFFF * (Pixel >> 6 & 1));
Pos++;
}
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
char i, o, name[] = "COM6";
unsigned long ret;
int speed = 115200;
hDC = GetDC(0);
//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)
{
cout << o;
UpdatePixel(o);
}
_flushall();
}
ReleaseDC(0, hDC);
}
Запускается, но толку никакого - похоже не к тому порту цепляется.