Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading;
- using Microsoft.SPOT;
- using Microsoft.SPOT.Presentation;
- using Microsoft.SPOT.Presentation.Controls;
- using Microsoft.SPOT.Presentation.Media;
- using Microsoft.SPOT.Touch;
- using Gadgeteer.Networking;
- using GT = Gadgeteer;
- using GTM = Gadgeteer.Modules;
- using Gadgeteer.Modules.GHIElectronics;
- namespace Gadgeteer_RFID_Reader_02
- {
- public partial class Program
- {
- GT.Interfaces.Serial mySerial;
- //GT.Interfaces.DigitalOutput enablePin;
- GT.Timer timer = new GT.Timer(1000, GT.Timer.BehaviorType.RunContinuously);
- // This method is run when the mainboard is powered up or reset.
- void ProgramStarted()
- {
- timer.Tick += new GT.Timer.TickEventHandler(timer_Tick);
- timer.Start();
- // create a reference to the Mainboard socket
- GT.Socket socket = GT.Socket.GetSocket(4, false, null, null);
- // create a DigitalOutput pin on that socket and turn it high for 'off'
- //enablePin = new GT.Interfaces.DigitalOutput(socket, GT.Socket.Pin.Three, true, null);
- // create a Serial interface on that socket that reads at 2400
- mySerial = new GT.Interfaces.Serial(socket, 9600, GT.Interfaces.Serial.SerialParity.None, GT.Interfaces.Serial.SerialStopBits.One, 8, GT.Interfaces.Serial.HardwareFlowControl.NotRequired, null);
- // it has been preset to be pin 4 for TX and pin 5 for RX
- // create an event handeling robot for the serial pin
- mySerial.DataReceived += new GT.Interfaces.Serial.DataReceivedEventHandler(mySerial_DataReceived);
- // open the serial connection
- mySerial.Open();
- // use a button to turn the RFID reader on by swittching the pin low of 'on'
- //button.ButtonPressed += new Button.ButtonEventHandler(button_ButtonPressed);
- // tell everyone that we are moving
- Debug.Print("Program Started");
- }
- void timer_Tick(GT.Timer timer)
- {
- //enablePin.Write(false);
- mySerial.Write("!RW");
- mySerial.Write(0x01);
- mySerial.Write(0x33);
- //mySerial.Write(0x03);
- //mySerial.Write(0x04);
- //mySerial.Write(0x05);
- Debug.Print("Reader Started");
- }
- void mySerial_DataReceived(GT.Interfaces.Serial sender, System.IO.Ports.SerialData data)
- {
- byte[] serialDataArray = new byte[5];
- mySerial.Read(serialDataArray, 0, 5);
- Debug.Print(serialDataArray[0].ToString());
- Debug.Print(serialDataArray[1].ToString());
- Debug.Print(serialDataArray[2].ToString());
- Debug.Print(serialDataArray[3].ToString());
- Debug.Print(serialDataArray[4].ToString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment