org.sump.analyzer
Class Device

java.lang.Object
  extended by org.sump.analyzer.Device

public class Device
extends java.lang.Object

Device provides access to the physical logic analyzer device. It requires the rxtx package from http://www.rxtx.org/ to access the serial port the analyzer is connected to.

Version:
0.7
Author:
Michael "Mr. Sump" Poppitz

Field Summary
static int CLOCK_EXTERNAL_FALLING
          use external clock falling edge
static int CLOCK_EXTERNAL_RISING
          use external clock rising edge
static int CLOCK_INTERNAL
          use internal clock
 
Constructor Summary
Device()
          Creates a device object.
 
Method Summary
 boolean attach(java.lang.String portName, int portRate)
          Attaches the given serial port to the device object.
 void detach()
          Detaches the currently attached port, if one exists.
 int getAvailableChannelCount()
          Returns the number of available channels in current configuration.
 int getClockSource()
          Returns the current clock source.
 int getEnabledChannels()
          Returns the currently enabled channels.
 int getMaximumRate()
          Get the maximum sampling rate available.
 int getPercentage()
          Returns the percentage of the expected data that has already been read.
static java.lang.String[] getPorts()
          Gets a string array containing the names all available serial ports.
 int getTriggerMask(int stage)
          Returns the current trigger mask.
 int getTriggerStageCount()
          Returns the number of available trigger stages.
 int getTriggerValue(int stage)
          Returns the current trigger value.
 boolean isFilterAvailable()
          Returns wether or not the noise filter can be used in the current configuration.
 boolean isFilterEnabled()
          Returns wether or not the noise filter is enabled.
 boolean isRunning()
          Returns wether or not the device is currently running.
 boolean isTriggerEnabled()
          Returns wether or not the trigger is enabled.
 CapturedData run()
          Sends the configuration to the device, starts it, reads the captured data and returns a CapturedData object containing the data read as well as device configuration information.
 void setClockSource(int source)
          Sets the clock source to use.
 void setEnabledChannels(int mask)
          Set enabled channels.
 void setFilterEnabled(boolean enable)
          Sets wheter or not to enable the noise filter.
 void setParallelTrigger(int stage, int mask, int value, int level, int delay, boolean startCapture)
          Configures the given trigger stage in parallel mode.
 void setRate(int rate)
          Set the sampling rate.
 void setRatio(double ratio)
          Sets the ratio for samples to read before and after started.
 void setSerialTrigger(int stage, int channel, int mask, int value, int level, int delay, boolean startCapture)
          Configures the given trigger stage in serial mode.
 void setSize(int size)
          Sets the number of samples to obtain when started.
 void setTriggerEnabled(boolean enable)
          Sets wheter or not to enable the trigger.
 void stop()
          Informs the thread in run() that it is supposed to stop reading data and return.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLOCK_INTERNAL

public static final int CLOCK_INTERNAL
use internal clock

See Also:
Constant Field Values

CLOCK_EXTERNAL_RISING

public static final int CLOCK_EXTERNAL_RISING
use external clock rising edge

See Also:
Constant Field Values

CLOCK_EXTERNAL_FALLING

public static final int CLOCK_EXTERNAL_FALLING
use external clock falling edge

See Also:
Constant Field Values
Constructor Detail

Device

public Device()
Creates a device object.

Method Detail

setSize

public void setSize(int size)
Sets the number of samples to obtain when started.

Parameters:
size - number of samples, must be between 4 and 256*1024

setRatio

public void setRatio(double ratio)
Sets the ratio for samples to read before and after started.

Parameters:
ratio - value between 0 and 1; 0 means all before start, 1 all after

setRate

public void setRate(int rate)
Set the sampling rate. All rates must be a divisor of 200.000.000. Other rates will be adjusted to a matching divisor.

Parameters:
rate - sampling rate in Hz

setParallelTrigger

public void setParallelTrigger(int stage,
                               int mask,
                               int value,
                               int level,
                               int delay,
                               boolean startCapture)
Configures the given trigger stage in parallel mode. Currenty the trigger has four stages (0-3).

In mask and value each bit of the integer parameters represents one channel. The LSB represents channel 0, the MSB channel 31.

When a trigger fires, the trigger level will rise by one. Initially the trigger level is 0.

Parameters:
stage - trigger stage to write mask und value to
mask - bit map defining which channels to watch
value - bit map defining what value to wait for on watched channels
level - trigger level at which the trigger will be armed (0 = immediatly)
delay - delay in samples to wait in between match and fire
startCapture - if true that capture when trigger fires, otherwise only triggel level will increase

