I have Cobra II (wifi) and serial camera L2. I tried example from Dat in his post at http://www.tinyclr.com/forum/topic?id=9506&page=1#msg94738.
Everything works very well, but when I turn on wifi, video streaming hangs.
Not enough memory?
using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;
using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;
namespace TestSerCam4._2
{
public partial class Program
{
// This method is run when the mainboard is powered up or reset.
byte[] datajpg;
int index = 0;
void ProgramStarted()
{
/*******************************************************************************************
Modules added in the Program.gadgeteer designer view are used by typing
their name followed by a period, e.g. button. or camera.
Many modules generate useful events. Type +=<tab><tab> to add a handler to an event, e.g.:
button.ButtonPressed +=<tab><tab>
If you want to do something periodically, use a GT.Timer and handle its Tick event, e.g.:
GT.Timer timer = new GT.Timer(1000); // every second (1000ms)
timer.Tick +=<tab><tab>
timer.Start();
*******************************************************************************************/
// Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
Debug.Print("Program Started");
serCam.StartDataCaptured += new SerCam.StartDataCapturedEventHandler(serCam_StartDataCaptured);
serCam.OnDataCaptured += new SerCam.DataCapturedEventHandler(serCam_OnDataCaptured);
serCam.FinishDataCaptured += new SerCam.FinishDataCapturedEventHandler(serCam_FinishDataCaptured);
new Thread(VideoStreamming).Start();
}
void VideoStreamming()
{
while (true)
{
if (!serCam.isBusy)
{
serCam.TakePicture();
}
else Thread.Sleep(50);
}
}
void serCam_FinishDataCaptured(SerCam sender)
{
display_T35.SimpleGraphics.DisplayImage(new Bitmap(datajpg, Bitmap.BitmapImageType.Jpeg), 0, 0);
}
void serCam_OnDataCaptured(SerCam sender, byte[] data)
{
if (index + data.Length > datajpg.Length)
{
throw new Exception("Error");
}
Array.Copy(data, 0, datajpg, index, data.Length);
index += data.Length;
}
void serCam_StartDataCaptured(SerCam sender, int sizeImage)
{
index = 0;
datajpg = new byte[sizeImage];
}
}
}
wifi code:
static WiFiRS9110 WifiInterface = new WiFiRS9110(SPI.SPI_module.SPI2, G120.Pin.P1_10, G120.Pin.P2_11, G120.Pin.P1_9);
void StartWifi()
{
if (!WifiInterface.IsOpen)
WifiInterface.Open();
//Enable DHCP
if (!WifiInterface.NetworkInterface.IsDhcpEnabled)
WifiInterface.NetworkInterface.EnableDhcp();
//Assign the TCP/IP stack
NetworkInterfaceExtension.AssignNetworkingStackTo(WifiInterface);
//Setup our events
WifiInterface.NetworkAddressChanged += new NetworkInterfaceExtension.NetworkAddressChangedEventHandler(GHI_Wifi_NetworkAddressChanged);
WifiInterface.WirelessConnectivityChanged += new WiFiRS9110.WirelessConnectivityChangedEventHandler(GHI_Wifi_WirelessConnectivityChanged);
//Scan for networks
WiFiNetworkInfo[] wifiInfo = WifiInterface.Scan();
bool found = false;
for (int i = 0; i < wifiInfo.Length; i++)
{
if (wifiInfo[i].SSID == "ap")
{
found = true;
WifiInterface.Join(wifiInfo[i], "");
Debug.Print(wifiInfo[i].RSSI.ToString());
break;
}
}
if (!found)
Debug.Print("could not find network");
while (true)
{
IPAddress ip = IPAddress.GetDefaultLocalAddress();
if (ip != IPAddress.Any) break;
Thread.Sleep(1000);
}
}