Solved

sending bytes to the serial port

Posted on 2000-03-04
4
387 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
sorting efficency of sorting algorithm 30 104
Problem with SqlConnection 4 160
Microsoft C++ code failing in executable that worked 9 86
VS2015 Redefinition errors 4 30
The article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
In this article, you will read about the trends across the human resources departments for the upcoming year. Some of them include improving employee experience, adopting new technologies, using HR software to its full extent, and integrating artifi…
Viewers will learn how to use the Hootsuite Dashboard.
The viewer will learn how to successfully download and install the SARDU utility on Windows 8, without downloading adware.

863 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

24 Experts available now in Live!

Get 1:1 Help Now