Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ComPort component

Posted on 2003-11-21
16
Medium Priority
?
2,234 Views
Last Modified: 2011-09-20
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
Comment
Question by:rsch1973
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 4
  • +2
16 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 9796694
ComPort->WriteString("AT+CMGF=1\\xd");
ComPort->WriteString("AT+CMGS="0790000000"\\xd");
ComPort->WriteString("Test-SMS \\xd ");

0
 
LVL 48

Expert Comment

by:AlexFM
ID: 9796716
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
 
LVL 13

Expert Comment

by:SteH
ID: 9797174
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Author Comment

by:rsch1973
ID: 9797231
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
 
LVL 48

Expert Comment

by:AlexFM
ID: 9797340
What did you try exactly, please show your code. And where is the line 341?
0
 
LVL 6

Expert Comment

by:GloomyFriar
ID: 9797851
ComPort->WriteString("AT+CMGF=1\xd");
 ComPort->WriteString("AT+CMGS=\"0790000000\"\xd");
 ComPort->WriteString("Test-SMS \xd ");
0
 
LVL 13

Expert Comment

by:SteH
ID: 9798223
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
 
LVL 48

Expert Comment

by:AlexFM
ID: 9798310
ComPort->WriteString("AT+CMGF=1\\xd");
ComPort->WriteString("AT+CMGS=\"0790000000\"\\xd");
ComPort->WriteString("Test-SMS \\xd ");
0
 
LVL 1

Author Comment

by:rsch1973
ID: 9809142
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
 
LVL 13

Expert Comment

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

0
 
LVL 1

Author Comment

by:rsch1973
ID: 9809394
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
 
LVL 13

Expert Comment

by:SteH
ID: 9809438
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
 
LVL 1

Author Comment

by:rsch1973
ID: 9809725
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
 
LVL 13

Expert Comment

by:SteH
ID: 9809969
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
 
LVL 6

Expert Comment

by:GloomyFriar
ID: 9817281
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
 
LVL 16

Accepted Solution

by:
_nn_ earned 1500 total points
ID: 9862082
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question