DIGIT-ARC read-only archive · snapshot: July 23, 2026

Programming serial port

6 posts · originally from https://geek.digit.in/community/threads/programming-serial-port.16283/

bizzare_blue
bizzare_blue Original post #1
Oct 1, 2005 at 3:01 AM
How can I program the serial port?? I m well versed with C/C++....
bizzare_blue
Oct 3, 2005 at 12:05 AM
Port

Actually, I want to get a signal from the port where a device may b attatched.....How can I do this?


Also, I wanted 2 know bt Remote Interfacing....
ramprasad
Oct 3, 2005 at 4:54 PM
hi..

This is absolutely possible....
I have done it....
but currently , I dont remember anything, will let u know in a few days....

Regards,
Ramprasad
I
Oct 3, 2005 at 5:25 PM
quoting directly from my c++ compiler.....

DOS.h


þ inport reads a word from a hardware port
þ inportb reads a byte from a hardware port
þ outport outputs a word to a hardware port
þ outportb outputs a byte to a hardware port

Declaration:
þ int inport(int portid);
þ unsigned char inportb(int portid);
þ void outport(int portid, int value);
þ void outportb(int portid, unsigned char value);

Remarks:
þ inport works just like the 80x86 instruction IN. It reads the low
byte of a word from portid, the high byte from portid + 2.
þ inportb is a macro that reads a byte
þ outport works just like the 80x86 instruction OUT. It writes the
low byte of value to portid, the high byte to portid + 1.
þ outportb is a macro that writes value

Argument³ What It Is

portid ³ Inport port that inport and inportb read from;
³ outport port that outport and outportb write to
value ³ Word that outport writes to portid;
³ byte that outportb writes to portid.

If you call inportb or outportb when DOS.H has been included, they are
treated as macros that expand to inline code.

If you don't include DOS.H, or if you do include DOS.H and #undef the
macro(s), you get the function(s) of the same name.

Return Value:
þ inport and inportb return the value read
þ outport and outportb do not return


Name Address IRQ
COM 1 3F8 4
COM 2 2F8 3
COM 3 3E8 4
COM 4 2E8 3

does this help you?
sujithtom
Oct 4, 2005 at 7:28 AM
I heard (but i am not sure) that in Windows u can treat ports as files and write and read data from them. Try to open it in binary mode.
ramprasad
Oct 4, 2005 at 6:17 PM
Hi..

dheeraj_kumar is right...
For more examples check the Help in Turbo C


Regards,
Ramprasad