Question

Ougoing SMS collison problem (possible 3582 pts!)

Asked by: JooZ

Hi all

have developed an SMS gateway using VB, mscomm and Wavecom GSM modems, that receives requests for data via SMS and sends a reply to requestor via SMS.

however, now that my user loads have increased, i am experiencing high traffic at peak hours. this causes outgoing sms to collide with a half-incoming SMS. (fully received SMSes on the sim are cleared before attempting to send outgoing)

how do i detect if the signal is busy and it is safe to send an SMS out, and if a collision should occur, how do i trap it, and at what event/time period should i wait before attempting to resend (is there a command that says "resend last sms"?)

to reproduce problem, try firing up to 10 sms from a mobile to a gsm modem that is set to send a reply. most sms applications developed locally have not encountered the problem due to insufficient traffic congestion.

i am now a slave to the server, as i have to monitor the gateway everyday (on public holidays too!) and restart the application after it hangs. please help.

500 points to anyone who has a solution. if you can solve my problems once and for all with source code example. then i'm willing to give 3582 pts (all i've got)

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2003-03-05 at 13:22:46ID20539954
Tags

sms

Topic

Wireless Technologies

Participating Experts
5
Points
500
Comments
13

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. SMS from server to Mobile Phone via GSM Modem (suppor…
    Here's the situation: I've got IBM Director up and running. I want some events to be sent by SMS to a mobile phone. I've got a Siemens TC35 GSM Modem. I've set up the modem with a SIM, and also programmed in the pin, baud rate and so on. What I need: A script that should be ...
  2. SMS
    How can i send sms to a mobile, from a pc, do i need a gsm modem? A cellular gsm phone can serve? What software do i need? Please help me. The mobile is a crosscheck GSM 1900.
  3. SMS project for gsm mobile
    hi...i need to do wireless project related to SMS..so ineed to develop interactive between Pc and handphone. my project is like reminder...for example ihave a meeting 3p.m...then i sms to my server that i have meeting at 3 p.m...then the server will sms me at ot before 3p.m t...
  4. GSM
    I Already Own A GSM Modem, Should I Also Need To Subscribe To Any Service Providers(airtel , hutch ,etc.) For Sending SMS From PC To Mobile . Urgently Required...Please Reply At Earliest..

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: BigRatPosted on 2003-03-06 at 07:16:18ID: 8080607

I'd be quite happy with 50 cheeses :)

"is there a command that says "resend last sms"?"

Yes and No. You can put them into storage and send them from there, but the main problem is NOT the serial link but the wireless link. It is really just too slow (9600baud)

"how do i detect if the signal is busy and it is safe to send an SMS out"

You could in fact do :-

      ' Send an AT+CPAS command to the phone
       MSComm1.Output = "AT+CPAS" & Chr$(13) & Chr$(10)
       ' The phone responds with +CPAS: <pas>
       ' where pas = 0 (ready) 3 (Ringing) 4 (Active)

and that MIGHT help a bit, but collision is collision.

"i am now a slave to the server, as i have to monitor the gateway everyday (on public holidays too!) and restart the application after it hangs. please help."

Clobbered by your own success!

There are two possibilities :-

1) Introduce a second modem to post replies. One for in - polled I presume - and one for out.

2) Talk to your service provider about sending SMSs via some mechanism like E-Mail, HTTP or TCP/IP (there is a standard here - you make up a PDU and connect to the SPs SMS Server port and write the PDU into the socket). You have to make a contract with them but the SMSs can be sent cheaper (bulk rates) and often (Vodafone is an example if I remember rightly) they'll provide you with the software.

I'd seriously consider the latter option. Indeed there is also a mechanism to recieve incomming SMSs over a TCP/IP connection. All you need is effectively an Internet connection, and DSL these days is cheap and fast.


HTH

 

by: mtasallotiPosted on 2003-03-06 at 12:59:13ID: 8083519

I'll do better than give you source code, I'll give you an opensource high volume server ...

If you aren't too attached to your code, then, I would suggest using an open source gateway such as Kannel to get the job done.  Kannel in use by very high volume environments and I do believe that you can do load-balancing with it as well.  You can also directly connect this to a number of SMSC's once you have it stablized for you envirnment.  You can download Kannel from kannel.3glab.org.

Based on the VB comments, the only down side for you may be that it is a Linux-based server.  You'll need Cygwin to run it under windows.

