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

x
?
Solved

Serial Port  Communications

Posted on 1998-01-29
4
Medium Priority
?
230 Views
Last Modified: 2013-12-03
I have a program that I want to dial a number, however when I run the program nothing happens.Please tell me whats wrong with this code.
#include<windows.h>
#include<windowsx.h>
#include<iostream.h>
void main()
{
      DCB *dcb;
char jess[31]="ATDP 169";
char *jesse=jess;
int dummy;
HANDLE hComm;
hComm = CreateFile( "COM2",  
                    GENERIC_READ | GENERIC_WRITE,      
                              0,
                    0,
                              OPEN_EXISTING,
                    FILE_FLAG_WRITE_THROUGH,
                    0);
cout<<"Handle to Com2 opened!\n";
cout<<"Dialing test!\n";
GetCommState(hComm,dcb);
SetCommState(hComm,dcb);
WriteFile(hComm,jesse,strlen(jesse),0,NULL);
cin>>dummy;
CloseHandle(hComm);
cout<<"Closed!";
}
0
Comment
Question by:laeuchli
  • 2
4 Comments
 
LVL 7

Accepted Solution

by:
galkin earned 40 total points
ID: 1410604
Lok at documentation of WriteFile. This is extract from there "...If lpOverlapped is NULL, lpNumberOfBytesWritten cannot be NULL...". Forth and the fifth parameters cannot be NULL together.
Besides strlen returns string length EXCLUDING '\0' character so correct string length is strlen() + 1.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1410605
Although the rest of your answer is surely right, I'm not sure why you are suggesting there might be a problem with the string length.  There is a problem only if he wants to send the NUL character and this is unlikely.
0
 
LVL 3

Expert Comment

by:stefanr
ID: 1410606
How about adding a '\r' to the dial string, i.e.
char jess[31]="ATDP 169\r";

/Stefan
0
 
LVL 3

Expert Comment

by:stefanr
ID: 1410607
...and (oops!) change
DCB *dcb;
to
DCB dcb;
and
GetCommState(hComm,dcb);
to
GetCommState(hComm,&dcb);
and similar to SetCommState.
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

824 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