// Data Link analyzer for .NET Micro Framework // Written by: Pavel Bansky // http://bansky.net // This code was written to analyze traffic between // PICAXE 18X micro controller and DS18B20 thermometer using System; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; using EmbeddedFusion.SPOT.Hardware; using System.Threading; namespace LinkAnalyzer { public class Program { public static void Main() { LinkListener linkListener = new LinkListener(); // Power supply port for analyzed devices OutputPort powerSupply = new OutputPort(Meridian.Pins.GPIO13, false); // Stabilizing wait Thread.Sleep(2000); // Start listening to communication linkListener.Start(); // Power up the PICAXE device powerSupply.Write(true); // Wait while sampling while (linkListener.Running) { } // Print the sample results linkListener.Print(); } } public class LinkListener { InterruptPort listener; DataRecord[] recordArray = new DataRecord[255]; int dataIndex = 0; // Identifies that analyzer is running public bool Running = false; // Start analyzer public void Start() { dataIndex = 0; Running = true; // Interrupt port where the analyzer listens listener = new InterruptPort(Meridian.Pins.GPIO14, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth); listener.OnInterrupt += new GPIOInterruptEventHandler(listener_OnInterrupt); } // Stop analyzer public void Stop() { Running = false; listener.OnInterrupt -= new GPIOInterruptEventHandler(listener_OnInterrupt); //listener.Dispose(); } // Print results public void Print() { for (int i = 0; i < dataIndex; i++) { // Determines how long the status was present on the line long divval = (recordArray[i+1].Time - recordArray[i].Time) / 10; Debug.Print(i.ToString()+"| "+recordArray[i].State.ToString() + ", " + divval.ToString()); } } // Catch all changes on the line void listener_OnInterrupt(Cpu.Pin port, bool state, TimeSpan time) { DataRecord d = new DataRecord(); d.State = state; d.Time = time.Ticks; // Add data into recordArray recordArray[dataIndex++] = d; // Stop after 110 samples !! Change for your needs !! if (dataIndex > 110) Stop(); } } // Struct for records public struct DataRecord { public bool State; public long Time; } }