Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

sending bytes to the serial port

Posted on 2000-03-04
4
Medium Priority
?
417 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 100 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Have you ever run into that annoying problem where the computer won't boot?  Wouldn't it be great if you had a tool that would make that disk boot again?  I have found one tool that works more often than not ...
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

927 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