4

Problems:

  1. I am able to use hyperterminal to send SMS via COM9. All good.
  2. But I cannot properly use AT commands in matlab to do the same thing. I even cannot pass the first "AT" step. The error I received is "Unexpected Error: Unexpected Error: An error occurred during writing." It seems coming from fprintf. Help!

Here is the codes:

try
    s = serial('COM9','BaudRate',9600); 
    fopen(s);
    tx='AT';  
    tx1=char(13);
    tx2=char(10);
    fprintf(s, '%s', sprintf('%s%s%s', tx, tx1, tx2));
    out = fscanf(s);
    disp(out);
    fclose(s); 
catch aException
    fclose(s);
    error(message('MATLAB:serial:fprintf:opfailed', aException.message));
  • 1
    Have you tried running the code with `dbstop if caught error` (or `dbstop if error`)? Please indicate at what line the error occuers exactly. – Dennis Jaheruddin Jul 24 '13 at 11:04

1 Answers1

1

You have done the serial communication part properly. In AT command set, to check the working of the device it's enough if you send 'AT' and a line feed. Also you gave both carriage return and line feed to the device simultaneously. That could create a problem. Also while writing MATLAB code for the first time, try sending the characters individually as you do in Hyperterminal. It will solve your problem.

There will be no problem from MATLAB's perspective when the communication link is created successfully.

Steven
  • 1,365
  • 2
  • 13
  • 28
Anand
  • 693
  • 1
  • 8
  • 26