Апр 252012
 

using System;
using System.Threading;

using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Hardware;

namespace iButton
{
public class Program
{
static OneWire ow = new OneWire((Cpu.Pin)FEZ_Pin.Digital.Di4);
static OutputPort led = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, false);

public static void Main()
{
bool ledState = false;

while (true)
{
byte[] readall = new byte[8];

if (ow.Search_GetNextDevice(readall))
{
string hex = ByteArrayToString(readall);
Debug.Print("========================");
if (readall[0] != 0x01)
{
Debug.Print("Device is not a DS1990A family device.");
}
Debug.Print(hex);

for (int i = 0; i < 6; i++)
{
Thread.Sleep(200);
ledState = !ledState;
led.Write(ledState);
}
}
}
}

public static string ByteArrayToString(byte[] ba)
{
string hex = string.Empty;
for (int i = ba.Length - 1; i >= 0; i--)
{
hex += " " + ByteToHex(ba[i]);
}

return hex;
}

public static string ByteToHex(byte b)
{
const string hex = "0123456789ABCDEF";
int lowNibble = b & 0x0F;
int highNibble = (b & 0x0F0) >> 4;
string s = new string(new char[] { hex[highNibble], hex[lowNibble] });

return s;
}
}
}

 Posted by at 13:42

 Leave a Reply

(required)

(required)


девять × = 18

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>