Solved

sending bytes to the serial port

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What is the cheapest way to learn Websphere MQ? 2 91
Free software for pdf to word conversion 4 56
Problem with SqlConnection 4 170
What is sub-make ? 2 61
A high-level exploration of how our ever-increasing access to information has changed the way we do our jobs.
If your app took Google’s lash recently, here are the 5 most likely reasons.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
XMind Plus helps organize all details/aspects of any project from large to small in an orderly and concise manner. If you are working on a complex project, use this micro tutorial to show you how to make a basic flow chart. The software is free when…

823 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