Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Accessing serial port in Windows 2000 using C

Status
Not open for further replies.

champnim

Junior Member level 2
Joined
Sep 9, 2006
Messages
22
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,489
settings for baud rate of 115200 in turbo c

I want to know how to access serial port in Windows 2000 using C...I was using Turbo C and I tried ouptortb but it did not work
 

turboc c++ serial port

I understand, that you're trying to access serial port hardware from a 16-Bit DOS application. Basically Windows 2000 operating system doesn't allow direct hardware access for applications. Windows 2000 has limited support for legacy DOS software by virtualizing COM port hardware, so such applications may still work. I have Borland Pascal applications with Com Port usage, and they basically work even with a FTDI USB adapter installed as COM1.

Your way of operating the COM port may be incompatible with virtualization. But as my last activities in this field have been at least 10 years ago, I can't give you any hints. I suggest to use e. g. C-Builder or any other 32-Bit compiler and build a 32-Bit console application. It would access the COM port through Windows API which is much faster than virtualization and allows full control of all parameters. Examples should be available with most compilers.

Another option, that may be still supported (altough I never tried it) is accessing COM ports through INT14h fossil BIOS interface. But I think, the only plausible reason to use INT14 or COM port direct access would be when making an application that should work in a plain DOS enviroment.
 

reading a serial port using windows

How about using C# to design a GUI interfacing PIC and PC. Anyone know?
 

pascal acces ports in windows

I had done the C program using turboC but unable to recollect. Need to dig out the program from some old CD. But not sure if it is dependent on WINDOWS OS version.
 

win 2000 com port direct access

ckshivaram said:
I had done the C program using turboC but unable to recollect. Need to dig out the program from some old CD. But not sure if it is dependent on WINDOWS OS version.

Can u pls post ur code or how you went about it
 

serial port communication using c

#include <dos.h>
#include <stdio.h>
#include <conio.h>

#define PORT1 0x3F8

/* Defines Serial Ports Base Address */
/* COM1 0x3F8 */
/* COM2 0x2F8 */
/* COM3 0x3E8 */
/* COM4 0x2E8 */

void main(void)
{
int c;
int ch;
outportb(PORT1 + 1 , 0); /* Turn off interrupts - Port1 */

/* PORT 1 - Communication Settings */

outportb(PORT1 + 3 , 0x80); /* SET DLAB ON */
outportb(PORT1 + 0 , 0x03); /* Set Baud rate - Divisor Latch Low Byte */
/* Default 0x03 = 38,400 BPS */
/* 0x01 = 115,200 BPS */
/* 0x02 = 57,600 BPS */
/* 0x06 = 19,200 BPS */
/* 0x0C = 9,600 BPS */
/* 0x18 = 4,800 BPS */
/* 0x30 = 2,400 BPS */
outportb(PORT1 + 1 , 0x00); /* Set Baud rate - Divisor Latch High Byte */
outportb(PORT1 + 3 , 0x03); /* 8 Bits, No Parity, 1 Stop Bit */
outportb(PORT1 + 2 , 0xC7); /* FIFO Control Register */
outportb(PORT1 + 4 , 0x0B); /* Turn on DTR, RTS, and OUT2 */

printf("\nSample Comm's Program. Press ESC to quit \n");

do { c = inportb(PORT1 + 5); /* Check to see if char has been */
/* received. */
if (c & 1) {ch = inportb(PORT1); /* If so, then get Char */
printf("%c",ch);} /* Print Char to Screen */

if (kbhit()){ch = getch(); /* If key pressed, get Char */
outportb(PORT1, ch);} /* Send Char to Serial Port */

} while (ch !=27); /* Quit when ESC (ASC 27) is pressed */
}


This will read a char from the terminal and send it com port. Also it will receive the same char and print it on the terminal.



Try to configure hyper terminal to verify.


all the best
 
serial port programming in c outportb

ATD is commands for modem.
I suppose you can type the command and at the end issue escape. But your modem checks for CR and LF. Some modem are configured for taking (CTRL+Z) as terminating characters.

change the program I gave to you by replacing esc with (0x0a and 0x0d)(CR and LF), or take ASCII of ctrl Z. then send the commands to the modem using the serial port. then read the response from the modem.

thanks and regards
shivaram
 
+windows 2000 +direct +serial port

Im nt able 2 understand wat ur tryin to say...Im doin the following
printf("\nSample Comm's Program. Press ESC to quit \n");

outportb(PORT1,'A');
outportb(PORT1,'T');
outportb(PORT1,'\r');
do { c = inportb(PORT1 + 5); /* Check to see if char has been */
/* received. */
if (c & 1) {ch = inportb(PORT1); /* If so, then get Char */
printf("%c",ch);} /* Print Char to Screen */

if (kbhit()){ch = getch();} /* If key pressed, get Char */
//outportb(PORT1, ch);} /* Send Char to Serial Port */
} while (ch !=027); /* Quit when ESC (ASC 27) is pressed */

Now here how do send the entire 'AT\r' in one outportb line. Also at the moment Im getting a reply of 'OK' from the modem but my program is not exiting...what shud i do fr tht?
Thanx in advance
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top