how to send an SMS message through GSM using Mat lab software

2 次查看(过去 30 天)
hi there i have already wrote the matlab code as shown below but its not working when i connect with the GSM modem. is there any one who can help me and write the correct mat lab code and i am so thank full for your kindness!!
this is the mat lab code i already write and try to test the gsm
%%%%%%%%%%%%%%%%Matlab code for sending SMS%%%%%%%%%%%%
clc;
clear all;
global BytesAvail;
global A;
global B;
tx ='AT';
tx1=char(13);
tx2=char(26);
tx3='AT+CMGS="15510961424"'; % You have to replace this with the Receiver's Phone number
tx4= ' This is a test msg '; %This is the msg body
tx5='AT+CMGF=1';
s = serial('COM6', 'BaudRate', 9600); % You have to replace this with your 3G modem's COMport number
fopen(s);
s.Terminator = 'CR';
fprintf(s,'%s', tx);
fprintf(s,'%s', tx1);
BytesAvail=s.BytesAvailable;
if(BytesAvail > 0), A=fread(s,BytesAvail,'char'); end
A;
sprintf('%c', A)
%%%%%%%%%%%%%%%Send SMS%%%%%%%%%%%%
fprintf(s,'%s', tx5);
fprintf(s,'%s', tx1);
fprintf(s,'%s', tx3);
fprintf(s,'%s', tx1);
fprintf(s,'%s', tx4);
fprintf(s,'%s', tx2);
BytesAvail=s.BytesAvailable;
if(BytesAvail > 0), B=fread(s,BytesAvail,'char'); end
B;
fclose(s)
%%%%%%%%%%%%%%%%%%%%End%%%%%%%%%%%
  1 个评论
Bhargav K Naidu
Bhargav K Naidu 2016-5-19
I am working on a similar project, my code is not working can anyone please help me over and the code used by me is :
ss=serial('COM7');
ss.baudrate=9600;
fopen(ss);
ss.Terminator = 'CR'
tx ='AT';
tx1=char(13);
tx2 ='AT+CMGF=1';
tx3 ='AT+CSCS="GSM"';
tx4 ='AT+CMGS="=+919844806008"';
tx5 ='water';
tx6=char(26);
fprintf(ss,'%s',tx);
fprintf(ss,'%s',tx1);
pause(1);
fprintf(ss,'%s',tx2);
fprintf(ss,'%s',tx1);
pause(1);
fprintf(ss,'%s',tx3);
fprintf(ss,'%s',tx1);
pause(1);
fprintf(ss,'%s',tx4);
fprintf(ss,'%s',tx1);
pause(1);
fprintf(ss,'%s',tx5);
pause(1);
fprintf(ss,'%s',tx6);

请先登录,再进行评论。

回答(1 个)

syed wasim basha
syed wasim basha 2018-3-14
编辑:syed wasim basha 2018-3-14
I too worked on the similar project,i got success by using query cmd which can write and read string to the interfacing objects. I even successfully made a call by using this code.
ob1 = instrfind('Type', 'serial', 'Port', 'COM3', 'Tag', '');
% Create the serial port object if it does not exist % otherwise use the object that was found. if isempty(ob1) ob1 = serial('COM3'); else fclose(ob1); ob1 = ob1(1); end
fopen(ob1); tx='ATD*********;'; out1 = query(ob1,tx); fclose(ob1);
i think this will help you.
  1 个评论
shweta shetty
shweta shetty 2018-3-27
I tried this but it says: "Warning: Unsuccessful read: A timeout occurred before the Terminator was reached." Can you please suggest a solution?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 MATLAB Mobile Fundamentals 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by