GIDForums  

Go Back   GIDForums > Computer Programming Forums > MS Visual C++ / MFC Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 12-Jan-2009, 06:46
roidrage666 roidrage666 is offline
New Member
 
Join Date: Jan 2009
Posts: 7
roidrage666 is on a distinguished road

Serial com for modem / CSerialPort


Hi there. I ve begun to write a small app in MFC so I can send/receive SMS / Calls without using any terminal.

I'm using CSerialPort 1.27
and I just have written down a few lines in this way

CPP / C++ / C Code:
port->Open(1, 9600, CSerialPort::NoParity, 8,CSerialPort::OneStopBit, CSerialPort::NoFlowControl);

	char *sBuf ="AT" + char(13);
 
	port->Write(sBuf, strlen(sBuf)); 

 char *sBuf1 ="ATD <mob. number>" + char(13) ;
 
	port->Write(sBuf1, strlen(sBuf1)); 


just to test it.

It doesn't work, and given my recent bitter experiance with serial coms in .net, I begin to get paranoid..

Please any help would be very helpful, thanks in advance.
Last edited by LuciWiz : 12-Jan-2009 at 07:12. Reason: Please insert your C++ code between [cpp] & [/cpp] tags
  #2  
Old 12-Jan-2009, 08:54
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,200
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: serial com for modem / CSerialPort


Quote:
Originally Posted by roidrage666
CPP / C++ / C Code:
	char *sBuf ="AT" + char(13);
 
That's invalid code.

To create a string literal, you can use \xcc to embed the hexadecimal value of a char.

For example, the hex value of decimal 13 is 0x0d, so you could have
CPP / C++ / C Code:
    char *sBuf = "AT\x0d";

To embed certain C (and C++) special chars such as \r, you can just use the special char designation inside the quotes

The intent of the following is more clear (to me, at least), and I don't have to depend on future code maintainers having memorized the hexadecimal value for ASCII carriage-return, so I would recommend something like:
CPP / C++ / C Code:
    char *sBuf1 ="ATD <mob. number>\r";

Here's a reference to my second example: Constants

Here's a standard C++ test program (no MFC stuff or any other non-Standard library classes):
CPP / C++ / C Code:
#include <iostream>

using namespace std;

int main()
{
    char *sBuf = "AT\x0d";
    char *sBuf1 ="ATD <mob. number>\r";

    cout << "sBuf: " << endl << " ";
    for (int i = 0; sBuf[i]; i++){ 
        if (isprint(sBuf[i])) {
            cout << "'" << sBuf[i] << "',";
        }
        else  {
            cout << "<" << int(sBuf[i]) << "> ";
        }
    }
    cout << endl << endl;
    cout << "sBuf1:" << endl << " ";
    for (int i = 0; sBuf1[i]; i++){ 
        if (isprint(sBuf1[i])) {
            cout << "'" << sBuf1[i] << "',";
        }
        else  {
            cout << "<" << int(sBuf1[i]) << "> ";
        }
    }
    cout << endl;
    return 0;
}

Printing chars (separated by commas) are shown between single quote marks and decimal values of non-printing chars are shown between angle brackets:
Code:
sBuf: 'A','T',<13> sBuf1: 'A','T','D',' ','<','m','o','b','.',' ','n','u','m','b','e','r','>',<13>

Regards,

Dave
Last edited by davekw7x : 12-Jan-2009 at 09:26.
  #3  
Old 13-Jan-2009, 02:44
roidrage666 roidrage666 is offline
New Member
 
Join Date: Jan 2009
Posts: 7
roidrage666 is on a distinguished road

Re: serial com for modem / CSerialPort


really, this couldn't be more helpful, Dave...

Thanks man, all works fine now
 
 

Recent GIDBlogOnce again, no time for hobbies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Hard drive/CPU Diagnoses Issues binarybug Computer Hardware Forum 1 22-Jan-2007 20:23
Serial Port Communication a3.charles C Programming Language 0 04-Aug-2006 00:42
receive X10 signals with w800rf32a serial soldstatic C++ Forum 0 06-Jul-2006 14:44
Problem to read on a serial port collinm C Programming Language 2 30-Mar-2005 02:42
Serial Port communication in C or C++ dmkst56 C++ Forum 0 23-Mar-2005 21:18

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 22:24.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.