We've moved the CellularRadioManager class into this project, so it's easier to use the driver for GPRS connections.

The included code sample shows how to create the modem, and how to use it to POST to an HTTP web service


private CellularRadioManager _radioManager;

// ctor
public void MyClass()
{
	 // for a FEZ Cerberus, using Socket 2
 	_radioManager = new CellularRadioManager(2)
 	{
		DebugPrintEnabled = true,
		IsHttpModeEnabled = true
	};
}

// use
private bool SendDataToServer(string post)
{
	DebugPrint("TcpSend: Connect");
	var retVal = true;
	if (!_radioManager.Connect(YOUR_SERVER_ADDRESS_HERE))
	{
		DebugPrint("Tcp Send: Connect Failed");
		TcpDisconnect();
		Thread.Sleep(2000);
		return false;
	}
	// send data
	DebugPrint("TcpSend: Start Send");
	if (!_radioManager.SendData(post))
	{
		DebugPrint("Tcp Send: SendData Failed");
		TcpDisconnect();
		Thread.Sleep(2000);
		return false;
	}
	// wait to flush
	string data;
	if (!_radioManager.ReceiveData(10000, out data))
	{
		DebugPrint("Tcp Send: ReceiveData Failed or empty");
		TcpDisconnect();
		Thread.Sleep(2000);
		return false;
	}
	DebugPrint(data);

	// ReSharper disable StringIndexOfIsCultureSpecific.1
	if (data.IndexOf(@"HTTP/1.1 201 Created") <= -1)
	{
		// unsuccessful server transaction, TODO: re-try?
		DebugPrint("Tcp Send: Server FAILED");
		TcpDisconnect();
		Thread.Sleep(2000);
		return false;
	}
	// successful server transaction
	DebugPrint("Tcp Send: Server OK - \"201 Created\"");
	TcpDisconnect();
	Thread.Sleep(2000);
	return true;

}

private void TcpDisconnect()
{
	if (_radioManager.Disconnect())
	{
		DebugPrint("Tcp Send: Disconnected");
		return;
	}
	DebugPrint("Tcp Send: Disconnect Failed");
}

private static void DebugPrint(string str)
{
	Debug.Print(str);
}

Last edited Jan 14, 2013 at 12:40 AM by ByronR, version 7

Comments

mawarnes_codeplex Jan 2, 2013 at 3:19 PM 
Hi, I've got this code, but I'm struggling with how I can use it. Is it possible to put some example code in there?