Скачиваний:
34
Добавлен:
15.09.2014
Размер:
1.35 Кб
Скачать
#include <windows.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream> 

#define PORT "COM2"

int Read(HANDLE H, char &c)
{
	DWORD Byte;
	if(!ReadFile(H, &c, 1,&Byte,0))
		{
			puts("Error read");
			_getch();
			return 0;
		
		}
	return 1;
}


int Write(HANDLE H,char c)
{
	DWORD Byte;
	if(!WriteFile(H, &c, 1, &Byte, NULL))
	{
			puts("Error write");
			_getch();
			return 0;
		
	}
	return 1;
}





int main()
{
	HANDLE handle;                

	handle = CreateFileA(PORT,GENERIC_READ | GENERIC_WRITE,0,0,OPEN_EXISTING,0,NULL);

	if(handle == INVALID_HANDLE_VALUE)
	{
		puts("Error1");
		_getch();
		return 0;
	}

	char c;

	while(1)
	{
		
		
		if(Read(handle,c))
		{
			int i;	
		}
		else
			return 0;
		if(c=='1'||c=='2')
			break;
	}
	system("cls");
	int flag=0;
	if(c=='1')
		flag=1;




	puts("Vivod: \n");
	char *ms;
	ms=(char*)calloc(5,sizeof(char));//с отчиской
	ms[5]='\n';
	while(1)
	{	
			if(Read(handle,c))
			{
				ms[0]=ms[1];
				ms[1]=ms[2];
				ms[2]=ms[3];
				ms[3]=c;
				if(c==13)
					printf("\n");
				else
					printf("%c",c);
				if(!strcmp(ms,"exit"))
				{
					
					break;
				}

				if(flag==1)
					if(!Write(handle,c))
						return 0;
			}
	
	}
	return 0;
}
Соседние файлы в папке Солодуха