• Domingo 28 de Abril de 2024, 23:07

Autor Tema:  Dudas Para Trabajar Con Puerto Serial  (Leído 1601 veces)

cesar_omar

  • Nuevo Miembro
  • *
  • Mensajes: 18
    • Ver Perfil
Dudas Para Trabajar Con Puerto Serial
« en: Jueves 10 de Febrero de 2005, 13:27 »
0
Saludos

 Estoy realizando un trabajo en c++ de puerto serial y mi sistema operativo en windows xp peor cuando corro el programa me dice que no puede abrir el puerto


 A continuacion el codigo:

#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 , 0x0C); /* Set Baud rate - Divisor Latch Low Byte */

/* Default 0x03 = 38,400 BPS */
/* 0x01 = 115,200 BPS */
/* 0x02 = 56,700 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 */


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

© Jonathan ©

  • Moderador
  • ******
  • Mensajes: 1671
  • Nacionalidad: ar
    • Ver Perfil
    • http://www.einstec.com.ar
Re: Dudas Para Trabajar Con Puerto Serial
« Respuesta #1 en: Viernes 11 de Febrero de 2005, 00:28 »
0
- Hola, si quieres hacer funcionar ese codigo tendras que olvidarte de lo facil.. en XP nada es como en windows 98, el error es de privilegios y a menos que uses apis no tendras acceso al puerto.. busca informacion sobre UserPort.sys, io.sys o cualquier driver que maneje el puerto via apis, la api es la CreateFile, investiga en google. Saludos ;)
EINSTEC Tecnología «La única fuente del conocimiento es la experiencia.»

«Lo importante es no dejar de hacerse preguntas.»