I have the following code, which compiles me as is. The problem is that I do not understand why he does not receive me or send data from one computer to another. I would also like to know why I can not configure the speed of the data, I have tried but I do not understand what the error is.
#include "stdafx.h"
#include "windows.h"
#include "conio.h"
int main()
{
char envio[100] = {};
char recibe[100] = {};
char tamaño;
DWORD Bescrito = 1, Brecibido=1;
HANDLE dato = CreateFile(L"COM3",
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL);
//DCB config_;
//if (GetCommState(dato, &config_) == 0)
//{
// //AfxMessageBox("Get configuration port has problem.");
// printf("Puerto Error");
// return Bescrito;
//}
//// Assign user parameter.
//config_.BaudRate = 115200; // Specify buad rate of communicaiton.
//config_.StopBits = 1; // Specify stopbit of communication.
//config_.Parity = 0; // Specify parity of communication.
//config_.ByteSize = 8; // Specify byte of size of communication.
//if (SetCommState(dato, &config_) == 0)
//{
// printf("Configuracion Puerto frito");
//}
if (dato != 0) {
int op;
printf("puerto abierto");
op = _getch();
do
{
//escriura
printf("\nescriba: ");
scanf_s("%s", envio, 100);
tamaño = strlen(envio);
WriteFile(dato, envio, tamaño, &Bescrito, NULL);
Sleep(2);
//lectura
printf("\nleyendo: \n");
do {
ReadFile(dato, recibe, 1, &Brecibido, NULL);
if (Brecibido == 1)
{
printf("%s", recibe[0]);
}
} while (!_kbhit());
_getch();
}while (op != 27);
}
else if (dato==0)
{
printf("error de apertura.");
_getch();
}
CloseHandle;
return 0;
}