peony3000

Gadgeteer RFID 02

Jun 4th, 2012
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.89 KB | None | 0 0
  1. using System;
  2. using System.Threading;
  3. using Microsoft.SPOT;
  4. using Microsoft.SPOT.Presentation;
  5. using Microsoft.SPOT.Presentation.Controls;
  6. using Microsoft.SPOT.Presentation.Media;
  7. using Microsoft.SPOT.Touch;
  8.  
  9. using Gadgeteer.Networking;
  10. using GT = Gadgeteer;
  11. using GTM = Gadgeteer.Modules;
  12. using Gadgeteer.Modules.GHIElectronics;
  13.  
  14. namespace Gadgeteer_RFID_Reader_02
  15. {
  16.     public partial class Program
  17.     {
  18.         GT.Interfaces.Serial mySerial;
  19.         //GT.Interfaces.DigitalOutput enablePin;
  20.  
  21.         GT.Timer timer = new GT.Timer(1000, GT.Timer.BehaviorType.RunContinuously);
  22.         // This method is run when the mainboard is powered up or reset.  
  23.         void ProgramStarted()
  24.         {
  25.             timer.Tick += new GT.Timer.TickEventHandler(timer_Tick);
  26.             timer.Start();
  27.  
  28.             // create a reference to the Mainboard socket
  29.             GT.Socket socket = GT.Socket.GetSocket(4, false, null, null);
  30.             // create a DigitalOutput pin on that socket and turn it high for 'off'
  31.             //enablePin = new GT.Interfaces.DigitalOutput(socket, GT.Socket.Pin.Three, true, null);
  32.             // create a Serial interface on that socket that reads at 2400
  33.             mySerial = new GT.Interfaces.Serial(socket, 9600, GT.Interfaces.Serial.SerialParity.None, GT.Interfaces.Serial.SerialStopBits.One, 8, GT.Interfaces.Serial.HardwareFlowControl.NotRequired, null);
  34.             // it has been preset to be pin 4 for TX and pin 5 for RX
  35.             // create an event handeling robot for the serial pin
  36.            
  37.             mySerial.DataReceived += new GT.Interfaces.Serial.DataReceivedEventHandler(mySerial_DataReceived);
  38.             // open the serial connection
  39.             mySerial.Open();
  40.  
  41.             // use a button to turn the RFID reader on by swittching the pin low of 'on'
  42.             //button.ButtonPressed += new Button.ButtonEventHandler(button_ButtonPressed);
  43.  
  44.              // tell everyone that we are moving
  45.             Debug.Print("Program Started");
  46.         }
  47.  
  48.         void timer_Tick(GT.Timer timer)
  49.         {
  50.      
  51.             //enablePin.Write(false);
  52.            
  53.             mySerial.Write("!RW");
  54.             mySerial.Write(0x01);
  55.             mySerial.Write(0x33);
  56.             //mySerial.Write(0x03);
  57.             //mySerial.Write(0x04);
  58.             //mySerial.Write(0x05);
  59.             Debug.Print("Reader Started");
  60.         }
  61.  
  62.         void mySerial_DataReceived(GT.Interfaces.Serial sender, System.IO.Ports.SerialData data)
  63.         {
  64.             byte[] serialDataArray = new byte[5];
  65.             mySerial.Read(serialDataArray, 0, 5);
  66.             Debug.Print(serialDataArray[0].ToString());
  67.             Debug.Print(serialDataArray[1].ToString());
  68.             Debug.Print(serialDataArray[2].ToString());
  69.             Debug.Print(serialDataArray[3].ToString());
  70.             Debug.Print(serialDataArray[4].ToString());
  71.         }
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment