Best Answer Nevyn, 03 January 2014 - 03:48 PM
I would look at adding the UART code to the RFID something ike the following:
//UART Project codesusing System;using System.Net;using System.Net.Sockets;using System.Threading;using Microsoft.SPOT;using SecretLabs.NETMF.Hardware;using SecretLabs.NETMF.Hardware.Netduino;using System.IO.Ports;namespace UART{ public class Program { static SerialPort serialPortUART = new SerialPort(SerialPorts.COM2, 9600, Parity.None, 8, StopBits.One); private static void sendDataUsingCOMPort(string _string) { byte[] data = System.Text.Encoding.UTF8.GetBytes(_string + "n"); serialPortUART.Open(); serialPortUART.Write(data, 0, data.Length); serialPortUART.Flush(); serialPortUART.Close(); } public static void Main() { SerialPort serialPort = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One); string id; serialPort.Open(); while (true) { int bytesToRead = serialPort.BytesToRead; if (bytesToRead > 0) { // get the waiting data byte[] buffer = new byte[bytesToRead]; serialPort.Read(buffer, 0, buffer.Length); // print out our received data id = new String(System.Text.Encoding.UTF8.GetChars(buffer)); sendDataUsingCOMPort(id); Debug.Print(id); } Thread.Sleep(100); // wait a bit so we get a few bytes at a time… } } }}
BTW - as I don't have a reader I have not had the chance to test this.
Also, this is not the most efficient way or reading from a serial port. I'd suggest that you look at using interrupts and assembling a string. You will need to work out when you have a "complete" buffer of data before tranmitting to then Windows app.
Hope this helps,
Mark
Go to the full post