Вот код для отправляющей программы:
#include<iostream>
#include<conio.h>
#include <stdio.h>
#include<windows.h>
using namespace std;
int t[4];
HANDLE hPort;
LPCTSTR sPortName;
DCB dDCB;
int buffer;
DWORD RealRead;
DWORD RealWrite;
DWORD dw = 0;
void getTime()
{
SYSTEMTIME sm;
GetLocalTime(&sm);
t[0] = sm.wHour;
t[1] = sm.wMinute;
t[2] = sm.wSecond;
t[3] = sm.wMilliseconds;
}
void choosePort()
{
char n;
int a=0;
cout<<"Please, enter the numder of Com-port!"<<endl;
cout<<"Com1 - pressed (1)"<<endl;
cout<<"Com2 - pressed (2)"<<endl;
cout<<"Com3 - pressed (3)"<<endl;
cout<<"Com4 - pressed (4)"<<endl;
while(a == 0)
{
cin>>n;
if (n == '1')
{
cout<<"Com1 is active!"<<endl;
sPortName = "com1";
a = 1;
}
else if (n == '2')
{
cout<<"Com2 is active!"<<endl;
sPortName = "com2";
a = 1;
}
else if (n == '3')
{
cout<<"Com3 is active!"<<endl;
sPortName = "com3";
a = 1;
}
else if (n == '4')
{
cout<<"Com4 is active!"<<endl;
sPortName = "com4";
a = 1;
}
else
{
cout<<"Try agian, man!"<<endl;
a = 0;
}
}
}
int main()
{
choosePort();
hPort = CreateFile(
LPCTSTR (sPortName),
GENERIC_READ or GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
0);
dDCB.DCBlength = sizeof(LPDCB);
GetCommState(
hPort,
&dDCB);
dDCB.BaudRate = CBR_115200;
dDCB.ByteSize = 8;
dDCB.Parity = EVENPARITY;
dDCB.StopBits = 2;
SetCommState(
hPort,
&dDCB);
getTime();
while(dw =! 3)
{
buffer = t[dw];
WriteFile(
hPort,
buffer,
1,
&RealWrite,
NULL);
inc dw;
}
closeHandle(hPort);
getch();
}
?
p.s. Есть ли какие-нибудь дельные наработки по программированию com'а на с/с++?