I can't get analog IO to work with javaclient2
I have a Phidget interface kit.
LV-MaxSonar -EZ1s
I can get it to work under C++ but not Java. I couldn't find an example for
doing analog IO. I am probably doing something wrong. See below for working
C++ and not working Java code (annotations embedded with *** prefix). The
player cfg file is also listed.
Player 2.1.0rc1
Javaclient2 2.0.1
Java version 6 update 5 1.6.0-05
Fedora core 5
Eclipse 3.1.2
C++ code
---------------------------------------------------------------------
#include <iostream>
#include <libplayerc++/playerc++.h>
int
main(int argc, char *argv[])
{
using namespace PlayerCc;
PlayerClient robot("localhost");
AioProxy ap(&robot,0);
int i = 0;
// Read the 8 digital inputs
for(i=0; i<30; i++)
{
robot.Read();
std::cout << ap[1] << " " <<
ap[2] << " " <<
ap[3] << " " <<
ap[4] << " " <<
ap[5] << " " <<
ap[6] << " " <<
std::endl;
sleep(1);
}
}
Java code
----------------------------------------------------------------------------
----
import javaclient2.PlayerException;
import javaclient2.PlayerClient;
import javaclient2.structures.PlayerConstants;
import javaclient2.AIOInterface;
import javaclient2.structures.PlayerMsgHdr;
import javaclient2.structures.aio.PlayerAioData;
public class PhidgetSensorTest3
{
final static long serialVersionUID = 1L;
final static int NO_READINGS = 6;
final static int FIRST_INDEX = 1;
final static float MAX_RANGE = 1;
public static void main(String[] args)
{
PlayerClient myPlayerClient = null;
AIOInterface mySonar = null;
PlayerAioData sonarData = null;
float[] reading = null;
try
{
myPlayerClient = new PlayerClient ("localhost", 6665);
mySonar = myPlayerClient.requestInterfaceAIO(0,
PlayerConstants.PLAYER_OPEN_MODE);
}
catch (PlayerException e)
{
System.err.println ("PhidgetSensorTest3::main Error connecting to
Player");
System.err.println (" [" + e.toString() + " ]");
System.exit(1);
}
System.out.println("PhidgetSensorTest3::main connected");
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{}
System.out.println("PhidgetSensorTest3::main request data");
myPlayerClient.requestData();
// System.out.println("PhidgetSensorTest3::main read all");
// myPlayerClient.readAll();
// PlayerMsgHdr sonarHeader = new PlayerMsgHdr();
// System.out.println("PhidgetSensorTest3::main read data");
// mySonar.readData(sonarHeader);
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{}
if (!mySonar.isDataReady())
System.out.println("PhidgetSensorTest3::main not ready"); *** this
line prints
System.out.println("PhidgetSensorTest3::main get data");
sonarData = mySonar.getData();
System.out.println("PhidgetSensorTest3::main get voltages");
reading = sonarData.getVoltages (); *** null pointer error because
sonarData is null
/*
System.out.println("--- SonarViewPhidget::paint loop");
for (int i=FIRST_INDEX; i<NO_READINGS; i++)
{
float f = reading[i];
System.out.println (f);
}
*/
System.out.println("PhidgetSensorTest3::main exit");
}
}
phidgetIFK.cfg ---------------------------------------------------------
# Use only the interfaces needed: if you don't need to write things to the
screen, or there is none, just
# provide aio and dio, without speech
# To get the serial number, use: lsusb -v |grep iSerial.*3 , or use "serial
-1" to connect to the first available phidget
driver
(
name "phidgetIFK"
#provides ["aio:0" "dio:0" "speech:0"]
provides ["aio:0" "dio:0"]
serial -1
alwayson 1
samplingrate 16
alarmtime 21
)
|