Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2236
  • Last Modified:

ComPort component

Hi,

I wrote a programme to communicate with a GSM modem using the ComPort component (www.winsoft.sk). To send a sms I use the following code:

  ComPort->WriteString("AT+CMGF=1\xd");
  ComPort->WriteString("AT+CMGS="0790000000"\xd");
  ComPort->WriteString("Test-SMS \xd ");

I get the following error message for it:

[C++ Error] MainForm.cpp(340): E2380 Unterminated string or character constant
[C++ Error] MainForm.cpp(340): E2121 Function call missing )
[C++ Error] MainForm.cpp(340): E2379 Statement missing ;
[C++ Error] MainForm.cpp(340): E2134 Compound statement missing }

It works fine when I am using a Edit field to input the text.

What do I do wrong? Do I have to use the text different? I mean the text I would like to send. Maybe I have to transform it first!

Thanks,
Ronald
0
rsch1973
Asked:
rsch1973
  • 5
  • 4
  • 4
  • +2
1 Solution
 
AlexFMCommented:
ComPort->WriteString("AT+CMGF=1\\xd");
ComPort->WriteString("AT+CMGS="0790000000"\\xd");
ComPort->WriteString("Test-SMS \\xd ");

0
 
AlexFMCommented:
One more correction:

ComPort->WriteString("AT+CMGF=1\\xd");
ComPort->WriteString("AT+CMGS=\"0790000000\"\\xd");
ComPort->WriteString("Test-SMS \\xd ");

\ in string constant should be written as \\. " in string constant should be written as \"
0
 
SteHCommented:
Is \xd from your original message meant to be a line feed? Then it should look like \n in a string or \0x0d outside of a string.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
rsch1973Author Commented:
Thanks,

I tried it but now I get the following:

[C++ Error] MainForm.cpp(341): E2380 Unterminated string or character constant
[C++ Error] MainForm.cpp(341): E2121 Function call missing )
[C++ Error] MainForm.cpp(341): E2379 Statement missing ;
[C++ Error] MainForm.cpp(341): E2134 Compound statement missing }

Regards,
Ronald
0
 
AlexFMCommented:
What did you try exactly, please show your code. And where is the line 341?
0
 
GloomyFriarCommented:
ComPort->WriteString("AT+CMGF=1\xd");
 ComPort->WriteString("AT+CMGS=\"0790000000\"\xd");
 ComPort->WriteString("Test-SMS \xd ");
0
 
SteHCommented:
Still \x is remaining. I could not find a meaning for it. \ is an escape character inside strings allowing you to put special functionality in which is not readable. And what are the line numbers? My guess:

l339:   ComPort->WriteString("AT+CMGF=1\xd");
l340:   ComPort->WriteString("AT+CMGS=\"0790000000\"\xd"); // was giving problems due to " inside string.
l341:    ComPort->WriteString("Test-SMS \xd ");
the box  is giving the problem now. It is a n arrow for you but not here.
Solution for this should be to look up the hex code for that character and write it like \0x?? replacing the ?? with the hex value of that char.

When having several errors on a single line only care about the first. The other normally disappear when the first is solved.
0
 
AlexFMCommented:
ComPort->WriteString("AT+CMGF=1\\xd");
ComPort->WriteString("AT+CMGS=\"0790000000\"\\xd");
ComPort->WriteString("Test-SMS \\xd ");
0
 
rsch1973Author Commented:
Thanks a lot,

How can I send the strings 'Ctrl+Z' or '' (both are equal) via comport component with  the BCB6? If I use '' the compiler do not accept it. What can I do?

Ronald    
0
 
SteHCommented:
Ctrl+Z is EOF = 0x1A.
ComPort->WriteString ("Test-SMS\0x1A\\xd");
or should it be
ComPort->WriteString ("Test-SMS\0x1A\0x0d"); ?

0
 
rsch1973Author Commented:
Thanks,

I am confused a little bit. Now the compiler takes it but it seems when the application sends '0x1A' (ctrl+z) it copies some text to it which I input before which is 'AT+CMGS=\"0790000000\"\xd'.

When I use a Edit field to input AT commands it works if I copy the AT commands including 'CTRL+Z' from a testprogramme for my GSM modem. It does not work if I enter the text myself. I mean when it comes to the CTRL+Z it is doing the same thing as my programme it copies some text to it.

It seems for me there are two different CTRL+Z!!! Do you have any suggestions to go around it?

Cheers,
Ronald

 
0
 
SteHCommented:
It seems that the test program is adding some non printable characters which you don't see in the edit control but which are present if you copy and paste them. But they are missing if you enter only the printable chars yourself. Copy and paste the AT commands into an editor which allows hex display. The hex notation can then be copied to your app.
0
 
rsch1973Author Commented:
I tried it but the only charakters who are added are two space chars (20 in hex). When I run the programme with it the GSM modem sends back the same error like before.

Do you have any other solutions?

Ronald
0
 
SteHCommented:
Help will be difficult now, since now it is not a C++ problem but a GSM one.

Is the com port opened as binary? (Should be default.) How do you know, that the app is sending more to the phone?

Can you send the exact string the GSM test program is using and the ones you are sending? In hex notation if possible.

A short look on AT commands for mobile phone at least shows, that the ending of all commands is a CR = 0x0d not \xd. And AT+CMGS syntax is
AT+CMGS=0790000000<CR>Test-SMS<Ctrl-Z>
You are writing twice for a single command. This might be OK but it could be that you need to send it in one go:
AT+CMGS=0790000000\0x0DTest-SMS\0x1A\0x0D
0
 
GloomyFriarCommented:
I recommend you to use PortMon from www.sysinternals.com.
It'll show you what is really sent to RS.
You can find the problem by comparing what was sent with what is have to be sent.
0
 
_nn_Commented:
Ronald,

I saw your other thread in the Modems TA, but found this one still active. First a piece of advice : experts don't like to answer questions from askers with too many open questions. You have 10, that's a bit much. Please make an effort to close some of them.

Else, I'm not sure you're handling correctly the programming of a modem (following is not specific to GSM ones). You need to first get the result of a command before entering another one. So basically, you have to do following steps :
- flush input buffer
- write the command
- read a result (in most cases, "OK")
at _every_ stage.

Specifically for GSM AT commands and contrary to what SteH proposed, you must wait for the "> " prompt in the middle of the AT+CMGS operation :
- write "AT+CMGS=\"9999999\"\r"
- wait for ">"
- write "you message\x1A" (no need for an additional \r here)
- get the result (should be "OK")

Finally, you should make sure you have read the standards about the GSM AT standards (as well as a couple others) and make sure you're set up with your GSM modem. Usually, you need to do a couple things before attempting to send a SMS, like entering a PIN, and maybe a couple other things like the submission mode, the notifications you want, the character set, extended error codes, you name it (there's a lot, see your modem documentation if you have one).

Hope this helps.

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 5
  • 4
  • 4
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now