Solved

sending bytes to the serial port

Posted on 2000-03-04
4
407 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

If your app took Google’s lash recently, here are the 5 most likely reasons.
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

631 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