If you have this many messages then you should be seriously considering an SMS Gateway (like Kannel) so that you can at least connect directly to the carrier's SMSC to save on incoming request costs and to handle volume.

---

Now regarding your current problem.  I don't believe that collisions can cause you to receive half-SMS's - may be an issue with Wavecom modems.  The SMSC will either fully deliver the message to your module based on module ack or it will store it in a store-and-forward queue for later delivery.  This sounds like it could be module memory issue, or load on the wavecom processor issue.  

- Are there any messages stored on the modem?
- Are you polling the modem (not good) or using the indicator events like CIND.
- Also, I don't believe that this should happen, but who knows in a high volume environment.  Could the incoming +CIND interrupts be cutting into your parsing algorithm - that is, are you sure (via logging) that the messages are in-fact half-messages or could something like a +CIND or +WIND be throwing off the parser - just a thought ...

Mathew

 

by: JooZPosted on 2003-03-06 at 22:21:48ID: 8086306

thanks for your suggestions, folks
----------
BigRat.
have been looking at AT+CPAS for a long time, but as you have already mentioned, the delay to wait for the cpas reply still does not guarantee that the instance of sending out is free from collision.

for instance
MSComm1.Output = "AT+CPAS" & Chr$(13) & Chr$(10)

then should i apply a boolean lock and go into a doevents loop? or should i specify a 1 second timeout? i already have several loop cycles waiting for triggers and boolean lock/unlocks, and its hitting the processors pretty bad. sigh. need optimisation somewhere...
----------

mtasalloti.
i looked at kannal when i first started developing the gateway. many of the algorithms in the gateway is derived from kannal's open source. however, trying to puzzle out the language got a bit too much for me, and i could not customize it to bundle into one complete application- gateway solution. kannal uses mutex locks to handle flow control, if i recall, and there was no equivalent in VB. hence the problem arising...

incoming sms Costs are born by requestor. outgoing sms will be marginally cheaper, but not enough to cover capital outlay.


- Are there any messages stored on the modem?
all messages on the modem are cleared before attmepting to send outgoing.

- Are you polling the modem (not good) or using the indicator events like CIND.
periodic polling of modems, and then using MSMQ triggers to reduce secondary polling for processing. how do i use CIND ?

- Also, I don't believe that this should happen, but who knows in a high volume environment.  Could the incoming +CIND interrupts be cutting into your parsing algorithm - that is, are you sure (via logging) that the messages are in-fact half-messages or could something like a +CIND or +WIND be throwing off the parser - just a thought ...

there is no problem of half-received SMSes. its a problem of outgoing sms colliding with half-incoming SMS and causing the application to hang. have not figured out how to trap the error equivalent to "message sending failed". any ideas?


----------

bigrat and mtasallotti...

the setup is as follows - up to 4 gsm modems, with a simcard of a different mobile network in each one. all modems process incoming messages irregardless of source mobile network, but outgoing sms to any particular network is only sent using the simcard-modem pair of that network.  012-> 012 , etc..

each modem monitor runs in a seperate thread. yes, using vb6.  i'll have to look into vb.net's multithreading abilities in the near future, but the problem at hand is most crucial at the moment. multithreads and inter-thread communication has been resolved ages ago. no crashes or interference with operations. (took me a while to get it right)

dedicating a single outgoing modem for outgoing is insufficient. real time delays at queue cause problems for my users and their clients. (its a retail application distributing goods via sms)

as for SMSC connectivity, local telcos require a leased line into their smsc. they do not accept sms-transmission via public internet. capital outlay for laying the infrastructure to even -one- telco will set me back at least 2 years in profit margins. sigh. moreover, i would have to commit to some crazy figure like 2 million smses a month. the problem i face now is not high sms volume, but high sms traffic at peak hours. volume has not reached those levels yet. international resellers cause delays and are prone to downtime or delays. (keeping a client waiting 5 minutes at the counter is NOT a good thing, trust me. *grin*)

hope the further information is useful. thanks again for the comments.

JooZ

 

by: mtasallotiPosted on 2003-03-06 at 23:35:12ID: 8086527

Wow, now it gets even more interesting ... sounds like you've working on this for a while.  Thanks for the backround on your project so far.

Ok, I'm grasping a bit since I don't see why modem messages should hang applications (I take it that the app is waiting for something that its not receiving).  

