Solved

Serial Port  Communications

Posted on 1998-01-29
4
204 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 10 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

760 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

22 Experts available now in Live!

Get 1:1 Help Now