Solved

Serial Port  Communications

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
TFS Branching 4 71
Having Trouble with MS Access 2010 CommandBars 19 91
Where to obtain Oracle Data Provider for .NET 3.5 7 47
Need more details 5 124
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…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and 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…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

911 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

26 Experts available now in Live!

Get 1:1 Help Now