So, what if we take as much load off the modem as possible.  What do you need to poll for at all?  The WIND and CMTI commands will provide you with everything your application needs.

If, you are getting the messages off the modem using CMGR, then, what I would suggest is to modify your code to simply receive new messages as forwarded from the modem using CMTI. Anyways, excuse the CIND thing, that's either and Ericsson or Philips indication message.  The Wavecom equivilant is CMTI and you set it through CNMI.

So with AT+CNMI=2,2,0,1,0  .. your server will just be forwarded with the full incoming message as it arrives through CMTI unsolicited messages.  *** With this CNMI, you'll also turn on +CDS unsolicited messages which will tell you about the status of your sent items. ***

One last item - are the cut off messages particular to a specific mobile operator.  I wonder if there could be something wrong with their SMSC.

Hope this helps

 

by: BigRatPosted on 2003-03-07 at 03:32:40ID: 8087509

"... local telcos require a leased line into their smsc. they do not accept sms-transmission via public internet. .... moreover, i would have to commit to some crazy figure like 2 million smses a month."

Simply amazing! One can run the protocol through S-Tunnel with certificates. And 2,000,000! Who sends that many?

"...modem hanging the application...."

I do get this problem on Windows with my Nokia phone (6210), but not on Linux with a Siemens TC35.

Question: How long does a message stay in SI storage? Until it is read (read then delete) or until the App has processed it (read, process, delete send).

Question: What speed are you driving the modem?

 

by: ShadowLightPosted on 2003-05-07 at 15:02:21ID: 8483431

Hi,

I have developed a SMS system just like you, an SMS Sending and receiving program that can send 900sms/hour over a SIEMENS TC35 Terminal using Visual Basic, this project is for the market so I will not give (I do not have the rights of direct source code because I have developed this project for a company as freelance programmer) the exact source code but I will give detailed steps how-to avoid/minimize the collision especially under VB using mscomm control. I have faced the same issues like as yours. Well, If you do the following arrangements to your program you will be able to send (with a SIEMENS TC35 GSM Modem) about 900 SMS'es per hour while receiving incoming ones and sms status reports simulatneously without any side effects.

Well, there are some rules that you have to follow while dealing with a GSM Modem;

1. After sending a AT Command to device you must wait response from device and then send another one (this is forcing programmer to use multithreaded programmer with a tight "command pooling" algorithm)

2. If an exact command to be send second time (etc. failure of first command, sending a new one may be required of the same command.) make sure to use "A/" which is "Repeat previous command line"

3. Disable all redundant functions (I will explain this later in detailed manner)

4. Make sure that your connection to device is as follows
      a. Open port in 57600 rather than 19200 (Use setting mscomm.settings="57600,N,8,1") (DO NOT Use 115200, it may result unwanted situations even your computer and modem supports it)
      b. Open connection in Hardware flow control mode (mscomm.handshaking=comRTS)
      c. Set Comm Controls' Null Discard to true (mscomm.NullDiscard = True)
      d. Set comm control's (here after will be referred as CC) in/out buffer to 512 or lower (regarding as your needs more little value more good)
      f. Set CC's RTreshold Value = 1 for evaluting output without harrassing CC and Device (This is important and I will mention more about this.)
      g. Set local rate to a fixed value that you have opened port (AT+IPR=57600)
      h. Set FlowControl Mode from Device to Hardware flow Control using "AT\Q3" command
      i. ***** Disable Command Echo by using "ATE0" command this will shutdown the entered commands to redirected to output, as a result of this you will not be able to see what you have entered as Command, but this takes nearly 50% (in some cases 60%, especially when sending SMS!) weight from your GSM modem and enhances performance greatly *****
      The settings found above will ensure that your communication with your GSM Modem at top rate and very healthy.

How-to Send AT Commands to Device (Explanation of Step 1 which is written above);
Golden rule is to wait one commands "full" response from device and send another one after response received; but how ?
As I wrote the whole program under Visual Basic 6 I was unable to multithreaded program; but I came up a pooling like solution for this limitation;
      Create global function in a module name it sth like SendATCommand which only returns Boolean value (True or False) this will act spinal of the squential pooling system (which is somewhat lame but works fine) this function takes arguments of AT Command to be send, expected result and will return that if the command was successful (True) or failed (False)
      Create a Global Variable sth like BufferStatus and make it integer (in our case it will take only three values as 0,1 or 2). This will trigger CheckedDelay function receive buffer from CC!
      Create another function (this may not be a global one which will be used primarily by SendATCommand function to analyze output of device) named as sth like CheckedDelay.
      Optionally (Generally must but not neccessarily if you do not want.) create a sub which will and name it sth EvalOut evaluate output which is other than the commands expected result and will be called within SendAtCmd here are the code samples for these ones!

