Solved

sending bytes to the serial port

Posted on 2000-03-04
4
384 Views
Last Modified: 2013-11-15
hi,
i am trying to send some bytes to serial port and was wondering if there was any function in c++ to do that. i looked in the help files and tried using outport. this is the exact copy of the code in the help files which i tried to use
#include <conio.h>
#include <stdio.h>
int main(void)
{
   int port = 0;
   int value = 'C';

   outport(port, value);
   printf("Value %d sent to port number %d\n", value, port);
   return 0;
}

but it doesn't work. says undefined function outport. is there some other header file that i need to include or can someone suggest some other function? also, i may want to use c++ builder so can someone suggest some vcl components that i can download that would help me do the same thing?

thanks in advance.
0
Comment
Question by:twilight_prince
  • 2
4 Comments
 

Accepted Solution

by:
sunraj earned 50 total points
ID: 2582873
hi prince,

If you are are working on Win32 environment then following answer will difinitely help.

Use the following function first to create a handle to the file (Comm port),

HANDLE h_comm1;
DCB dcb1;

h_comm1 CreateFile("COMM1",.......);
if (h_comm1 == NULL)
    exit(0);

/* set the dcb values such as baud rate,
   stop bit, data bit etc...*/
WriteFile(h_comm1......);

if u are working on win32 environment, then let me know so that i could send u the complete working code.


regards
0
 

Author Comment

by:twilight_prince
ID: 2583897
yes, i am using windows 98 which counts as a win32 environment doesn't it?
0
 

Author Comment

by:twilight_prince
ID: 2583911
acutally i am starting to get more interested in builder as well so if u ( or someone) can point me to a place with some well documented VCL components to do this, that would be much appreciated
0
 

Expert Comment

by:thiel
ID: 2631993
#define COM1BASE 0x3F8
#define COM2BASE 0x2F8
#define TXDATA COM1BASE
#define LCR (COM1BASE+3)  /* 0x3FB line control */
#define LSR (COM1BASE+5)  /* 0x3FD line status  */

#include <conio.h>  /* required for getch(), inp() and outp() */


void Setup_Serial(void)
{
      _outp(LCR,0x80);
      /* set up bit 7 to 1 to set Register address bit */

      _outp(TXDATA,0x30);
      _outp(TXDATA+1,0x00);
      /* load TXRegister with 2400 bauds*/

      _outp(LCR,0x03);
      /* parity */
}


void Send_Character(int ch)
{
      char status;

      do
      {
            status = _inp(LSR) & 0x40;
      } while (status !=0x40);
      /* repeat until Tx buffer empty ie bit 6 set */

      _outpw(TXDATA,(char) ch);
}


int Get_Character(void)
{
      int status;

      do
      {
            status = _inp(LSR) & 0x01;
      } while (status !=0x01);
      /* Repeat until bit 1 in LSR is set */

      return((int) _inp(TXDATA));
}
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Video by: Tony
This video teaches viewers how to export a project from Adobe Premiere Pro and the various file types involved.
An overview on how to enroll an hourly employee into the employee database and how to give them access into the clock in terminal.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now