Hi, I have written a C program in Turbo C to load BITMAP image and now i am trying to send it over serial port. Kindly Help me how to send that image data which i already loaded in memory over serial port using OUTPORTB or BIOSCOM ?
#include <stdio.h>
#include <stdlib.h>
#include <mem.h>
#include <conio.h>
#include <dos.h>
#define COM1 0x3F8
typedef unsigned short word;
typedef unsigned char byte;
typedef unsigned long dword;
typedef struct tagBITMAP /* the structure for a bitmap. */
{
word width;
word height;
byte *data;
} BITMAP;
void fskip(FILE *fp, int num_bytes)
{
int i;
for (i=0; i<num_bytes; i++)
fgetc(fp);
}
void load_bmp(char *file,BITMAP *b)
{
FILE *fp;
long index;
word num_colors;
int x;
/* open the file */
if ((fp = fopen(file,"rb")) == NULL)
{
printf("Error opening file %s.\n",file);
exit(1);
}
/* check to see if it is a valid bitmap file */
if (fgetc(fp)!='B' || fgetc(fp)!='M')
{
fclose(fp);
printf("%s is not a bitmap file.\n",file);
exit(1);
}
/* read in the width and height of the image, and the
number of colors used; ignore the rest */
fskip(fp,16);
fread(&b->width, sizeof(word), 1, fp);
fskip(fp,2);
fread(&b->height,sizeof(word), 1, fp);
fskip(fp,22);
fread(&num_colors,sizeof(word), 1, fp);
fskip(fp,6);
/* assume we are working with an 8-bit file */
if (num_colors==0) num_colors=256;
/* try to allocate memory */
if ((b->data = (byte *) malloc((word)(b->width*b->height))) == NULL)
{
fclose(fp);
printf("Error allocating memory for file %s.\n",file);
exit(1);
}
fskip(fp,num_colors*4);
/* read the bitmap */
for(index=(b->height-1)*b->width;index>=0;index-=b->width)
for(x=0;x<b->width;x++)
b->data[(word)index+x]=(byte)fgetc(fp);
fclose(fp);
}
void main (void)
{
BITMAP bmp;
char data;
clrscr();
load_bmp("arrow.bmp",&bmp);
/*outportb(COM1, data); How to send Image data over serial port
which is already loaded in memory */
free(bmp.data);
getch();
}