Function SendATCommand(Cmd As String, Optional DelayTime As Integer, _
                                    Optional ExpectedResult As String,optional termchar as string) As Boolean

        SendATCmd = False ' set to failed status from beginning
       
        If DelayTime = Empty Then DelayTime = 3
        If ExpectedResult = Empty Then ExpectedResult = DefaultResponse ' deafult Response is defined outside of this function and is vbcrlf & "OK" & Vbcrlf
        If TermChar = Empty Then TermChar = DefaultTermChar ' deafult termchar is defined outside of this function and is vbcr
       
        BufferStatus = 2 ' Global: BufferStatus; Ready to accept incoming from Device
       
        CCtl.Output = Cmd & TermChar ' Send command to CC
       
        If CheckedDelay(DelayTime, ExpectedResult) = True Then SendATCmd = True 'if Expected result met from output that this command was successful

End Function

Private Function CDelay(DelayTime As Integer, SrcStr As String) As Boolean
   
    Dim PauseTime As Long
    Dim Start As Long
    Dim Buffer As String
    Dim SBuffer As String
       
        Do Until BufferStatus = 1 ' Wait until CC's onComm Event's RTreshold property sets this to 1 from 2
            DoEvents
        Loop

        BufferStatus = 0 ' When CC's oncomm event sets this to 2 to 1 set 1 to 0 to avoid conflicts until this function executed completely once!
           
        CDelay = False
        PauseTime = DelayTime
        Start = Timer
       
        Do While Timer < Start + PauseTime ' this will ensure if anything missed from CC's oncomm event and will continue to check output until the expected values are reached

            Buffer = CCtl.Input
            SBuffer = SBuffer & Buffer

            If InStr(SBuffer, SrcStr) Then
                CDelay = True
                Exit Function
            End If

            If InStr(SBuffer, DefaultError) Then ' default error is "ERROR"
                CDelay = False
                Exit Function
            End If
           
            DoEvents

        Loop

End Function


by the way do not forget the following about CC;

Private Sub Comm_OnComm()

      Select Case Comm.CommEvent
           
            Case comEvReceive   ' Received RThreshold # of chars. We have set this befare to 1 to catch every character.
                If BufferStatus = 2 Then BufferStatus = 1
       
        End Select

End Sub

and always use Extended error reporting by entering the following command to the Device, this will enable you to see why an error occured;
AT+CMEE=1

this will enable output error's with their result codes such as "+CMS Error : 500" then you will be able to know why an error occured.
Mostly two types of errors will occur while and SMS Exchange with SMSC
1st is error Nr 500 which is "unknown error" : This is the SMS Collision while sending SMS if this occurs! and if in a SMS Send session this occurs you must give a 200ms delay after every AT Command entered to device for the safety after, one command (AT+CMGS for exmaple) is succeeded you may cancel 200ms delay safely!
2nd is error Nr 42: This is refferred as Congestion/Switching Equipment Congestion means that either your cell or destination cell too busy to handle the SMS you are trying to send or the path is closed temporarily.
Solution to 2nd is to send SMS to that destination with a delay (10S to 1m)

A very Important point is to Send SMS'es in PDU mode rather than Text Mode because GSM Modem will better handle pdu mode and will be much much faster because there will be no internal conversion from text-mode to pdu mode! (This is really really important about reliability)
If you are too lazy to write a Text - to - PDU Conversion (I know it is not easy but ... because I have written :) ) here is a quick trick for you ;
Switch Modem to Text Mode using AT+CMGF=1
then Write your SMS to SIM by using AT+CMGW
and then Swicth Modem to PDU Mode using AT+CMGF=0
Now Send your SMS from SIM using AT+CMSS
Afterwards you will have to delete the sent SMS by using AT+CMGD
and if you need do not forget to Swicth Modem to Text Mode using AT+CMGF=1 again.
This works well, but slows the actual progress as you have to do many steps.
So I recommend you write a Text <--> PDU Converter and work in full PDU mode

