Solved

Serial Communication for null modem

Posted on 2000-02-13
2
324 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
  • 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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…

757 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

18 Experts available now in Live!

Get 1:1 Help Now