Solved

Serial Port  Communications

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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

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…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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…

832 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