Thread: how to send ASCII to modem?

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    23

    how to send ASCII to modem?

    does anyone know how i could send ascii to terminate my moderm?
    i want to hard code <ctrl-Z> and i have found the ASCII of Ctrl-z, but how could i write this ASCII to the modem socket?

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Are you using socket to communicate with the modem? How?

    In most cases - you open a com port for this purpose...
    You can then write to the port as if it is file
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    23
    fd= open(MODEM_DEV, PARAMS);

    i am connecting to gsm modem
    so basically i write to fd, but how i could send ascii number as ascii number and not string?
    any command or function that i need to use?

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    string is just a sequence of ACSII numbers...
    So just make a sequence of one character and write it
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #5
    Registered User
    Join Date
    Nov 2006
    Posts
    23
    i am actually writing AT commands to gsm, like the following
    write (fd, "AT+CMGS =\"+60125649001\"\r\nhello\n" ,40);
    and i need <ctrl-z> to send out the message. however i need to hardcode this <ctrl-z>, if i wrote the ascii 01A, the program will treat 01A as part of the message, so how should i send this 01A to terminate the modem?

  6. #6
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    I dunno... try something like
    Code:
    /* This assumes buffer is large enough to accommodate the following */
    strcpy(buffer,"AT+CMGS =\"+60125649001\"\r\nhello\n");
    buffer[strlen(buffer) + 1] = '\0';
    buffer[strlen(buffer)] = (char)0x1A;
    
    write(fd, buffer, strlen(buffer) + 1);
    Sent from my iPad®

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Read the manual which comes with your modem perhaps?

    Or maybe since you're using linux (I guess), then see if there is an ioctl() command to cause and end of file to be sent to the modem.

    Or search the web for "AT commands".
    From memory, there's something about sending "+++" to cause the modem to revert from data mode back into command mode.

    Are you sure you don't mean
    "ATZ"
    As a command, rather than <ctrl-z> as a character?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  8. #8
    Registered User
    Join Date
    Nov 2006
    Posts
    23
    thanks thanks... i've got it to work!!!
    i need a <ctrl-z> to send the message out

  9. #9
    Registered User
    Join Date
    Nov 2006
    Posts
    23
    i have get the modem to sms out, but some coding that i not really understand why after i off the modem n reset it, the 1st command that i sent through will not be responsed?
    strcpy(buffer, "AT+CMGS =\"25649001\"\r\nhello\n");
    buffer[strlen(buffer)+1] = '\0';
    buffer[strlen(buffer)] =(char)0x1A;
    unless i add read () before the above code. anyone know why?
    write (fd, buffer, strlen(buffer)+1);

  10. #10
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Make sure the whole buffer was sent successfully.
    Sent from my iPad®

  11. #11
    Registered User
    Join Date
    Nov 2006
    Posts
    23
    bzero (buffer, sizeof(buffer));
    read(fd, buffer, sizeof(buffer));
    strcpy(buffer, "AT+CMGS =\"+60125649001\"\r\nhello\n");
    buffer[strlen(buffer)+1] = '\0';
    buffer[strlen(buffer)] =(char)0x1A;
    write (fd, buffer, strlen(buffer)+1);
    wait();

    this is how the code looks like. the whole buffer was sent. But the problem comes each time i reset the modem. the function read above supposingly does nothing, but without read() while i reset the modem it seems couldnt get reply (perhaps it didnt send out the message for the 1st time).

  12. #12
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Are you reopening your connection to your modem again? You probably have to. You are in effect, when you tell your modem to reset, shutting it off and turning it back on. You should have to open again.


    Quzah.
    Hope is the first step on the road to disappointment.

  13. #13
    Registered User OnionKnight's Avatar
    Join Date
    Jan 2005
    Posts
    555
    strcpy(buffer, "AT+CMGS =\"+60125649001\"\r\nhello\n");
    buffer[strlen(buffer)+1] = '\0';
    buffer[strlen(buffer)] =(char)0x1A;
    --->
    strcpy(buffer, "AT+CMGS =\"+60125649001\"\r\nhello\n\x1A");

  14. #14
    Registered User
    Join Date
    Nov 2006
    Posts
    23
    it works properly now. i guess i need to set the serial port each time i reset the modem or restart the pc.
    thanks everyone

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. tuncated uint8_t
    By Coens in forum C Programming
    Replies: 14
    Last Post: 11-24-2008, 07:57 AM
  2. sending n no of char data uning send() function,
    By thebrighter in forum Windows Programming
    Replies: 1
    Last Post: 08-22-2007, 12:26 PM
  3. Replies: 11
    Last Post: 03-24-2006, 11:26 AM
  4. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  5. LISP (DrScheme) any one?
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 03-31-2004, 12:52 PM