Another very important point is (as already meantioned here) receive incoming SMS and Reports in Display only mode;
(and evaluate them in a sub while receiving buffer from device)
to do this set
      AT+CSMS=1
      AT+CNMI = 3,2,0,1,1 (Check these values from you modems manual, your modem may not support these, find equivalent values for yuor self)
well now do not forget that you will receive any incoming SMS directly in to CC's buffer NOT TO SIM Card, so as soon as you receive +CMT: ... or +CDS: ...
you have to enter command AT+CNMA (new sms message acknowledge) or otherwise you CNMI setting will be reset and you will no longer receive reports and incoming SMS'es will start to fall SIM Card again.
When you Enter AT+CNMA device will return "OK" only your operator is waiting an Acknowledge from you and not timed out yet. (about 5 seconds)
I know this is a bit obscure but all the way it is.


2. Disabling redundant functions;
      if you do not need;
            a. Disable Cell Broadcast Messages immediately and never receive them
            b. Disable all functionality except SMS by using Barring function with AT+CLCK="AI",1,0000,247,1 and AT+CLCK="AO",1,0000,247,1

            these will greatly enhance modem's responsiveness

Some last things to say,
      avoid mutliple cycles, use only one if you can (Define a HQ and let it control all the things squentially, one by one)
      DoEvents is a Gift from heaven to VB programmers but it costs too much CPU Power and in some such rare cases may screw up things so use it wisely and not all the time.
      lastly and if you feel that you need to give any delay somewhere you can use 100ms (if you are a paranoid like me you can use 200ms also :) ) but more is absolutely waste of time.

I hope that I may help you a little bit, you may ask whatever you want about, I will appreciate to help in this topic everyone.

      
Onur Buyukcaglar

 

by: ShadowLightPosted on 2003-05-07 at 15:53:57ID: 8483742

Hi,

I have developed a SMS system just like you, an SMS Sending and receiving program that can send 900sms/hour over a SIEMENS TC35 Terminal using Visual Basic, this project is for the market so I will not give (I do not have the rights of direct source code because I have developed this project for a company as freelance programmer) the exact source code but I will give detailed steps how-to avoid/minimize the collision especially under VB using mscomm control. I have faced the same issues like as yours. Well, If you do the following arrangements to your program you will be able to send (with a SIEMENS TC35 GSM Modem) about 900 SMS'es per hour while receiving incoming ones and sms status reports simulatneously without any side effects.

Well, there are some rules that you have to follow while dealing with a GSM Modem;

1. After sending a AT Command to device you must wait response from device and then send another one (this is forcing programmer to use multithreaded programmer with a tight "command pooling" algorithm)

2. If an exact command to be send second time (etc. failure of first command, sending a new one may be required of the same command.) make sure to use "A/" which is "Repeat previous command line"

3. Disable all redundant functions (I will explain this later in detailed manner)

4. Make sure that your connection to device is as follows
      a. Open port in 57600 rather than 19200 (Use setting mscomm.settings="57600,N,8,1") (DO NOT Use 115200, it may result unwanted situations even your computer and modem supports it)
      b. Open connection in Hardware flow control mode (mscomm.handshaking=comRTS)
      c. Set Comm Controls' Null Discard to true (mscomm.NullDiscard = True)
      d. Set comm control's (here after will be referred as CC) in/out buffer to 512 or lower (regarding as your needs more little value more good)
      f. Set CC's RTreshold Value = 1 for evaluting output without harrassing CC and Device (This is important and I will mention more about this.)
      g. Set local rate to a fixed value that you have opened port (AT+IPR=57600)
      h. Set FlowControl Mode from Device to Hardware flow Control using "AT\Q3" command
      i. ***** Disable Command Echo by using "ATE0" command this will shutdown the entered commands to redirected to output, as a result of this you will not be able to see what you have entered as Command, but this takes nearly 50% (in some cases 60%, especially when sending SMS!) weight from your GSM modem and enhances performance greatly *****
      The settings found above will ensure that your communication with your GSM Modem at top rate and very healthy.

