Solved

ComPort component

Posted on 2003-11-21
16
2,217 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
  • 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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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 500 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now