Solved

Serial Port  Communications

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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…
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…

738 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