Hello all,
I am trying to write a program that will capture a string sent from winxp via serial port and recieve onto win98. I have used outportb and turboC++ (5.0) to get this and have had some success but I am only receiving approx 16 characters and I need approx 40 characters to make it useful.
Please bear with me as my coding is as a working user rather than from a developer standpoint so much of the code has been copied from other projects.
Brief desciprion - The program loops several times and pulls data from the buffer until a # character is encountered. Data is stored into a string variable stringRead and after gathering data the string is displayed via a printf statement. When the program is run on xp it displays all characters but when the same program is run on win98 I am only seeing about 16 characters. Is this a feature of the differences between the two OS's or have I made some programmatical error?
Here is the code:-
/* This program is used to pull data from the serial port */
#include <dos.h>
#include <stdio.h>
#include <conio.h>
#define PORT1 0x3F8 /* Defines Serial Port Base Address (COM1 */
#define MAXSIZE 80
void main(void)
{
unsigned char c = 0;
unsigned char chrctr = 0;
unsigned char stringRead[MAXSIZE] = "\nawaiting data\n";
int i,j;
clrscr();
outportb(PORT1 + 1, 0); /* Turn off interrupts */
/* PORT1 Communication Settings */
outportb(PORT1 + 3, 0x80); /* Set DLAB ON */
outportb(PORT1 + 0, 0x30); /* Set the baud rate to 19200 */
outportb(PORT1 + 1, 0x00); /* Set Baud - Divisor latch HIGH */
outportb(PORT1 + 3, 0x03); /* 8 bits, no parity, 1 stop */
outportb(PORT1 + 2, 0xC7); /* FIFO Control Register */
outportb(PORT1 + 4, 0x0B); /* Turn on DTR, RTS, and OUT2) */
for(i=0;i<5;i++)
{
c = inportb(PORT1 + 5);
chrctr = inportb(PORT1);
j = 0;
while(c & 0x01) /*if data is available*/
{
if(chrctr != '#') /*if character isn't a hash symbol*/
{
chrctr = inportb(PORT1);
delay(100);
stringRead[j] = chrctr;
delay(100);
j++;
/*printf("%c",chrctr);*/
}
/*printf("%s", stringRead);*/
c=inportb(PORT1 + 5);
}
delay(100);
printf("\n%s\n", stringRead);
delay(3000);
}
}
I am trying to write a program that will capture a string sent from winxp via serial port and recieve onto win98. I have used outportb and turboC++ (5.0) to get this and have had some success but I am only receiving approx 16 characters and I need approx 40 characters to make it useful.
Please bear with me as my coding is as a working user rather than from a developer standpoint so much of the code has been copied from other projects.
Brief desciprion - The program loops several times and pulls data from the buffer until a # character is encountered. Data is stored into a string variable stringRead and after gathering data the string is displayed via a printf statement. When the program is run on xp it displays all characters but when the same program is run on win98 I am only seeing about 16 characters. Is this a feature of the differences between the two OS's or have I made some programmatical error?
Here is the code:-
/* This program is used to pull data from the serial port */
#include <dos.h>
#include <stdio.h>
#include <conio.h>
#define PORT1 0x3F8 /* Defines Serial Port Base Address (COM1 */
#define MAXSIZE 80
void main(void)
{
unsigned char c = 0;
unsigned char chrctr = 0;
unsigned char stringRead[MAXSIZE] = "\nawaiting data\n";
int i,j;
clrscr();
outportb(PORT1 + 1, 0); /* Turn off interrupts */
/* PORT1 Communication Settings */
outportb(PORT1 + 3, 0x80); /* Set DLAB ON */
outportb(PORT1 + 0, 0x30); /* Set the baud rate to 19200 */
outportb(PORT1 + 1, 0x00); /* Set Baud - Divisor latch HIGH */
outportb(PORT1 + 3, 0x03); /* 8 bits, no parity, 1 stop */
outportb(PORT1 + 2, 0xC7); /* FIFO Control Register */
outportb(PORT1 + 4, 0x0B); /* Turn on DTR, RTS, and OUT2) */
for(i=0;i<5;i++)
{
c = inportb(PORT1 + 5);
chrctr = inportb(PORT1);
j = 0;
while(c & 0x01) /*if data is available*/
{
if(chrctr != '#') /*if character isn't a hash symbol*/
{
chrctr = inportb(PORT1);
delay(100);
stringRead[j] = chrctr;
delay(100);
j++;
/*printf("%c",chrctr);*/
}
/*printf("%s", stringRead);*/
c=inportb(PORT1 + 5);
}
delay(100);
printf("\n%s\n", stringRead);
delay(3000);
}
}