0

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();
}
4
Contributors
3
Replies
21
Views
6 Years
Discussion Span
Last Post by rubberman
0

download the ATENUSB to serial bridge driver.Install it on your PC.After this you check in HardwareManager/Device MAnager ur serial port is been detected.Now to communicate you require Console which is capable for doing your needs.Some consoles are Termite,Putty,Minicom

0

it is better to use inpout32.dll for x86 architecture (from logix4u) and use other advance IDE (like codeblocks, dev c++, eclipse) they are best than turbo c .

Edited by ikhan521: something mistake

0

Simplest? Use fopen() w/ binary write flag on the device name (COM1, COM2, etc), and then simply write the data to the file descriptor. I leave the actual coding to you as an exercise.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.