Solved

ComPort component

Posted on 2003-11-21
16
2,226 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
Industry Leaders: 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!

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

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
typedef std::deque<BYTE> ByteVector is broken in vs2012 23 89
thread-safe code in c++ 2 120
How to gracefully close the c++ 11 thread? 3 122
boost::uuid crashes 17 36
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

762 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