How-to Send AT Commands to Device (Explanation of Step 1 which is written above);
Golden rule is to wait one commands "full" response from device and send another one after response received; but how ?
As I wrote the whole program under Visual Basic 6 I was unable to multithreaded program; but I came up a pooling like solution for this limitation;
      Create global function in a module name it sth like SendATCommand which only returns Boolean value (True or False) this will act spinal of the squential pooling system (which is somewhat lame but works fine) this function takes arguments of AT Command to be send, expected result and will return that if the command was successful (True) or failed (False)
      Create a Global Variable sth like BufferStatus and make it integer (in our case it will take only three values as 0,1 or 2). This will trigger CheckedDelay function receive buffer from CC!
      Create another function (this may not be a global one which will be used primarily by SendATCommand function to analyze output of device) named as sth like CheckedDelay.
      Optionally (Generally must but not neccessarily if you do not want.) create a sub which will and name it sth EvalOut evaluate output which is other than the commands expected result and will be called within SendAtCmd here are the code samples for these ones!

Function SendATCommand(Cmd As String, Optional DelayTime As Integer, _
                                    Optional ExpectedResult As String,optional termchar as string) As Boolean

        SendATCmd = False ' set to failed status from beginning
       
        If DelayTime = Empty Then DelayTime = 3
        If ExpectedResult = Empty Then ExpectedResult = DefaultResponse ' deafult Response is defined outside of this function and is vbcrlf & "OK" & Vbcrlf
        If TermChar = Empty Then TermChar = DefaultTermChar ' deafult termchar is defined outside of this function and is vbcr
       
        BufferStatus = 2 ' Global: BufferStatus; Ready to accept incoming from Device
       
        CCtl.Output = Cmd & TermChar ' Send command to CC
       
        If CheckedDelay(DelayTime, ExpectedResult) = True Then SendATCmd = True 'if Expected result met from output that this command was successful

End Function

Private Function CDelay(DelayTime As Integer, SrcStr As String) As Boolean
   
    Dim PauseTime As Long
    Dim Start As Long
    Dim Buffer As String
    Dim SBuffer As String
       
        Do Until BufferStatus = 1 ' Wait until CC's onComm Event's RTreshold property sets this to 1 from 2
            DoEvents
        Loop

        BufferStatus = 0 ' When CC's oncomm event sets this to 2 to 1 set 1 to 0 to avoid conflicts until this function executed completely once!
           
        CDelay = False
        PauseTime = DelayTime
        Start = Timer
       
        Do While Timer < Start + PauseTime ' this will ensure if anything missed from CC's oncomm event and will continue to check output until the expected values are reached

            Buffer = CCtl.Input
            SBuffer = SBuffer & Buffer

            If InStr(SBuffer, SrcStr) Then
                CDelay = True
                Exit Function
            End If

            If InStr(SBuffer, DefaultError) Then ' default error is "ERROR"
                CDelay = False
                Exit Function
            End If
           
            DoEvents

        Loop

End Function


by the way do not forget the following about CC;

Private Sub Comm_OnComm()

      Select Case Comm.CommEvent
           
            Case comEvReceive   ' Received RThreshold # of chars. We have set this befare to 1 to catch every character.
                If BufferStatus = 2 Then BufferStatus = 1
       
        End Select

End Sub

and always use Extended error reporting by entering the following command to the Device, this will enable you to see why an error occured;
AT+CMEE=1

this will enable output error's with their result codes such as "+CMS Error : 500" then you will be able to know why an error occured.
Mostly two types of errors will occur while and SMS Exchange with SMSC
1st is error Nr 500 which is "unknown error" : This is the SMS Collision while sending SMS if this occurs! and if in a SMS Send session this occurs you must give a 200ms delay after every AT Command entered to device for the safety after, one command (AT+CMGS for exmaple) is succeeded you may cancel 200ms delay safely!
2nd is error Nr 42: This is refferred as Congestion/Switching Equipment Congestion means that either your cell or destination cell too busy to handle the SMS you are trying to send or the path is closed temporarily.
Solution to 2nd is to send SMS to that destination with a delay (10S to 1m)

A very Important point is to Send SMS'es in PDU mode rather than Text Mode because GSM Modem will better handle pdu mode and will be much much faster because there will be no internal conversion from text-mode to pdu mode! (This is really really important about reliability)
If you are too lazy to write a Text - to - PDU Conversion (I know it is not easy but ... because I have written :) ) here is a quick trick for you ;
Switch Modem to Text Mode using AT+CMGF=1
then Write your SMS to SIM by using AT+CMGW
and then Swicth Modem to PDU Mode using AT+CMGF=0
Now Send your SMS from SIM using AT+CMSS
Afterwards you will have to delete the sent SMS by using AT+CMGD
and if you need do not forget to Swicth Modem to Text Mode using AT+CMGF=1 again.
This works well, but slows the actual progress as you have to do many steps.
So I recommend you write a Text <--> PDU Converter and work in full PDU mode

