[chronojump-server] RFID script can receive a ID_SERIAL_SHORT. and only works with FTDI.
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump-server] RFID script can receive a ID_SERIAL_SHORT. and only works with FTDI.
- Date: Fri, 21 Jun 2019 15:24:01 +0000 (UTC)
commit f3bb1385149c196c5c6ca49e07f69179ef4225c5
Author: Xavier de Blas <xaviblas gmail com>
Date: Fri Jun 21 17:23:18 2019 +0200
RFID script can receive a ID_SERIAL_SHORT. and only works with FTDI.
chronojumpserver-django/rfid-csharp/RFID.cs | 97 ++++++++++++++++++++++++---
chronojumpserver-django/rfid-csharp/RFID.exe | Bin 5632 -> 6656 bytes
2 files changed, 88 insertions(+), 9 deletions(-)
---
diff --git a/chronojumpserver-django/rfid-csharp/RFID.cs b/chronojumpserver-django/rfid-csharp/RFID.cs
index a1838b5..48846e9 100755
--- a/chronojumpserver-django/rfid-csharp/RFID.cs
+++ b/chronojumpserver-django/rfid-csharp/RFID.cs
@@ -21,17 +21,18 @@ using System.Collections.Generic; //List<T>
using System.IO;
using System.IO.Ports;
using System.Threading;
+using System.Diagnostics;
public class RFIDMain
{
const string rfidFile = "/tmp/chronojump_rfid.txt";
- public static void Main()
+ public static void Main(string[] args)
{
//debug starts
string str = "Called RFIDMain. Writing at /tmp/rfidcalled.txt";
Console.WriteLine(str);
-
+
/*TextWriter writer = File.CreateText("/tmp/rfidcalled.txt");
writer.Write(str);
writer.Flush();
@@ -41,7 +42,11 @@ public class RFIDMain
removeFile();
- RFID rfid = new RFID();
+ string searchedDevice = "";
+ if(args.Length == 1)
+ searchedDevice = args[0];
+
+ RFID rfid = new RFID(searchedDevice);
RFID.StatusEnum status = rfid.Start();
if(status == RFID.StatusEnum.DETECTED) {
@@ -73,12 +78,19 @@ public class RFID
public enum StatusEnum { NO_PORTS, NO_RFID_PORT, NO_DETECTED, DETECTED };
public string Captured;
+
+ //if searchedDevice == "" returns the first FTDI
+ //else returns the FTDI device with this ID_SERIAL_SHORT
+ private string searchedDevice;
+ private string foundDevice;
+
private bool stop;
//public event EventHandler ChangedEvent; //raised when change RFID vaues
private SerialPort port;
- public RFID()
+ public RFID(string searchedDevice)
{
+ this.searchedDevice = searchedDevice;
Captured = "";
stop = false;
}
@@ -92,13 +104,10 @@ public class RFID
string str = "";
- /*
bool found = findRFIDPort(l);
if(! found)
return StatusEnum.NO_RFID_PORT;
- */
- //findRFIDPort() opens the port, but now is not called
port = new SerialPort(l[0], 9600); //for the rfid
port.Open();
@@ -147,14 +156,27 @@ public class RFID
return StatusEnum.DETECTED;
}
- /*
private bool findRFIDPort(List<string> l)
{
foreach(string p in l)
{
Console.WriteLine("portName: " + p);
+
+ foundDevice = "";
+ if(isFTDI(p))
+ {
+ if(searchedDevice == "")
+ return true;
+ else if(searchedDevice == foundDevice)
+ return true;
+ }
+
+ /* commented because it is slow, starting, waiting to arduino fully started to read
string ...
+
port = new SerialPort(p, 9600); //for the rfid
port.Open();
+
+ // this is the slow process
Thread.Sleep(2000); //sleep to let arduino start reading. Use 3000 if NO_RFID_PORT
if (port.BytesToRead > 0){
@@ -182,10 +204,67 @@ public class RFID
Console.WriteLine("Arduino RFID NOT found on port: " + p);
port.Close();
+ */
}
return(false);
}
- */
+
+
+ private bool isFTDI(string port)
+ {
+ Console.WriteLine("Checking if it is FTDI: " + port);
+
+ Process process = new Process();
+ ProcessStartInfo processStartInfo = new ProcessStartInfo();
+
+ //1) get path
+ processStartInfo.FileName = "udevadm";
+ processStartInfo.Arguments = "info -q path -n " + port;
+
+ //Console.WriteLine ("ExecuteProcess FileName: " + processStartInfo.FileName);
+ //Console.WriteLine ("ExecuteProcess Arguments: " + processStartInfo.Arguments);
+
+ processStartInfo.CreateNoWindow = true;
+ processStartInfo.UseShellExecute = false;
+ processStartInfo.RedirectStandardInput = false;
+ processStartInfo.RedirectStandardError = true;
+ processStartInfo.RedirectStandardOutput = true;
+
+ process.StartInfo = processStartInfo;
+ process.Start();
+
+ string path = process.StandardOutput.ReadToEnd().TrimEnd ('\n');
+ //Console.WriteLine ("path = " + path);
+
+ if (path == "")
+ return false;
+
+ //2) read FTDI info
+ processStartInfo.Arguments = "info -p " + path;
+ //Console.WriteLine ("ExecuteProcess Arguments: " + processStartInfo.Arguments);
+ process.StartInfo = processStartInfo;
+ process.Start();
+
+ string result = process.StandardOutput.ReadToEnd().TrimEnd ('\n');
+
+ if (result == "")
+ return false;
+
+ bool ftdi = false;
+ foreach (string lineOut in result.Split('\n'))
+ {
+ if (lineOut.Contains("ID_VENDOR=")) {
+ string [] strFull = lineOut.Split(new char[] {'='});
+ ftdi = (strFull[1] == "FTDI");
+ } else if (lineOut.Contains("ID_SERIAL_SHORT=")) {
+ string [] strFull = lineOut.Split(new char[] {'='});
+ Console.WriteLine("Serial number: " + strFull[1]);
+ foundDevice = strFull[1];
+ }
+ }
+
+ return ftdi;
+ }
private List<string> getPorts(bool debug)
{
diff --git a/chronojumpserver-django/rfid-csharp/RFID.exe b/chronojumpserver-django/rfid-csharp/RFID.exe
index 2228e49..5d9cc43 100755
Binary files a/chronojumpserver-django/rfid-csharp/RFID.exe and
b/chronojumpserver-django/rfid-csharp/RFID.exe differ
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]