0

I'm trying to send a SMS using AT command and I need to execute "Ctrl + Z" action after writing the message content.

I tried using the "x1A" and "u001A" but they're not working.

Here is the code that I'm using:

"AT+CMGS=\"$phoneNumber\"\r\n$message\\x1A"

To add more information I'm trying to automate the procedure of sending SMS in quectel modem:

AT+CMGS=[,] text is specified <Ctrl+Z/ESC>

I want to send "Ctrl+Z" by command not pressing the keys.

alejandro
  • 21
  • 3
  • What are you trying to do.. Undo the message? With what you posted it's unclear of what your trying to do. Add more code so we can see the bigger picture and explain what your trying to do – Camp Nerd Dec 06 '22 at 16:37
  • I know the commands I am just trying to figure how your calling the end text portion... There is not enough code to go on – Camp Nerd Dec 06 '22 at 16:42
  • this is usually what's used, but you said that did not work, correct? – Camp Nerd Dec 06 '22 at 16:50
  • What I need is a one line command to do the "Ctrl+z" action by not pressing the keys. – alejandro Dec 07 '22 at 07:14
  • the first thing logically would be to set up and invoke the keyboard key like you would do in c#. However, when it comes to the Android keyboard that’s a whole different ball game. I don’t know the keycodes for the android keyboard. If you find the keycodes for android keyboard you could possibly simulate the key combo. But this is what I have found docs wise.. https://www.developershome.com/sms/cmgsCommand.asp it explains the entire setup maybe you can decipher it – Camp Nerd Dec 07 '22 at 11:38

1 Answers1

1

Strictly answering your question, the function for concatenating CTRL+Z character to the AT command string is toChar():

var testString = "test" + 0x1A.toChar()

Anyway this will not work because the AT command you are using is not correct.

+CMGS command, in text mode, only the destination number is passed as a parameter. The message has to be sent after the prompt > is received from the modem. So:

  1. Make sure to switch to text mode (default is PDU mode)

     AT+CMGF=1
    
  2. Send +CMGS command and wait for the prompt

     AT+CMGS=xxxyyyzzz
     >
    
  3. Send the actual message appending the text terminator as explained above

Design your program accordingly.

Roberto Caboni
  • 7,252
  • 10
  • 25
  • 39
  • 1
    Spot on answer. For details/reasoning why waiting for the prompt before sending the payload is important, see the first part of [this answer](https://stackoverflow.com/a/15591673/23118). – hlovdal Dec 18 '22 at 22:55