Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Serial command???? 1

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Who could let me know which are the right command to communicate using a serial port???

Thanks a lottttt
 
There used to be some functions named inportb, inpw, outportb, and outpw but they are no longer supported and won't work with NT-based OS's like NT, 2000, ect. You're best bet is getting a third party component or treat the port like you would a file. By treating it like a file, you would use iostreams or CreateFile on the com port of your choice. Somthing like,
Code:
std::ofstream OFile; // stream set up
//OFile.open("Label.dat");      // For Testing
//OFile.open("LPT1:"); // LPT port
OFile.open("COM1:"); // COM 1 port
James P. Cottingham

I am the Unknown lead by the Unknowing.
I have done so much with so little
for so long that I am now qualified
to do anything with nothing.
 
And what happens then ? does the data stay buffered until you read from the com or lpt on the connected computer?
(just out of curiousity :))
Greetz,

The Muppeteer.

themuppeteer@hotmail.com

Don't eat yellow snow...
 
As far as the LPT port, yes, I don't know about the COM port since I've never used it but I suspect that it is, too.

Just looking at my example, I realized that I didn't supply any method of changing the IO speed, bits, stop bits, etc. I did find an example for CreateFile.
Code:
DCB dcb;
HANDLE hCom;
DWORD dwError;
BOOL fSuccess;

hCom = CreateFile("COM1",
    GENERIC_READ | GENERIC_WRITE,
    0,    /* comm devices must be opened w/exclusive-access */
    NULL, /* no security attrs */
    OPEN_EXISTING, /* comm devices must use OPEN_EXISTING */
    0,    /* not overlapped I/O */
    NULL  /* hTemplate must be NULL for comm devices */
    );

if (hCom == INVALID_HANDLE_VALUE) {
    dwError = GetLastError();

    /* handle error */
}

/*
 * Omit the call to SetupComm to use the default queue sizes.
 * Get the current configuration.
 */

fSuccess = GetCommState(hCom, &dcb);

if (!fSuccess) {
    /* Handle the error. *
}

/* Fill in the DCB: baud=9600, 8 data bits, no parity, 1 stop bit. */

dcb.BaudRate = 9600;
dcb.ByteSize = 8;
dcb.Parity = NOPARITY;
dcb.StopBits = ONESTOPBIT;

fSuccess = SetCommState(hCom, &dcb);

if (!fSuccess) {
    /* Handle the error. *
}
This came from BCB's MS SDK help file. (alphabet soup) :) James P. Cottingham

I am the Unknown lead by the Unknowing.
I have done so much with so little
for so long that I am now qualified
to do anything with nothing.
 
It is part of the Windows API. My help files say the library is kernel32.lib and the header is winbase.h . Depending on how you are compiling you may already be including the library.
James P. Cottingham

I am the Unknown lead by the Unknowing.
I have done so much with so little
for so long that I am now qualified
to do anything with nothing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top