I have problems with the Cellular Radio Module.
When an sms arrives, I get an ‘System.ArgumentOutOfRangeException’.
Very rarely, it’s successfull. But when I’ve got the exception then the program is completely broken.
The reason in code:
while (serialLine.BytesToRead > 0)
{
response += (char) serialLine.ReadByte();
}
This loop is left, even if still data is coming in. Probably a very small break in the serial communication?
If you have distinctive message separator then you accumulate the content until you get that separator. Or if your message has fixed size you can check the size.
You realize that this is the constructor of the CellularRadio object, and that putting that loop in there is pretty much going to fail - if you look lower down in the code you quoted, it creates a new thread that’s job is to read the input.
Can you take a step back and tell us what you’re trying to do, and how you went about it?
I had that problem also. I added the driver source directly into my project so I could change things on the fly. Here is my revision that seemed to “fix” this problem:
#region Check Sms Received (CMTI)
if (response.IndexOf("+CMTI:") > 0)
{
try
{
string cmd = "+CMTI:";
first = response.IndexOf(cmd) + cmd.Length;
last = response.IndexOf("\n", first);
reply = (response.Substring(first, last - first)).Trim();
char[] sep = { ',' };
string[] split = reply.Split(sep);
/* try
{
*/
int position = int.Parse(split[1]);
newMessages.Enqueue(position);
RetrieveSms(position, false);
}
catch (Exception)
{
DebugPrint("ERROR");
}
}
@ logictechs - But then you can loose sms information?
If this happens during receiving, the information will be lost.
I want to use this combined with a relay: if sms received with certain contact, activate relais.
So it must be without any error (in normal condition).
How can we find the author of this code?
And who maintains the ‘GTM.Seeed’ library?
Hmm, you are bumping into the usual pitfalls and roadblocks. I wish I had some more time to coordinate a serious overhaul of this driver. I actually think the module is ok, but the driver is having serious issues. Thanks logitechs for helping Stijn.