Hi,
Im using this code to address my ComPort:
Code:
#pragma hdrstop
#include <condefs.h>
#pragma argsused
#include <iostream.h>
#include <stdio.h>
#include <windows.h>
int main()
{
HANDLE HdComm;
DWORD DwError;
DCB Dcb;
unsigned char Msg[128], Data;
//int RealNum;
DWORD RealNum;
Data='a';
// Open the COMM port.
HdComm = CreateFile( "COM1", GENERIC_READ | GENERIC_WRITE, 0,
NULL, OPEN_EXISTING, 0, NULL );
if ( HdComm == INVALID_HANDLE_VALUE /*cmaryus*/ ) // If COMM port can't be opened, then ...
{
DwError = GetLastError(); // Display error code, and abort.
FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, 0, DwError, 0, (char *)Msg, 124, 0 );
printf( "Cannot Open Port COM1 !\nError Code: %d, - %s.\n", DwError, Msg );
return 1;
}
// Initialize COMM port.
SetupComm( HdComm, 1024, 1024 );
GetCommState( HdComm, &Dcb );
Dcb.BaudRate = BAUD_9600;
Dcb.Parity = NOPARITY;
Dcb.ByteSize = 8;
Dcb.StopBits = ONESTOPBIT;
SetCommState( HdComm, &Dcb );
//cout<<Data;
do {
// ReadFile( HdComm, &Data, 1, &RealNum, NULL ); //Recieve the char from COM1
WriteFile( HdComm, &Data, 1, &RealNum, NULL ); //Write the recieved data to COM1
printf( "%02x ", Data ); //Display the data
} while( Data != 0x1b ); // Loop until the data is ESC
CloseHandle( HdComm );
return 0;
}
When I check the Com1Port with the other PC`s Hyperterminal I don`t get the a, I get squares.
I´m trying to send to a 8051 µP , and would like to know what the ComPort sbuf really puts out.
What do I have to send for Data and what does the Sbuf turn out?
Thanks
Johannes