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

Fixed Linux issues

parent a4f8701d
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
{
devs = FTDevice.getDevices(true);
// System.out.printf("FTDevice.getDevices() Found %d devices\n", devs.size());
}
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.
String serial = devRaw.getDevSerialNumber();
......
......@@ -3,6 +3,7 @@
<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="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"/>
</classpath>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
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.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.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6
......@@ -26,16 +26,19 @@ package com.ftdi;
import com.sun.jna.Library;
import com.sun.jna.Memory;
import com.sun.jna.Native;
import com.sun.jna.NativeLong;
import com.sun.jna.Platform;
import com.sun.jna.Pointer;
import com.sun.jna.Structure;
import com.sun.jna.ptr.ByteByReference;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.PointerByReference;
import com.sun.jna.ptr.ShortByReference;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;
......@@ -148,13 +151,12 @@ interface FTD2XX extends Library {
public int Type;
public int ID;
public int LocId;
public Memory SerialNumber = new Memory(16);
public Memory Description = new Memory(64);
public int ftHandle;
public byte[] SerialNumber = new byte[16];
public byte[] Description = new byte[64];
public Pointer ftHandle;
@Override
protected List<String> getFieldOrder() {
// TODO Auto-generated method stub
return null;
return Arrays.asList("Flags", "Type", "ID", "LocId", "SerialNumber", "Description", "ftHandle");
}
}
......@@ -774,7 +776,7 @@ interface FTD2XX extends Library {
int FT_GetDeviceInfoDetail(int dwIndex, IntByReference lpdwFlags,
IntByReference lpdwType, IntByReference lpdwID,
IntByReference lpdwLocId, Pointer pcSerialNumber,
Pointer pcDescription, IntByReference ftHandle);
Pointer pcDescription, PointerByReference ftHandle);
/**
* Gets information concerning the devices currently connected. This
......@@ -798,7 +800,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_Open(int iDevice, IntByReference ftHandle);
int FT_Open(int iDevice, PointerByReference ftHandle);
/**
* Open the specified device and return a handle that will be used for
......@@ -821,7 +823,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_OpenEx(Pointer pvArg1, int dwFlags, IntByReference ftHandle);
int FT_OpenEx(Pointer pvArg1, int dwFlags, PointerByReference ftHandle);
/**
* Close an open device.
......@@ -829,7 +831,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_Close(int ftHandle);
int FT_Close(Pointer ftHandle);
/**
* Read data from the device.
......@@ -842,7 +844,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_Read(int ftHandle, Pointer lpBuffer, int dwBytesToRead,
int FT_Read(Pointer ftHandle, Pointer lpBuffer, int dwBytesToRead,
IntByReference lpdwBytesReturned);
/**
......@@ -856,7 +858,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_Write(int ftHandle, Pointer lpBuffer, int dwBytesToWrite,
int FT_Write(Pointer ftHandle, Pointer lpBuffer, int dwBytesToWrite,
IntByReference lpdwBytesWritten);
/**
......@@ -866,7 +868,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_SetBaudRate(int ftHandle, int dwBaudRate);
int FT_SetBaudRate(Pointer ftHandle, int dwBaudRate);
/**
* This function sets the baud rate for the device. It is used to set
......@@ -878,7 +880,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_SetDivisor(int ftHandle, short usDivisor);
int FT_SetDivisor(Pointer ftHandle, short usDivisor);
/**
* This function sets the data characteristics for the device.
......@@ -892,7 +894,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_SetDataCharacteristics(int ftHandle, byte uWordLength,
int FT_SetDataCharacteristics(Pointer ftHandle, byte uWordLength,
byte uStopBits, byte uParity);
/**
......@@ -903,7 +905,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_SetTimeouts(int ftHandle, int dwReadTimeout, int dwWriteTimeout);
int FT_SetTimeouts(Pointer ftHandle, int dwReadTimeout, int dwWriteTimeout);
/**
* This function sets the flow control for the device.
......@@ -917,7 +919,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_SetFlowControl(int ftHandle, short usFlowControl, byte uXon,
int FT_SetFlowControl(Pointer ftHandle, short usFlowControl, byte uXon,
byte uXoff);
/**
......@@ -926,7 +928,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_SetDtr(int ftHandle);
int FT_SetDtr(Pointer ftHandle);
/**
* This function clears the Data Terminal Ready (DTR) control signal.
......@@ -934,7 +936,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_ClrDtr(int ftHandle);
int FT_ClrDtr(Pointer ftHandle);
/**
* This function sets the Request To Send (RTS) control signal.
......@@ -942,7 +944,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_SetRts(int ftHandle);
int FT_SetRts(Pointer ftHandle);
/**
* This function clears the Request To Send (RTS) control signal.
......@@ -950,7 +952,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_ClrRts(int ftHandle);
int FT_ClrRts(Pointer ftHandle);
/**
* Gets the modem status and line status from the device.
......@@ -960,7 +962,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_GetModemStatus(int ftHandle, IntByReference lpdwModemStatus);
int FT_GetModemStatus(Pointer ftHandle, IntByReference lpdwModemStatus);
/**
* Gets the number of bytes in the receive queue.
......@@ -970,7 +972,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_GetQueueStatus(int ftHandle, IntByReference lpdwAmountInRxQueue);
int FT_GetQueueStatus(Pointer ftHandle, IntByReference lpdwAmountInRxQueue);
/**
* Get device information for an open device.
......@@ -985,7 +987,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_GetDeviceInfo(int ftHandle, IntByReference pftType,
int FT_GetDeviceInfo(Pointer ftHandle, IntByReference pftType,
IntByReference lpdwID, Pointer pcSerialNumber, Pointer pcDescription,
Pointer pvDummy);
......@@ -996,7 +998,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_GetDriverVersion(int ftHandle, IntByReference lpdwDriverVersion);
int FT_GetDriverVersion(Pointer ftHandle, IntByReference lpdwDriverVersion);
/**
* This function returns D2XX DLL version number.
......@@ -1014,7 +1016,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_GetComPortNumber(int ftHandle, IntByReference lplComPortNumber);
int FT_GetComPortNumber(Pointer ftHandle, IntByReference lplComPortNumber);
/**
* Gets the device status including number of characters in the receive
......@@ -1030,7 +1032,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_GetStatus(int ftHandle, IntByReference lpdwAmountInRxQueue,
int FT_GetStatus(Pointer ftHandle, IntByReference lpdwAmountInRxQueue,
IntByReference lpdwAmountInTxQueue, IntByReference lpdwEventStatus);
/**
......@@ -1041,7 +1043,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_SetEventNotification(int ftHandle, int dwEventMask, Pointer pvArg);
int FT_SetEventNotification(Pointer ftHandle, int dwEventMask, Pointer pvArg);
/**
* This function sets the special characters for the device.
......@@ -1053,7 +1055,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_SetChars(int ftHandle, byte uEventCh, byte uEventChEn,
int FT_SetChars(Pointer ftHandle, byte uEventCh, byte uEventChEn,
byte uErrorCh, byte uErrorChEn);
/**
......@@ -1062,7 +1064,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_SetBreakOn(int ftHandle);
int FT_SetBreakOn(Pointer ftHandle);
/**
* Resets the BREAK condition for the device.
......@@ -1070,7 +1072,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_SetBreakOff(int ftHandle);
int FT_SetBreakOff(Pointer ftHandle);
/**
* This function purges receive and transmit buffers in the device.
......@@ -1079,7 +1081,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_Purge(int ftHandle, int dwMask);
int FT_Purge(Pointer ftHandle, int dwMask);
/**
* This function sends a reset command to the device.
......@@ -1087,7 +1089,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_ResetDevice(int ftHandle);
int FT_ResetDevice(Pointer ftHandle);
/**
* Send a reset command to the port.
......@@ -1095,7 +1097,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_ResetPort(int ftHandle);
int FT_ResetPort(Pointer ftHandle);
/**
* Send a cycle command to the USB port.
......@@ -1103,7 +1105,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_CyclePort(int ftHandle);
int FT_CyclePort(Pointer ftHandle);
/**
* This function can be of use when trying to recover devices
......@@ -1130,7 +1132,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_SetResetPipeRetryCount(int ftHandle, int dwCount);
int FT_SetResetPipeRetryCount(Pointer ftHandle, int dwCount);
/**
* Stops the driver's IN task.
......@@ -1138,7 +1140,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_StopInTask(int ftHandle);
int FT_StopInTask(Pointer ftHandle);
/**
* Restart the driver's IN task.
......@@ -1146,7 +1148,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_RestartInTask(int ftHandle);
int FT_RestartInTask(Pointer ftHandle);
/**
* This function allows the maximum time in milliseconds that a USB request
......@@ -1157,7 +1159,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_SetDeadmanTimeout(int ftHandle, int dwDeadmanTimeout);
int FT_SetDeadmanTimeout(Pointer ftHandle, int dwDeadmanTimeout);
/**
* Read a value from an EEPROM location.
......@@ -1167,7 +1169,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_ReadEE(int ftHandle, int dwWordOffset, ShortByReference lpwValue);
int FT_ReadEE(Pointer ftHandle, int dwWordOffset, ShortByReference lpwValue);
/**
* Write a value to an EEPROM location.
......@@ -1177,7 +1179,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_WriteEE(int ftHandle, int dwWordOffset, short wValue);
int FT_WriteEE(Pointer ftHandle, int dwWordOffset, short wValue);
/**
* Erases the device EEPROM.
......@@ -1185,7 +1187,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_EraseEE(int ftHandle);
int FT_EraseEE(Pointer ftHandle);
/**
* Read the contents of the EEPROM.
......@@ -1194,7 +1196,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_EE_Read(int ftHandle, FT_PROGRAM_DATA.ByReference pData);
int FT_EE_Read(Pointer ftHandle, FT_PROGRAM_DATA.ByReference pData);
/**
* Read the contents of the EEPROM and pass strings separately.
......@@ -1211,7 +1213,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_EE_ReadEx(int ftHandle, FT_PROGRAM_DATA.ByReference pData,
int FT_EE_ReadEx(Pointer ftHandle, FT_PROGRAM_DATA.ByReference pData,
String Manufacturer, String ManufacturerId, String Description,
String SerialNumber);
......@@ -1222,7 +1224,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_EE_Program(int ftHandle, FT_PROGRAM_DATA.ByReference pData);
int FT_EE_Program(Pointer ftHandle, FT_PROGRAM_DATA.ByReference pData);
/**
* Program the EEPROM and pass strings separately.
......@@ -1239,7 +1241,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_EE_ProgramEx(int ftHandle, FT_PROGRAM_DATA.ByReference pData,
int FT_EE_ProgramEx(Pointer ftHandle, FT_PROGRAM_DATA.ByReference pData,
String Manufacturer, String ManufacturerId,
String Description, String SerialNumber);
......@@ -1251,7 +1253,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_EE_UASize(int ftHandle, IntByReference lpdwSize);
int FT_EE_UASize(Pointer ftHandle, IntByReference lpdwSize);
/**
* Read the contents of the EEPROM user area.
......@@ -1265,7 +1267,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_EE_UARead(int ftHandle, Pointer pucData, int dwDataLen,
int FT_EE_UARead(Pointer ftHandle, Pointer pucData, int dwDataLen,
IntByReference lpdwBytesRead);
/**
......@@ -1277,7 +1279,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_EE_UAWrite(int ftHandle, Pointer pucData, int dwDataLen);
int FT_EE_UAWrite(Pointer ftHandle, Pointer pucData, int dwDataLen);
/**
* Set the latency timer value.
......@@ -1287,7 +1289,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_SetLatencyTimer(int ftHandle, byte ucTimer);
int FT_SetLatencyTimer(Pointer ftHandle, byte ucTimer);
/**
* Get the current value of the latency timer.
......@@ -1296,7 +1298,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_GetLatencyTimer(int ftHandle, ByteByReference pucTimer);
int FT_GetLatencyTimer(Pointer ftHandle, ByteByReference pucTimer);
/**
* Enables different chip modes.
......@@ -1323,7 +1325,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_SetBitMode(int ftHandle, byte ucMask, byte ucMode);
int FT_SetBitMode(Pointer ftHandle, byte ucMask, byte ucMode);
/**
* Gets the instantaneous value of the data bus.
......@@ -1333,7 +1335,7 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_GetBitmode(int ftHandle, ByteByReference pucMode);
int FT_GetBitmode(Pointer ftHandle, ByteByReference pucMode);
/**
* Set the USB request transfer size.
......@@ -1343,6 +1345,6 @@ interface FTD2XX extends Library {
* @return FT_STATUS: FT_OK if successful, otherwise the return value is an
* FT error code.
*/
int FT_SetUSBParameters(int ftHandle, int dwInTransferSize,
int FT_SetUSBParameters(Pointer ftHandle, int dwInTransferSize,
int dwOutTransferSize);
}
......@@ -23,9 +23,13 @@
*/
package com.ftdi;
import com.ftdi.FTD2XX.FT_DEVICE_LIST_INFO_NODE;
import com.sun.jna.Memory;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.ByteByReference;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.PointerByReference;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
......@@ -35,6 +39,8 @@ import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import nl.nikhef.tools.Utils;
/**
* Java class to communicate easily to a FTDI device.
* @author Peter Kocsis <p. kocsis. 2. 7182 at gmail.com>
......@@ -44,14 +50,14 @@ public class FTDevice {
static private final FTD2XX ftd2xx = FTD2XX.INSTANCE;
private final int devID, devLocationID, flag;
private final DeviceType devType;
private int ftHandle;
private Pointer ftHandle;
private final String devSerialNumber, devDescription;
private FTDeviceInputStream fTDeviceInputStream = null;
private FTDeviceOutputStream fTDeviceOutputStream = null;
private boolean open = false;
private FTDevice(DeviceType devType, int devID, int devLocationID,
String devSerialNumber, String devDescription, int ftHandle,
String devSerialNumber, String devDescription, Pointer ftHandle,
int flag) {
this.devType = devType;
this.devID = devID;
......@@ -126,14 +132,14 @@ public class FTDevice {
@Override
public int hashCode() {
int hash = 5;
hash = 97 * hash + this.ftHandle;
hash = 97 * hash + this.ftHandle.hashCode();
return hash;
}
@Override
public String toString() {
return "FTDevice{" + "devDescription=" + devDescription
+ ", devSerialNumber=" + devSerialNumber + '}';
+ ", devSerialNumber=" + devSerialNumber + "devLocationId=" + devLocationID + '}';
}
private static void ensureFTStatus(int ftstatus) throws FTD2XXException {
......@@ -147,7 +153,7 @@ public class FTDevice {
IntByReference devType = new IntByReference();
IntByReference devID = new IntByReference();
IntByReference locID = new IntByReference();
IntByReference ftHandle = new IntByReference();
PointerByReference ftHandle = new PointerByReference();
Memory devSerNum = new Memory(16);
Memory devDesc = new Memory(64);
......@@ -182,9 +188,10 @@ public class FTDevice {
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);
//device is occupied?
if (isIncludeOpenedDevices) {
devs.add(device);
} else {
......@@ -192,17 +199,37 @@ public class FTDevice {
devs.add(device);
}
}
}
Logger.getLogger(FTDevice.class.getName()).log(Level.FINE,
"Found devs: {0} (All:{1})",
new Object[]{devs.size(), devNum.getValue()});
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.
* @param description Filtering option, exact match need.
* @return List contain available FTDI devices.
......@@ -302,7 +329,7 @@ public class FTDevice {
public void open() throws FTD2XXException {
Memory memory = new Memory(16);
memory.setString(0, devSerialNumber);
IntByReference handle = new IntByReference();
PointerByReference handle = new PointerByReference();
ensureFTStatus(ftd2xx.FT_OpenEx(memory, FTD2XX.FT_OPEN_BY_SERIAL_NUMBER,
handle));
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