Solved

Serial Communication for null modem

Posted on 2000-02-13
2
327 Views
Last Modified: 2010-04-10
I need some help... or even better codes (written in visual C++) to transmit and receive data from the serial port using NULL MODEM to communicate between two computers.

I've tried using the _outp and _inp method but it doesn't work in MFC
application.

Please Help!!! Thanks
0
Comment
Question by:oCEAN
[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
2 Comments
 

Accepted Solution

by:
mathewboorman earned 50 total points
ID: 2517614
Null Modem - it does not matter what device it is, you need to use the file IO API.

A simple case would use:
CreateFile using file name "COMM1" to use default serial settings.
ReadFile() to receive data
WriteFile() to send data


Here is a Microsoft example of setting up the comms from MSDN.

DCB dcb;
HANDLE hCom;
DWORD dwError;
BOOL fSuccess;

hCom = CreateFile( "COM1",
    GENERIC_READ | GENERIC_WRITE,
    0,    // comm devices must be opened w/exclusive-access
    NULL, // no security attributes
    OPEN_EXISTING, // comm devices must use OPEN_EXISTING
    0,    // not overlapped I/O
    NULL  // hTemplate must be NULL for comm devices
    );

if (hCom == INVALID_HANDLE_VALUE)
{
    dwError = GetLastError();

    // handle error
}

// Omit the call to SetupComm to use the default queue sizes.
// Get the current configuration.

fSuccess = GetCommState(hCom, &dcb);

if (!fSuccess)
{
    // Handle the error.
}

// Fill in the DCB: baud=9600, 8 data bits, no parity, 1 stop bit.

dcb.BaudRate = 9600;
dcb.ByteSize = 8;
dcb.Parity = NOPARITY;
dcb.StopBits = ONESTOPBIT;

fSuccess = SetCommState(hCom, &dcb);

if (!fSuccess)
{
    // Handle the error.
}


0
 

Expert Comment

by:mathewboorman
ID: 2517621
BTW _inp and _outp are talking about hardware level IO to internal devices such as disk (and communications) controllers.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

726 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