how to send an SMS message through GSM using Mat lab software
조회 수: 8 (최근 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
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
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
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 Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!