use of com.neuronrobotics.sdk.genericdevice.GenericDevice in project java-bowler by NeuronRobotics.
the class PingSpeedTest method main.
/**
* @param args
*/
public static void main(String[] args) {
// BowlerAbstractConnection c = new SerialConnection("/dev/DyIO0");
// BowlerAbstractConnection c = new SerialConnection("COM65");
BowlerAbstractConnection c = ConnectionDialog.promptConnection();
// }
if (c == null)
System.exit(1);
System.out.println("Starting test");
// Log.enableInfoPrint();
GenericDevice dev = new GenericDevice(c);
dev.connect();
long start;
double avg = 0;
int i;
avg = 0;
dev.ping();
for (i = 1; i < 5000000 && dev.isAvailable(); i++) {
start = System.currentTimeMillis();
dev.ping();
double ms = System.currentTimeMillis() - start;
avg += ms;
System.out.println("Average cycle time: " + (int) (avg / i) + "ms\t\t\t this loop was: " + ms);
dev.getNamespaces();
}
System.out.println("Average cycle time for ping: " + (avg / i) + " ms");
dev.disconnect();
System.exit(0);
}
use of com.neuronrobotics.sdk.genericdevice.GenericDevice in project java-bowler by NeuronRobotics.
the class DeviceManager method addConnection.
public static void addConnection(BowlerAbstractConnection connection) {
if (connection == null) {
return;
}
GenericDevice gen = new GenericDevice(connection);
try {
if (!gen.connect()) {
throw new InvalidConnectionException("Connection is invalid");
}
if (!gen.ping(true)) {
throw new InvalidConnectionException("Communication failed");
}
} catch (Exception e) {
// connection.disconnect();
ThreadUtil.wait(1000);
BowlerDatagram.setUseBowlerV4(false);
if (!gen.connect()) {
throw new InvalidConnectionException("Connection is invalid");
}
if (!gen.ping()) {
connection = null;
throw new InvalidConnectionException("Communication failed");
}
throw new RuntimeException(e);
}
if (gen.hasNamespace("neuronrobotics.dyio.*")) {
DyIO dyio = new DyIO(gen.getConnection());
dyio.connect();
String name = "dyio";
addConnection(dyio, name);
} else if (gen.hasNamespace("bcs.cartesian.*")) {
BowlerBoardDevice delt = new BowlerBoardDevice();
delt.setConnection(gen.getConnection());
delt.connect();
String name = "bowlerBoard";
addConnection(delt, name);
addConnection(new NRPrinter(delt), "cnc");
} else if (gen.hasNamespace("bcs.pid.*")) {
GenericPIDDevice delt = new GenericPIDDevice();
delt.setConnection(gen.getConnection());
delt.connect();
String name = "pid";
addConnection(delt, name);
} else if (gen.hasNamespace("bcs.bootloader.*") || gen.hasNamespace("neuronrobotics.bootloader.*")) {
NRBootLoader delt = new NRBootLoader(gen.getConnection());
String name = "bootloader";
addConnection(delt, name);
} else if (gen.hasNamespace("neuronrobotics.bowlercam.*")) {
BowlerCamDevice delt = new BowlerCamDevice();
delt.setConnection(gen.getConnection());
delt.connect();
String name = "bowlercam";
addConnection(delt, name);
} else {
addConnection(gen, "device");
}
}
use of com.neuronrobotics.sdk.genericdevice.GenericDevice in project java-bowler by NeuronRobotics.
the class SimpleConnection method main.
/**
* @param args
*/
public static void main(String[] args) {
SerialConnection s = null;
System.out.println("Connecting and disconnecting");
// Windows
// s=new SerialConnection("COM5");
// OSX
// s=new SerialConnection("/dev/tty.usbmodemfd13411");
// Linux
s = new SerialConnection("/dev/DyIO.74F726800079");
GenericDevice dyio = new GenericDevice(s);
// Log.enableDebugPrint(true);
dyio.connect();
double avg = 0;
long start = System.currentTimeMillis();
int i;
for (i = 0; i < 500; i++) {
dyio.ping();
double ms = System.currentTimeMillis() - start;
avg += ms;
start = System.currentTimeMillis();
}
System.out.println("Average cycle time for ping: " + (avg / i) + " ms");
dyio.disconnect();
System.exit(0);
// while(true);
}
use of com.neuronrobotics.sdk.genericdevice.GenericDevice in project java-bowler by NeuronRobotics.
the class SerialConnection method getConnectionByMacAddress.
public static SerialConnection getConnectionByMacAddress(MACAddress mac) {
List<String> ports = SerialConnection.getAvailableSerialPorts();
// Start by searching through all available serial connections for DyIOs connected to the system
for (String s : ports) {
System.out.println("Searching " + s);
}
for (String s : ports) {
try {
SerialConnection connection = new SerialConnection(s);
GenericDevice d = new GenericDevice(connection);
d.connect();
System.out.println("Pinging port: " + connection + " ");
if (d.ping()) {
String addr = d.getAddress().toString();
if (addr.equalsIgnoreCase(mac.toString())) {
connection.disconnect();
System.out.println("Device FOUND on port: " + connection + " " + addr);
return connection;
}
System.err.println("Device not on port: " + connection + " " + addr);
}
connection.disconnect();
} catch (Exception EX) {
EX.printStackTrace();
System.err.println("Serial port " + s + " is not a DyIO");
}
}
return null;
}
Aggregations