Can you take a picture of your setup? We might have a better visual.
Could he be referencing pin IO29 â COM3 TX?

Could he be referencing pin IO29 â COM3 TX?
Possible. I think itâs best to see a picture of the setup.
@ WouterH - Iâm building the code on PC first. Thatâs why I am using COM29. Iâm trying to load the code from VS2010 to the reader.
Ah, and COM29 is a serial to USB cable?
@ cluemain, I donât think you will ever load code to the reader. If it is a âserial UARTâ device, like you inferred, then it is dumb and all you need to do is write code that then runs on either your PC or on your Fez, and the reader is connected to that device.
Com29 refers to a PC port; if you are writing a WPF application that is running on .Net on the PC, then that is the port you will use. If you are writing a Micro Framework app, then you canât run it on the emulator and expect it to work if you have the reader connected to COM29, you will have to deploy to real hardware and connect the reader to that; and then your COM port will be COM1-4 as the others mention.
What reader do you have, it might help us unravel how you should approach this.
It seems to me that the .Net dll the vendor is providing you is the API wrapper for the serial commands, like the driver for the reader posted earlier in the thread. So all you really need to do is figure out the serial commands to read and write between teh reader and Fez, and you get the capability you want.
@ Brett - HI Brett! Sorry for the term. Itâs just the first term that came across my mind. Thanks for correcting me.
Iâm using M6e reader module from ThingMagic.
Also, I am writing a MF Console Application. With this, I have to load the code on FEZ and use one of its COMs to connect them to reader, am I right?
If thatâs the case, then Debug.Print wonât help me check for the received response.
Again, thank you!
a MF Console application WILL still allow you to use debug.print it of course will only work when you have the debugger attached to the process, either after youâve hit F5 in Visual Studio, or youâve got MFDeploy attached to the board. What it would NEVER do would be to display the information on a screen, if you had one attachedâŚ
And yep youâre exactly right - attach the reader to the Fez, deploy your application to the Fez, and sit back and watch the bytes roll in !
@ Brett - Deploy your application -> it should be FEZ Cobra Window Application, right? (since I want to display something on screen)
But since this is a serial connection on reader and PC (for now), how should i declare the statement:
SerialPort UART = new SerialPort("COM29",115200);
If you are NOT creating a Micro Framework application (ie youâre creatinga WINDOWS .NET app) then you can declare it with COM29.
And if you want to create windows on your Cobra, then you need to use either a standard Cobra application and use Glide, or you need to choose a Cobra Windows template.
Hi!
I run this code on FEZ.
using System;
using System.Threading;
using GHIElectronics.NETMF.FEZ;
using Microsoft.SPOT;
using System.IO.Ports;
using Microsoft.SPOT.Input;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Touch;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;
namespace FEZ_Cobra_Window_Application3
{
public class Program : Microsoft.SPOT.Application
{
class LCD
{
public Bitmap LCDPanel = new Bitmap(SystemMetrics.ScreenWidth, SystemMetrics.ScreenHeight);
Font font = Resources.GetFont(Resources.FontResources.small);
public LCD()
{
LCDPanel.Clear();
LCDPanel.Flush();
}
public void ShowMessage(string text)
{
LCDPanel.Clear();
LCDPanel.DrawText(text, font, Colors.White, 0, 5);
LCDPanel.Flush();
}
}
public static void Main()
{
LCD lcd = new LCD();
lcd.ShowMessage("LCD Show some text");
byte[] data = new byte[] { 0x00, 0x40, 0xDF };
foreach(byte a in data)
{
lcd.ShowMessage(a.ToString());
Thread.Sleep(500);
}
for (int x = 0; x < 10; x++)
{
Thread.Sleep(500);
lcd.ShowMessage(x.ToString());
}
SerialPort UART = new SerialPort("COM1", 115200, Parity.None, 8, StopBits.None);
UART.Handshake = Handshake.None;
int read_count = 0;
byte[] b;
byte[] rx_data = new byte[50];
b = new byte[] { 0x0B, 0x1D, 0x04, 0x00, 0xFF };
var tx_data_boot = new byte[] { 0x0B, 0x1D, 0x04, 0x00, 0xFF };
UART.ReadTimeout = 0;
UART.Flush();
UART.Open();
UART.Write(b, 0, b.Length);
UART.Flush();
Thread.Sleep(100);
read_count = UART.Read(rx_data, 0, rx_data.Length);
if (read_count != 27)
{
Debug.Print("Wrong. You received" + read_count.ToString());
lcd.ShowMessage("Wrong. You received" + read_count.ToString());
}
for (int x = 0; x <= read_count; x++)
{
Debug.Print("Byte:" + rx_data[x]);
lcd.ShowMessage(rx_data[x].ToString());
}
Thread.Sleep(100);
UART.Close();
while (true)
{
}
}
}
}
However, this produced an error:
[quote]The thread ââ (0x2) has exited with code 0 (0x0).
#### Exception System.ArgumentException - 0xfd000000 (1) ####
#### Message:
#### System.IO.Ports.SerialPort::InternalOpen [IP: 0000] ####
#### System.IO.Ports.SerialPort::Open [IP: 0018] ####
#### FEZ_Cobra_Window_Application3.Program::Main [IP: 00d6] ####
A first chance exception of type âSystem.ArgumentExceptionâ occurred in Microsoft.SPOT.Hardware.SerialPort.dll
An unhandled exception of type âSystem.ArgumentExceptionâ occurred in Microsoft.SPOT.Hardware.SerialPort.dll[/quote]
The exception was brought by UART.Open();
What might be wrong?
without checking, I think your initial flush() before the open is at fault
UART.Flush();
UART.Open();
@ Brett - i removed the UART.Flush. same results.
@ cluemain - If you are still having problems break it down to simple steps.
Wire up the module as below image 1.
Then start a simple .net Microframework console app and add the below and make sure you change the deployment options under the project properties to USB image 2.
Make sure you have added the necessary references
image 3
.
When you wave your card in front of the reader does anything appear in the output window of Visual Studio?
using System.IO.Ports;
using System.Text;
using System.Threading;
using Microsoft.SPOT;
namespace MFConsoleApplication1
{
public class Program
{
private static SerialPort _serialPort;
private static string _rfidCruft;
public static void Main()
{
_serialPort = new SerialPort("COM3", 9600, Parity.None, 8, StopBits.None);
_serialPort.DataReceived += new SerialDataReceivedEventHandler(SerialPortDataReceived);
Thread.Sleep(Timeout.Infinite);
}
static void SerialPortDataReceived(object sender, SerialDataReceivedEventArgs e)
{
int bytestoread = _serialPort.BytesToRead;
byte[] response = new byte[bytestoread];
_serialPort.Read(response, 0, bytestoread);
_rfidCruft = new string(Encoding.UTF8.GetChars(response));
Debug.Print(_rfidCruft);
}
}
}
PS might need to change the serial port details to the correct speed, parity etc.
@ Justin - Thanks! The port doesnt open due to unconnected 5V. I thought it is already ok since I used power adaptor to âpower the module upâ. Thanks
@ cluemain - I missed a lineâŚ
Line before _serialPort.Data⌠Add _serialPort.Open()