Another very important point is (as already meantioned here) receive incoming SMS and Reports in Display only mode;
(and evaluate them in a sub while receiving buffer from device)
to do this set
      AT+CSMS=1
      AT+CNMI = 3,2,0,1,1 (Check these values from you modems manual, your modem may not support these, find equivalent values for yuor self)
well now do not forget that you will receive any incoming SMS directly in to CC's buffer NOT TO SIM Card, so as soon as you receive +CMT: ... or +CDS: ...
you have to enter command AT+CNMA (new sms message acknowledge) or otherwise you CNMI setting will be reset and you will no longer receive reports and incoming SMS'es will start to fall SIM Card again.
When you Enter AT+CNMA device will return "OK" only your operator is waiting an Acknowledge from you and not timed out yet. (about 5 seconds)
I know this is a bit obscure but all the way it is.


2. Disabling redundant functions;
      if you do not need;
            a. Disable Cell Broadcast Messages immediately and never receive them
            b. Disable all functionality except SMS by using Barring function with AT+CLCK="AI",1,0000,247,1 and AT+CLCK="AO",1,0000,247,1

            these will greatly enhance modem's responsiveness

Some last things to say,
      avoid mutliple cycles, use only one if you can (Define a HQ and let it control all the things squentially, one by one)
      DoEvents is a Gift from heaven to VB programmers but it costs too much CPU Power and in some such rare cases may screw up things so use it wisely and not all the time.
      lastly and if you feel that you need to give any delay somewhere you can use 100ms (if you are a paranoid like me you can use 200ms also :) ) but more is absolutely waste of time.

I hope that I may help you a little bit, you may ask whatever you want about, I will appreciate to help in this topic everyone.

      
Onur Buyukcaglar

 

by: JooZPosted on 2003-05-07 at 22:32:30ID: 8485289

Thanks Onur!

reading thru your comment, i believe it may hold the key to my problems. I have to take a bit of time to tear open my project file and make the necessary changes to it and see if that works. If anyone else is wondering what happened to my situation, I moved the server back to my house and work from home now for easy maintenance. *grin*

might as well turn a big problem to my benefit in some way or other. hehehh.

Onur, it seems you have spent at least as much time on this as i me, and gone far more in depth that i ever would. Great stuff man! esp the bits abt text vs PDU speeds and redundant functions. My whole program is full of cycles, unfortunately, but upon checking, most of it was caused by the necessity for modem response. will ty and renovate the flow so that a master controller will handle it.

as for multithreading issues..
i use Srideep Prasad's MThreadVB object. It can be obtained here http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=27481&lngWId=1

Srideep is an amazing person that has managed to get around the limitations of VB in a funky manner. You might want to try it out. I basically create a MDI Parent, then spawn 4 MThreadVB sessions to handle 2 modems, one listener(parser) module and one Sending module, all with a child output screen each. The ocx which controls each modem is simply encapsulated in a window spawned by the modem threads. in this way. its theoretically possible to have up to 4 modems running from a single gateway app. (obviously an I/O card is required to support the extra two serial port connectors)

at this point tho, i havent even dared to go up to 3 modems, tho my experience with the SMS gateway that i based my program upon handles 3 modems fine. I dont think it was written in VB tho. heh...

I know for a fact that running two modems is fine using  MthreadVB. Theres a memory leak in my program somewhere that requires restarting every now and then (anything from several hours to several days, totally random) but i'm not sure if its caused by the multithreading object or just bad coding somewhere.

And, to cap things off, after over a year of trying to puzzle things out and many sleepless nights, i find that my regional distributor of Wavecom modems has FINALLY released an API, obtainable at http://www.dinkum.com.sg/products/hardware-wmapi.asp

sigh.. i'm still wondering if i should purchase it and be done with it or actually continue trying to fix the bugs in my .ocx

cheers
JooZ

 

by: ShadowLightPosted on 2003-05-08 at 01:54:12ID: 8486497

Hi Jooz,

