Here is my code.
The only error it gives is thet Sockets doesn’t excist in System.net
I use the Fez cobra and version 4.1
Program.cs
using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT.Input;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using GHIElectronics.NETMF.Hardware;
using GHIGraphicalDemo.Presentation;
//using GHIElectronics.NETMF.FEZ;
namespace GHIGraphicalDemo
{
public class Program : Application
{
public static Program program;
public static void Main()
{
Bitmap logo = Resources.GetBitmap(Resources.BitmapResources.ThomasMore_logo);
Configuration.StartUpLogo.Set(logo.GetBitmap(), (SystemMetrics.ScreenWidth - logo.Width ) / 2, (SystemMetrics.ScreenHeight - logo.Height) / 2);
Program program = new Program();
// Enable touch
Touch.Initialize(program);
TouchCollectorConfiguration.CollectionMethod = CollectionMethod.Native;
TouchCollectorConfiguration.CollectionMode = CollectionMode.InkAndGesture;
// Note, this is the amount of time (in ms) to elapse before sending a move event.
TouchCollectorConfiguration.TouchMoveFrequency = 100; // 10 events a second times a second
TestWindow currentWindow = new TestWindow(program);
// Start the application.
program.Run(currentWindow);
}
}
}
-------------------------------------------------------------------------------------------------------------------------And then the window with the code to read the sensor:
using System;
using System.IO.Ports;
using System.Text;
using System.Threading;
using System.Net;
using System.Net.Sockets;
using System.Text;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT.Input;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using GHIElectronics.NETMF.Hardware;
using GHIElectronics.NETMF.FEZ;
namespace GHIGraphicalDemo.Presentation
{
public class TestWindow : Window
{
private Program _program;
private string temper1 = "Temperatuur 1: ";
private string temper2 = "Temperatuur 2: ";
private byte[] adress = new byte[8];
private ushort temperatuur;
private static OneWire ow = new OneWire((Cpu.Pin)FEZ_Pin.Digital.IO21);
private byte[] conT = new byte[1];
private byte[] readrom = new byte[1];
private byte[] rx = new byte[2];
private Bitmap screen = new Bitmap(SystemMetrics.ScreenWidth, SystemMetrics.ScreenHeight);
private Font ninaBFont = Resources.GetFont(Resources.FontResources.NinaB);
private Font smallFont = Resources.GetFont(Resources.FontResources.small);
private string[] lines = new string[12];
public TestWindow(Program program)
{
_program = program;
while (true)
{
ow.Reset(); //temperatuur converteren
ow.WriteByte(0xCC);
ow.WriteByte(0x44);
while (ow.ReadByte() == 0) ;
ow.Reset();
if (adress[0] == 0)
ow.Search_GetNextDevice(adress);
ow.Reset();
ow.Search_IsDevicePresent(adress);
ow.WriteByte(0xbe);
temperatuur = ow.ReadByte();
temperatuur |= (ushort)(ow.ReadByte() << 8);
temper1 = ("Temperatuur 1 :" + temperatuur / 16 + " °C");
ow.Search_GetNextDevice(adress);
ow.Reset();
ow.Search_IsDevicePresent(adress);
ow.WriteByte(0xbe);
temperatuur = ow.ReadByte();
temperatuur |= (ushort)(ow.ReadByte() << 8);
temper2 = ("Temperatuur 2 :" + temperatuur / 16 + " °C");
DrawSettings();
}
}
public override void OnRender(DrawingContext dc)
{
dc.DrawImage(screen, 0, 0);
}
private void DrawSettings()
{
screen.Clear();
screen.DrawText("Temperatuur in de kelder:", ninaBFont, Colors.Yellow, 8, 5);
//Text
//screen.DrawText(matchStr, ninaBFont, Colors.Yellow, 230, 65);
screen.DrawText(temper1, ninaBFont, Colors.Red, 5, 100);
screen.DrawText(temper2, ninaBFont, Colors.Red, 5, 150);
screen.DrawText("Project pelletkachel KLIM & ELO", ninaBFont, Colors.White, 5, screen.Height - 15);
screen.Flush();
}
}
}