unkwntech

Mainboard

Apr 12th, 2013
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.88 KB | None | 0 0
  1. using System;
  2. using System.Threading;
  3. using GoBus;
  4. using Microsoft.SPOT;
  5. using Microsoft.SPOT.Hardware;
  6.  
  7. namespace ProtoModule_Test
  8. {
  9.     public class Program
  10.     {
  11.         public static void Main()
  12.         {
  13.             ProtoModule PM = new ProtoModule();
  14.             Thread.Sleep(Timeout.Infinite);
  15.         }
  16.  
  17.     }
  18.  
  19.     public class ProtoModule : GoModule
  20.     {
  21.         private Guid _guid = new Guid(new byte[] {0x07, 0x22, 0x075, 0x073, 0x52, 0xA5, 0x48, 0x24, 0xBC, 0xC2, 0x55, 0x2F, 0x69, 0x88, 0xED, 0x3E});
  22.         private SPI _spi;
  23.         private SPI.Configuration _spiConfig;
  24.         private InterruptPort _irqPort;
  25.  
  26.         public ProtoModule()
  27.         {
  28.             GoSocket[] sockets = base.GetSocketsByUniqueId(this._guid);
  29.             if(sockets.Length < 1)
  30.             {
  31.                 throw new Exception("Unable to find ProtoModule");
  32.             }
  33.             this.Initialize(sockets[0]);
  34.         }
  35.  
  36.         private void Initialize(GoSocket socket)
  37.         {
  38.             Cpu.Pin socketGpioPin;
  39.             SPI.SPI_module socketSpiModule;
  40.             Cpu.Pin socketSpiSlaveSelectPin;
  41.             if (!base.BindSocket(socket, this._guid))
  42.             {
  43.                 throw new ArgumentException();
  44.             }
  45.             socket.GetPhysicalResources(out socketGpioPin, out socketSpiModule, out socketSpiSlaveSelectPin);
  46.             this._spiConfig = new SPI.Configuration(socketSpiSlaveSelectPin, false, 0, 0, false, false, 500, socketSpiModule);
  47.             this._spi = new SPI(this._spiConfig);
  48.             this._irqPort = new InterruptPort(socketGpioPin, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
  49.             this._irqPort.OnInterrupt += _irqPort_OnInterrupt;
  50.         }
  51.  
  52.         private void _irqPort_OnInterrupt(uint d1, uint d2, DateTime ts)
  53.         {
  54.             Debug.Print(ts.ToString());
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment