FEZ Domino serial communication conundrum

Has anyone here tried connecting the fingerprint reader from Aratek to a Domino? or to any other NETMF device?

I’m having some major troubles.

Firstly i made it work, it scanned my fingerprint, it enrolled me in its own database and could basically authenticate me. But then it just stopped… every time i send the scan command it does nothing and after a couple of sends it raises a serial port error.

I thought… well… it’s my code… it’s faulty somehow.
And i redone just the scanning part of the code… now every time i send the scan command GC comes in and erases everything… the command itself isn’t even issued correctly because the GC comes and closes the serial connection(or so i think).

I’m having trouble figuring out if it’s the problem from the Aratek device or from the Domino or from my code.

If anyone else had this problem, not necessarily with the Aratek device but with any other serial device it would be very helpful at least i would know in what direction to go.

Any suggestions are highly appreciated!!!

Thanks.

PS:

  1. the Domino has the latest firmware
  2. i have the latest .NETMF
  3. i’m using Visual Studio 2010 Professional Edition
  4. Serial out communication seems to work just fine with a serial LCD
  5. cables are all working just fine, tested them with a multimeter.

Post your code please (and use the code tags).
It’s hard to help without seeing your code.

when the simplest things don’t work, then there’s a good chance that this is an issue in code. ( :wink: )

here’s a simple test: depending on how that device connects (I am assuming this is just a serial device over USB, I haven’t looked at this biometric manufacturer before) just output the same serial stream you are attempting to send to the device but route that through to a PC and see what it sees. If the PC isn’t getting the right commands, then it will never work when connected to the reader.

Serial ports are the most used interface so I doubt there is a problem in it

I will post the code as soon as possible… till then, it’s not an usb device, I’m using the com1 pins on the fez, also tried with the com2 pins on uext and nothing…

Remember to always post as many info as possible. Photos, source code, videos, schematics will tell us often more than even fully detailed explanation.

Okay… so as promissed here is the code:


static SerialPort fingerPrint;
        static bool readerSentData = false;
        public static void Main()
        {
            Debug.EnableGCMessages(false);
            fingerPrint = new SerialPort("COM2", 57600, Parity.None, 8, StopBits.One);

            fingerPrint.Open();

            fingerPrint.DataReceived += new SerialDataReceivedEventHandler(fingerPrint_DataReceived);
            fingerPrint.ErrorReceived += new SerialErrorReceivedEventHandler(fingerPrint_ErrorReceived);
            //while (!readerSentData)
            //{
                SendData(HexToByte("EF01FFFFFFFF01000316001A")); //this is the command to read system parameters
            //}

            Thread.Sleep(Timeout.Infinite);
        }

        static void fingerPrint_ErrorReceived(object sender, SerialErrorReceivedEventArgs e)
        {
            Debug.Print("Serial error");
        }

        static void fingerPrint_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            int bytesToRead = fingerPrint.BytesToRead;
            byte[] readBytes = new byte[bytesToRead];
            fingerPrint.Read(readBytes, 0, bytesToRead);
            string strReceived = ByteToHex(readBytes);
            readerSentData = strReceived.ToUpper().IndexOf("070003000A") > -1;
            Debug.Print(strReceived);
        }

        private static byte[] HexToByte(string hex)
        {
            int NumberChars = hex.Length;
            byte[] bytes = new byte[NumberChars / 2];
            for (int i = 0; i < NumberChars; i += 2)
                bytes[i / 2] = (byte)Convert.ToInt32(hex.Substring(i, 2), 16);
            
            return bytes;
        }

        private static string ByteToHex(byte[] data)
        {
            char[] lookup = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
            int i = 0, p = 2, l = data.Length;
            char[] c = new char[l * 2 + 2];
            byte d; c[0] = '0'; c[1] = 'x';
            while (i < l)
            {
                d = data[i++];
                c[p++] = lookup[d / 0x10];
                c[p++] = lookup[d % 0x10];
            }
            return new string(c, 2, c.Length - 2);
        }

        private static void SendData(byte[] data)
        {
            Debug.Print("Sending: " + ByteToHex(data));
            fingerPrint.Write(data, 0, data.Length);
            Thread.Sleep(100);
        }

So here it is…

After i send the command to read sys parameters it replies with the system parameters and then errors.

Are you assuming that when you get the DataReceived event all the data in a message is available?

You can not make that assumtion. You need to assemble the message yourself.

Indeed i encountered this problem a while ago and i fixed it.
This is just s snippet of the full application.
With this i’m just tryin to figure out what’s wrong.
This is just a dummy app.

The problem isn’t that i’m receiving the wrong response, the problem is that when i send the scan command i do not receive a response at all.

The application sends multiple scan commands and then it throws NullReferenceException.

In the case bellow i managed to see that every time i send the scan command it calls GC… and then throws NullReferenceException.

so lets be clear here. Null Reference Exception is a sure sign that the structure of your app is wrong and causing this. You need to show us the code that REPROS THIS behaviour. Is that this code above? If not, diagnosing a piece of code that doesn’t show the error you want diagnosed isn’t going to get us very far.

The code itself is that with a minor modification on the command i send. Thta’s the command for reading system parameters, the one that gets me the error is


while (!readerSentData)
            {
                SendData(HexToByte("EF01FFFFFFFF010003010005"));
            }

But… you won’t believe this.

I returned this morning to my laptop just to see if by any chance the reader started working…
And… it worked… i don’t know why… i don’t know how… but it just did…
and now it works…
And i swear i did NOT make any changes to the code, or to the wiring or to anything… i just plugged it in… pressed F5 (Visual Studio broke down and restarted) and it worked…

woo hoo. I always thought tempramental code just needed 24 hours in the naughty corner to cool down and behave properly :slight_smile:

This is not good… at all… what if it decides to misbehave exactly when i need to present my project?
I’ll be basically f***ed…

ok, so post your full code somewhere. We can cast an eye on it to see if you’ve made obvious things that might cause null refs, and then you can fix them if they exist. Or we say yep, looks right, and then you have to live in fear of a lurking weirdness coming back and bite you in the a$$ at demo time.