"My whole program is full of cycles, unfortunately, but upon checking, most of it was caused by the necessity for modem response. will ty and renovate the flow so that a master controller will handle it"
Well OK, modifying this will not be a problem because most of the AT Commands (roughly about 85% percent of them) will return either CrLf & "OK" & CrLf or CrLf & "Error" & CrLf (if you do not use Extended error reporting) so it is easy to handle mosta of them due to the tact they will return same things over and over again, well you might need some special responses regarding to the comments responses, I mean that command will return again sth like "OK" or "Error" but before these you may need middle responses. Lets say that you need the Manufacturer ID by using AT+GMI, this will return OK/Error at the end but will also return a middle value such as SIEMENS in my case. so I have to trap this value. Well this situation rather easy when you build you HQ, becasue when your HQ is completed you would be proccessing all most of the AT Commands, and the rest is either you are waiting a custom known or unknown result. You can do this easily by implementing a single "Search within Buffer" function that is fired from your HQ every time while it examines the portion of CC's Buffer.
And another topic that you mention it I have downloaded MThreadVB, it is really astonishing, but, there is an important issue for me. There are ten-thousands of ocxs, components are floating right outside, well whenever I start a program sth I always managed to find either sth similar or a like perfect match components DLLs or even completely free programs, well at the beginning I was using them happily which they were helping greatly, but I see soon that there is no challenge in it, I mean that I am programming sth, but the heart of the program was from another guy. did "I" code this program ? Well as I said there is no challenge in it. hehe!
As for your situation, try to estimate a timeline JOOz, If you do not have a time obligation/deadline you better renovate your code and drop ocx from my point of view, because thiss will increase your manageability over your own code and on the other side if that ocx has some bugs and flaws it will be hard to pretend someone else's code and to correct them.
by the way there is an issue about GSM Modems, SIEMENS TC35 supports multiplex mode (AT+CMUX), iy your modem supports it, I may give some basic info about this mode, now I am currently working on this mode because when using this mode you may be able to double-or-triple you application and modem performance.

Thats all for now.

Onur Buyukcaglar

 

by: jklankaPosted on 2003-07-08 at 23:45:40ID: 8882946

Hi,

Can anybody help me to develope a gateway using VB. I were asked  to develope a SMS Gateway using VB. So that I am trying to find some model source code.

Please send me if you dont mind to study a model of SMS gateway which created using VB.
My Email is jklanka@hotmail.com / jklanka@yahoo.com

Thanks

JK

 

by: JooZPosted on 2003-11-21 at 11:19:14ID: 9799277

first of all, many apologies to the xperts who have helped me and to experts-exchange for neglecting my duties towards my fellow experts who have helped me thus far.

i have stopped development on the GSM momdem integration with my appliation partially due to the fact that my company was taken over my dingbats who know nothing about information technology and also partially due to the overload of other real life issues that have consumed my time for the past few months. since then, i have left that company and have been concentrating on other projects such as failover clustering for SQL servers. :p

i am not sure if i wil ever touch the application again due to my inability to obtain investment into capital for a new company that i was planning to start up based upon SMS aggregation (those of you who do not know what aggregation is, feel free to email me and i'll explain to the fullest of my abilities) and i have been disheartened by the whole process to the point that i'm almost ready to turn my back upon SMS technology altogether.

i am 90% sure that any issues of multithreading have been sorted out due to the release of vb.net (correct me if i am wrong), message-collision-handling *should* be handled by the API from Dinkum and that any of you who are just beginning to explore GSM/SMS technology should not have any problems due to the high availability of commercial-grade solutions out there now.

points for this question go to Shadowlight aka Onur for being comprehensive in his explanation of his suggested answer. i am sure that your input has helped many fledgling developers out there.

for the other experts who have suggested answers, many thanks for your input. i am very appreciated for your time and effort in replying to my dilemma, and i wish that i could have put some of it to good use in the end, but ultimately, i never got around to correcting the whole application to the point that i could be proud of it. i am sure some of you know what i've gone thru from past experience. :/

good luck to all of you. be L337 and code like a demon. :) perhaps you might be appreciated more for your skills where you are than where i am.

sincerely,
JooZ

 

by: EmredrumPosted on 2008-12-26 at 16:54:27ID: 23246980

http://www.experts-exchange.com/Internet/Chat_-_IM/Q_23737701.html

What was the bearer of the message?  See my posts on the different rates or send/rec that SMS can handle.  I am not sure if your looking at software as the fault, rather than a thru-put issue on the data bearer.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...