setSerialTrigger

public void setSerialTrigger(int stage,
                             int channel,
                             int mask,
                             int value,
                             int level,
                             int delay,
                             boolean startCapture)
Configures the given trigger stage in serial mode. Currenty the trigger has four stages (0-3).

In mask and value each bit of the integer parameters represents one sample. The LSB represents the oldest sample not yet shifted out, the MSB the most recent. (The trigger compares to a 32bit shift register that is shifted by one for each sample.)

When a trigger fires, the trigger level will rise by one. Initially the trigger level is 0.

Parameters:
stage - trigger stage to write mask und value to
channel - channel to attach trigger to
mask - bit map defining which channels to watch
value - bit map defining what value to wait for on watched channels
level - trigger level at which the trigger will be armed (0 = immediatly)
delay - delay in samples to wait in between match and fire
startCapture - if true that capture when trigger fires, otherwise only triggel level will increase

setTriggerEnabled

public void setTriggerEnabled(boolean enable)
Sets wheter or not to enable the trigger.

Parameters:
enable - true enables the trigger, false disables it.

setFilterEnabled

public void setFilterEnabled(boolean enable)
Sets wheter or not to enable the noise filter.

Parameters:
enable - true enables the noise filter, false disables it.

setEnabledChannels

public void setEnabledChannels(int mask)
Set enabled channels.

Parameters:
mask - bit map defining enabled channels

setClockSource

public void setClockSource(int source)
Sets the clock source to use.

Parameters:
source - can be any CLOCK_ property of this class

getMaximumRate

public int getMaximumRate()
Get the maximum sampling rate available.

Returns:
maximum sampling rate

getTriggerMask

public int getTriggerMask(int stage)
Returns the current trigger mask.

Parameters:
stage - trigger stage to read mask from
Returns:
current trigger mask

getTriggerValue

public int getTriggerValue(int stage)
Returns the current trigger value.

Parameters:
stage - trigger stage to read value from
Returns:
current trigger value

getClockSource

public int getClockSource()
Returns the current clock source.

Returns:
the clock source currently used as defined by the CLOCK_ properties

getEnabledChannels

public int getEnabledChannels()
Returns the currently enabled channels.

Returns:
bitmask with enabled channels represented as 1

isTriggerEnabled

public boolean isTriggerEnabled()
Returns wether or not the trigger is enabled.

Returns:
true when trigger is enabled, false otherwise

isFilterEnabled

public boolean isFilterEnabled()
Returns wether or not the noise filter is enabled.

Returns:
true when noise filter is enabled, false otherwise

isFilterAvailable

public boolean isFilterAvailable()
Returns wether or not the noise filter can be used in the current configuration.

Returns:
true when noise filter is available, false otherwise

getTriggerStageCount

public int getTriggerStageCount()
Returns the number of available trigger stages.

Returns:
number of available trigger stages

getAvailableChannelCount

public int getAvailableChannelCount()
Returns the number of available channels in current configuration.

Returns:
number of available channels

isRunning

public boolean isRunning()
Returns wether or not the device is currently running. It is running, when another thread is inside the run() method reading data from the serial port.

Returns:
true when running, false otherwise

getPercentage

public int getPercentage()
Returns the percentage of the expected data that has already been read. The return value is only valid when isRunning() returns true.

Returns:
percentage already read (0-100)

getPorts

public static java.lang.String[] getPorts()
Gets a string array containing the names all available serial ports.

Returns:
array containing serial port names

attach

public boolean attach(java.lang.String portName,
                      int portRate)
Attaches the given serial port to the device object. The method will try to open the port.

A return value of true does not guarantee that a logic analyzer is actually attached to the port.

If the device is already attached to a port this port will be detached automatically. It is therefore not necessary to manually call detach() before reattaching.

Parameters:
portName - the name of the port to open
portRate - transfer rate to use (bps)
Returns:
true when the port has been assigned successfully; false otherwise.

detach

public void detach()
Detaches the currently attached port, if one exists. This will close the serial port.


run

public CapturedData run()
                 throws java.io.IOException,
                        java.lang.InterruptedException
Sends the configuration to the device, starts it, reads the captured data and returns a CapturedData object containing the data read as well as device configuration information.

Returns:
captured data
Throws:
java.io.IOException - when writing to or reading from device fails
java.lang.InterruptedException - if a read time out occurs after trigger match or stop() was called before trigger match

stop

public void stop()
Informs the thread in run() that it is supposed to stop reading data and return.