Commit 98f13730 authored by Vincent van Beveren's avatar Vincent van Beveren

Fixed Linux issues

parent a4f8701d
SFP-PLUS-I2C SFP-PLUS-I2C
------------ ============
Running on Ubuntu
=================
To run SaFariPark on Ubuntu two things need to happen:
1) The rights of the FTDI device must be relaxed such that any use has read and write permissions
2) the ftdi_sio driver must be prevented from loading, as it will interfere with opening the device
Relaxing driver rights
----------------------
Create a file named 90-ftdi in /etc/udev/rules.d/ and put in the following statement:
SUBSYSTEM=="usb", ATTRS{idVendor}=="0403", MODE="0666"
Prevent loading of the ftdi_sio driver
--------------------------------------
Edit the file /etc/modprobe.d/blacklist.conf and append the following line:
blacklist ftdi_sio
Note: This will prevent any FTDI based device from being loaded as a USB serial converted.
...@@ -46,12 +46,16 @@ public class MultiSFPProvider extends SFPProviderBase ...@@ -46,12 +46,16 @@ public class MultiSFPProvider extends SFPProviderBase
{ {
devs = FTDevice.getDevices(true); devs = FTDevice.getDevices(true);
// System.out.printf("FTDevice.getDevices() Found %d devices\n", devs.size());
} }
for (FTDevice devRaw : devs) for (FTDevice devRaw : devs)
{ {
if (devRaw.getDevType() == DeviceType.DEVICE_2232H && devRaw.getDevDescription().equals("MultiSFP A")) {
// System.out.println("Device: " + devRaw);
// XXX On Linux the MultiSFP A is descriptor is not generated once opened. But B remains. So we sync on that.
//
if (devRaw.getDevType() == DeviceType.DEVICE_2232H && devRaw.getDevDescription().equals("MultiSFP B")) {
// Only get the primary 'A' device, we know the second. // Only get the primary 'A' device, we know the second.
String serial = devRaw.getDevSerialNumber(); String serial = devRaw.getDevSerialNumber();
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="src" path="/nikhef-tools"/> <classpathentry kind="src" path="/nikhef-tools"/>
<classpathentry kind="lib" path="lib/jna-4.3.0.jar"/> <classpathentry kind="lib" path="lib/jna-4.4.0.jar"/>
<classpathentry kind="lib" path="lib/jna-platform-4.4.0.jar"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6 org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6 org.eclipse.jdt.core.compiler.source=1.6
This diff is collapsed.
...@@ -23,9 +23,13 @@ ...@@ -23,9 +23,13 @@
*/ */
package com.ftdi; package com.ftdi;
import com.ftdi.FTD2XX.FT_DEVICE_LIST_INFO_NODE;
import com.sun.jna.Memory; import com.sun.jna.Memory;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.ByteByReference; import com.sun.jna.ptr.ByteByReference;
import com.sun.jna.ptr.IntByReference; import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.PointerByReference;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
...@@ -35,6 +39,8 @@ import java.util.List; ...@@ -35,6 +39,8 @@ import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import nl.nikhef.tools.Utils;
/** /**
* Java class to communicate easily to a FTDI device. * Java class to communicate easily to a FTDI device.
* @author Peter Kocsis <p. kocsis. 2. 7182 at gmail.com> * @author Peter Kocsis <p. kocsis. 2. 7182 at gmail.com>
...@@ -44,14 +50,14 @@ public class FTDevice { ...@@ -44,14 +50,14 @@ public class FTDevice {
static private final FTD2XX ftd2xx = FTD2XX.INSTANCE; static private final FTD2XX ftd2xx = FTD2XX.INSTANCE;
private final int devID, devLocationID, flag; private final int devID, devLocationID, flag;
private final DeviceType devType; private final DeviceType devType;
private int ftHandle; private Pointer ftHandle;
private final String devSerialNumber, devDescription; private final String devSerialNumber, devDescription;
private FTDeviceInputStream fTDeviceInputStream = null; private FTDeviceInputStream fTDeviceInputStream = null;
private FTDeviceOutputStream fTDeviceOutputStream = null; private FTDeviceOutputStream fTDeviceOutputStream = null;
private boolean open = false; private boolean open = false;
private FTDevice(DeviceType devType, int devID, int devLocationID, private FTDevice(DeviceType devType, int devID, int devLocationID,
String devSerialNumber, String devDescription, int ftHandle, String devSerialNumber, String devDescription, Pointer ftHandle,
int flag) { int flag) {
this.devType = devType; this.devType = devType;
this.devID = devID; this.devID = devID;
...@@ -126,14 +132,14 @@ public class FTDevice { ...@@ -126,14 +132,14 @@ public class FTDevice {
@Override @Override
public int hashCode() { public int hashCode() {
int hash = 5; int hash = 5;
hash = 97 * hash + this.ftHandle; hash = 97 * hash + this.ftHandle.hashCode();
return hash; return hash;
} }
@Override @Override
public String toString() { public String toString() {
return "FTDevice{" + "devDescription=" + devDescription return "FTDevice{" + "devDescription=" + devDescription
+ ", devSerialNumber=" + devSerialNumber + '}'; + ", devSerialNumber=" + devSerialNumber + "devLocationId=" + devLocationID + '}';
} }
private static void ensureFTStatus(int ftstatus) throws FTD2XXException { private static void ensureFTStatus(int ftstatus) throws FTD2XXException {
...@@ -147,7 +153,7 @@ public class FTDevice { ...@@ -147,7 +153,7 @@ public class FTDevice {
IntByReference devType = new IntByReference(); IntByReference devType = new IntByReference();
IntByReference devID = new IntByReference(); IntByReference devID = new IntByReference();
IntByReference locID = new IntByReference(); IntByReference locID = new IntByReference();
IntByReference ftHandle = new IntByReference(); PointerByReference ftHandle = new PointerByReference();
Memory devSerNum = new Memory(16); Memory devSerNum = new Memory(16);
Memory devDesc = new Memory(64); Memory devDesc = new Memory(64);
...@@ -182,9 +188,10 @@ public class FTDevice { ...@@ -182,9 +188,10 @@ public class FTDevice {
ArrayList<FTDevice> devs = new ArrayList<FTDevice>(devNum.getValue()); ArrayList<FTDevice> devs = new ArrayList<FTDevice>(devNum.getValue());
for (int i = 0; i < devNum.getValue(); i++) { for (int i = 0; i < devNum.getValue(); i++)
{
FTDevice device = getXthDevice(i); FTDevice device = getXthDevice(i);
//device is occupied?
if (isIncludeOpenedDevices) { if (isIncludeOpenedDevices) {
devs.add(device); devs.add(device);
} else { } else {
...@@ -192,17 +199,37 @@ public class FTDevice { ...@@ -192,17 +199,37 @@ public class FTDevice {
devs.add(device); devs.add(device);
} }
} }
} }
Logger.getLogger(FTDevice.class.getName()).log(Level.FINE, Logger.getLogger(FTDevice.class.getName()).log(Level.FINE,
"Found devs: {0} (All:{1})", "Found devs: {0} (All:{1})",
new Object[]{devs.size(), devNum.getValue()}); new Object[]{devs.size(), devNum.getValue()});
return devs; return devs;
} }
private static String fromNullTerminated(byte[] array)
{
for (int i = 0; i < array.length; i++)
{
if (array[i] == 0) {
return new String(array, 0, i);
}
}
return new String(array);
}
/** private static FTDevice getFromInfoNode(FT_DEVICE_LIST_INFO_NODE info) {
return new FTDevice(DeviceType.values()[info.Type],
info.ID, info.LocId, fromNullTerminated(info.SerialNumber),
fromNullTerminated(info.Description), info.ftHandle, info.Flags);
}
/**
* Get the connected FTDI devices. It will not contain opened devices. * Get the connected FTDI devices. It will not contain opened devices.
* @param description Filtering option, exact match need. * @param description Filtering option, exact match need.
* @return List contain available FTDI devices. * @return List contain available FTDI devices.
...@@ -302,7 +329,7 @@ public class FTDevice { ...@@ -302,7 +329,7 @@ public class FTDevice {
public void open() throws FTD2XXException { public void open() throws FTD2XXException {
Memory memory = new Memory(16); Memory memory = new Memory(16);
memory.setString(0, devSerialNumber); memory.setString(0, devSerialNumber);
IntByReference handle = new IntByReference(); PointerByReference handle = new PointerByReference();
ensureFTStatus(ftd2xx.FT_OpenEx(memory, FTD2XX.FT_OPEN_BY_SERIAL_NUMBER, ensureFTStatus(ftd2xx.FT_OpenEx(memory, FTD2XX.FT_OPEN_BY_SERIAL_NUMBER,
handle)); handle));
this.ftHandle = handle.getValue(); this.ftHandle = handle.getValue();
......
package nl.nikhef.rebus.ftdi;
import com.ftdi.FTD2XXException;
import com.ftdi.FTDevice;
public class TestBinding {
public static void main(String[] args) throws FTD2XXException {
for (FTDevice dev: FTDevice.getDevices())
{
System.out.println(dev);
dev.open();
dev.write(0);
dev.close();
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment