Скачиваний:
35
Добавлен:
15.09.2014
Размер:
814 б
Скачать
#include "Com_Port.h"
#include <conio.h>

int main()
{
	int port = 1;
	int rate = 57600;

	SerialGate sg; // 

	char buf[20];
	int dwBytesRead = 0;
	bool terminate  = false;

	bool res = sg.Open(port, rate);
	if(res == false)
	{
		printf("Open Error..\n");
		getch();
		return 0;
	}
	else
	{
		printf("Open OK!..\n");
	}

	printf("Press key to send it to COM port.\n");
	printf("Press '#' to exit.\n\n");

	while(true)
	{
		char c = getch();
		printf("%c", c);

		sg.Send(&c, sizeof(c));

		if(c == '#')
		{	
			sg.Close();
			exit(0);
		}

		Sleep(10);
		dwBytesRead = sg.Recv(buf, sizeof(buf));		

		for(int i = 0; i < dwBytesRead; i++)
		{
			printf("%c", buf[i]);
			if(buf[i] == '#')
			{
				terminate = true;
				break;
			}
		}



	}	
	return 0;
}