I used the code in my own project but I got an error in the constructor:
An unhandled exception of type ‘System.Exception’ occurred in Microsoft.SPOT.Hardware.dll
/// <summary>Instantiates a Cellular Radio Module</summary>
/// <param name="socketNumber">The socket that this module is plugged in to.</param>
public CellularRadio(int socketNumber)
{
socket = Socket.GetSocket(socketNumber, true, this, null);
pwrkey = new Interfaces.DigitalOutput(socket, Socket.Pin.Three, false, this);
serialLine = new Interfaces.Serial(socket, 19200, Interfaces.Serial.SerialParity.None, Interfaces.Serial.SerialStopBits.One, 8, Interfaces.Serial.HardwareFlowControl.Required, this);
serialLine.Open();
serialLine.Write("AT");
Thread.Sleep(1000);
String response = "";
while (serialLine.BytesToRead > 0)
{
response += (char)serialLine.ReadByte();
}
DebugPrint("RESP: " + response);
if (response.Length != 0)
{
DebugPrint("Sending off pulse");
pwrkey.Write(true);
Thread.Sleep(1200);
pwrkey.Write(false);
Thread.Sleep(500);
}
isPowerOn = false;
readerThread = new Thread(new ThreadStart(SerialRead));
readerThread.Start();
}
Hi
I have tested the Cellular radio Module with a CerbuinoBee card this week.
The Cellular Radio Module is connected on socket 2.
If you want to send and receive SMS, the code posted in this topic https://www.ghielectronics.com/community/forum/topic?id=12072 runs very well but you must suppress the 2 lines SendATCommand in PowerOnSequenceThread() and send SMS only when the networkregistration is Registered. You must suppress code PIN. Here my test code.
using Gadgeteer.Modules.Seeed;
using Gadgeteer.Modules.Mekalogic;
using Gadgeteer.Modules.GHIElectronics;
void ProgramStarted()
{
Debug.Print("Program Started");
cellularRadio.DebugPrintEnabled = true;
cellularRadio.PowerOn(50);
cellularRadio.SmsReceived += new CellularRadio.SmsReceivedHandler(cellularRadio_NewSMSEvent);
cellularRadio.SmsRetrieved += new CellularRadio.SmsRetrievedHandler(cellularRadio_SMSReady);
cellularRadio.ModuleInitialized += new CellularRadio.ModuleInitializedHandler(cellularRadio_ModuleInitialized);
cellularRadio.PinStateRetrieved += new CellularRadio.PinStateRetrievedHandler(cellularRadio_PINEvent);
cellularRadio.GprsNetworkRegistrationChanged += new CellularRadio.GprsNetworkRegistrationChangedHandler(cellularRadio_GprsNetworkRegistrationChanged);
// cellularRadio.GsmNetworkRegistrationChanged += new CellularRadio.GsmNetworkRegistrationChangedHandler(cellularRadio_GsmNetworkRegistrationChanged);
cellularRadio.OperatorRetrieved += new CellularRadio.OperatorRetrievedHandler(cellularRadio_OperatorReady);
Thread powerOnThread = new Thread(new ThreadStart(PowerOnSequenceThread));
powerOnThread.Start(); }
private void PowerOnSequenceThread()
{
while (true)
Thread.Sleep(100);
}
void cellularRadio_GsmNetworkRegistrationChanged(CellularRadio sender, CellularRadio.NetworkRegistrationState networkState)
{
if (networkState == CellularRadio.NetworkRegistrationState.Registered)
{
Debug.Print("GSM NetworkRegistration = Registered");
cellularRadio.SendSms("06111111", "Gsm test message");
}
if (networkState == CellularRadio.NetworkRegistrationState.RegistrationDenied)
{
Debug.Print("GSM NetworkRegistration = RegistrationDenied");
}
if (networkState == CellularRadio.NetworkRegistrationState.Roaming)
Debug.Print("GSM NetworkRegistration = Roaming");
if (networkState == CellularRadio.NetworkRegistrationState.Searching)
{
Debug.Print("GSM NetworkRegistration = Searching");
char_Display.PrintString("GSM Searching");
}
if (networkState == CellularRadio.NetworkRegistrationState.NotSearching)
{
Debug.Print("GSM NetworkRegistration = NotSearching");
}
if (networkState == CellularRadio.NetworkRegistrationState.Unknown)
Debug.Print("GSM NetworkRegistration = Unknown");
if (networkState == CellularRadio.NetworkRegistrationState.Error)
{
Debug.Print("GSM NetworkRegistration = Error");
}
}
To use the Cellular Radio module with the library http://tcpcellularradio.codeplex.com.
For my first test I have the same problem like you ( "An unhandled exception of type ‘System.Exception’ occurred in Microsoft.SPOT.Hardware.dll ") because there are 2 initialization of the same socket (socket 2), one time in the program.generated.cs file and a second time in the program.cs file. You must suppress the initialization made in the generated file.
Here my code
private void InitializeModules() {
// this.cellularRadio = new GTM.Seeed.CellularRadio(2);
// THIS LINE MUST BE SUPPRESSED TO AVOID ERROR MESSAGE
//With this line I have strong]An unhandled exception of type 'System.Exception' occurred in Microsoft.SPOT.Hardware.dll[/b] "
}
void ProgramStarted()
{
Debug.Print("Program Started");
m_radioManager = new CellularRadioManager(2)
// YOU MUST COMMENT THE LINE « new CellularRadio(2) » in the program.generated.cs file see above.
{
AccessPointName = "orange",
DebugPrintEnabled = true,
IsHttpModeEnabled = true
};
Thread powerOnThread = new Thread(new ThreadStart(PowerOnSequenceThread));
powerOnThread.Start();
}
private void PowerOnSequenceThread()
{
RadioState previousState = RadioState.PowerOff;
while (true)
{
if (m_radioManager.RadioState != previousState)
{ previousState = m_radioManager.RadioState;
Debug.Print("RadioState=" + m_radioManager.RadioState.ToString());
if (m_radioManager.RadioState == RadioState.Busy)
Debug.Print("RadioState= Busy");
if (m_radioManager.RadioState == RadioState.PowerOff)
Debug.Print("RadioState= PowerOff");
if (m_radioManager.RadioState == RadioState.Ready)
Debug.Print("RadioState= Ready");
if (m_radioManager.RadioState == RadioState.StartingUp)
Debug.Print("RadioState= StartingUp");
if (m_radioManager.RadioState == RadioState.Unitialized)
Debug.Print("RadioState= Unitialized");
if (m_radioManager.RadioState == RadioState.WaitingForGprsConnection)
Debug.Print("RadioState= WaitingForGprsConnection");
if (m_radioManager.RadioState == RadioState.WaitingForIMEI)
Debug.Print("RadioState= WaitingForIMEI");
if (m_radioManager.RadioState == RadioState.WaitingForNetworkRegistration)
Debug.Print("RadioState= WaitingForNetworkRegistration");
}
if (m_radioManager.RadioState == RadioState.Ready)
{
m_radioManager.Connect("www.google.com");
var request =
"GET / HTTP/1.1" + m_crlf +
"Host: www.google.com" + m_crlf +
m_crlf;
m_radioManager.SendData(request);
var response = "";
m_radioManager.ReceiveData(5000, out response);
Debug.Print(response);
}
Thread.Sleep(500);
}
}
[quote] m_radioManager = new CellularRadioManager(2)
// YOU MUST COMMENT THE LINE « new CellularRadio(2) » in the program.generated.cs file see above.
[/quote]
Actually, editing the GENERATED code is not reliable, it will be re-generated and re-added, so the simple solution is to EXCLUDE the Cellular module from the designer.