0

Please have a look at the following code:

#pragma once
using namespace System::IO::Ports;
using namespace System::Text::RegularExpressions;
using namespace System::Collections::Generic;

    ref class SMS
    {
    public:
        SMS(void);
        void sendMessage();

    private:
        System::IO::Ports::SerialPort ^port;
    };

And the cpp file

#include "StdAfx.h"
#include "SMS.h"


SMS::SMS(void)
{
    //Initialize the Serial Port
    port = gcnew System::IO::Ports::SerialPort();
    port->PortName = "COM12";
    port->BaudRate = 9600;
    port->Parity = Parity::None;
    port->DataBits = 8;
    port->StopBits = StopBits::One;
    port->Handshake = Handshake::RequestToSend;
    port->DtrEnable = true;
    port->RtsEnable = true;
    port->NewLine = System::Environment::NewLine;

    if(!port->IsOpen)
    {
        port->Open();
    }

    //Set message format
    port->WriteLine("AT+CMGF=1");

    //Turn off echo
    port->WriteLine("ATE0");

    //Set memory configurations
    port->WriteLine("AT+CPMS=\"ME\",\"ME\",\"ME\"");





}


//This method will send the SMS

void SMS::sendMessage()
{
    if(!port->IsOpen)
    {
        port->Open();
    }

    port->WriteLine("AT+CMGS=\"012121212\"");
    port->WriteLine("Test Message From C#");
    port->WriteLine(System::Convert::ToString((char)(26)));

    port->Close();


}

I am trying to send SMS by accessing the dongle. The port is correct and the dongle also fine because it responded to my friend's code few hours back. What am I doing wrong here? Have I done anything incorrect with C++/CLI ? AT Commands?

halfer
  • 19,824
  • 17
  • 99
  • 186
PeakGen
  • 21,894
  • 86
  • 261
  • 463

2 Answers2

0

try adding "CR" "LF" (Carriage Return and Line Feed characters) after each AT command, some GSM dongles (like SIM900) needem in order to work. I hope this helps Regards

0

if for win32,.. prefer using

HFILE OpenFile( LPCSTR lpFileName, // pointer to filename LPOFSTRUCT lpReOpenBuff, // pointer to buffer for file information
UINT uStyle // action and attributes );

with other events,...

if using SMS gateway with modem AT command capability, that's fine for direct read and write to COM port if U using cell phone, many of this will not work. example nokia 6070, 3100 model group

best test it using hyperterminal.

I used CBuildre6 for

https://sites.google.com/site/xpressdms/rosegarden

cheer.