I am trying to send and recieve data by using rs232 port.For this i hav even written a program in C language using _bios_serial com,but the problem i am facing is that this command is unable to send the data.
Just for testing the port i hav shorted pins 2&3 together so that whatever be the data is transmitted by a PC it will be recieved back.
I hav even tried commands like outp,inp etc. but all of dem didnt work.
Plz reply me as soon as possible.
Following is my program to transmitt a char '*' at RS232 port nd recieves the same nd display it.This program doesnot indicate any syntax error but hav may hav any logical error :

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<bios.h>



void main(void)
{                   clrscr();
	 unsigned com1_status;
	 unsigned com1_send;
	 unsigned com1_rec;
	 unsigned com1_init;
	 int result, mask;



	 com1_init = _bios_serialcom(_COM_INIT, 0,
		  _COM_CHR8 | _COM_NOPARITY | _COM_STOP1 | _COM_1200);

	 printf("Init status: 0x%4.4X\n", com1_init);


	 com1_send = _bios_serialcom(_COM_SEND, 0, '*');

	 printf("Send status: 0x%4.4X\n", com1_send);

	 mask = 0x6100;

	 
	 printf("%0X\n",42);
	 com1_status = _bios_serialcom(_COM_STATUS, 0, 0);

	 printf("COM1 status: 0x%4.4X\n", com1_status);

	 /* wait until a character is ready */

  do {

		  com1_status = _bios_serialcom(_COM_STATUS, 0, 0);


		  com1_status = com1_status & 0xFF00;
		  if(kbhit())
		  { if(getch()==26)
				break;
		  }

	 } while( (mask & com1_status) == 0);

	 /* get a character */

	 com1_rec =  _bios_serialcom(_COM_RECEIVE, 0, 0);

	 printf("Read status: 0x%4.4X\n", com1_rec);

	 /* print the character we just received */

	 result = com1_rec & 0x00FF;

	 printf("Character: 0x%2.2X  =  %c\n", result, (char)result);
  getch();
}

<< moderator edit: added code tags: [code][/code] >>

Recommended Answers

All 2 Replies

What OS are you on? What compiler are you using? If you are on true DOS this was accomplished using interrupt routines. Google for ralf browns interrupt list and there should be some info in there. If you are on windows using a window or a console then check MSDN for the documentation on CreateFile(). For *nix I aint got a clue.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.