com.alarexgroup.m2mplf.adapters.io
Class PortAdapter

java.lang.Object
  extended by com.alarexgroup.m2mplf.adapters.io.PortAdapter
All Implemented Interfaces:
ATCommanderListener
public class PortAdapter
extends java.lang.Object
implements ATCommanderListener

Lets you create groups from respective GPIOs, aka ports.
These ports can be input or output. You can monitor status changes on input ports

Example of monitoring ports from pins GPIO1..4:

import com.alarexgroup.m2mplf.M2Mlet;
import com.alarexgroup.m2mplf.adapters.io.Port;
import com.alarexgroup.m2mplf.adapters.io.PortAdapter;
import com.alarexgroup.m2mplf.adapters.io.PortAdapterListener;
import com.alarexgroup.m2mplf.logging.Logger;

public class MyFirstM2M extends M2Mlet implements PortAdapterListener{
    public PortAdapter portAdapter;
    
    
    public MyFirstM2M() {
    }
    
    
    public void appStart() {
        int [] port1 = {0,1,2,3};
        portAdapter = PortAdapter.getPortAdapter(this);
        try {
            Port p = portAdapter.createInputPort(port1,false);
            portAdapter.startPoolingPort(p);
        
        catch (PortIOException ex) {
            ex.printStackTrace();
        }
        
    }



    public void onPortValueChanged(Port port, long value) {
     
        Logger.logDebug("Port: "+port.getId()+" "+value);
    }
}
    


Example of output port from pins GPIO1..4:

import com.alarexgroup.m2mplf.M2Mlet;
import com.alarexgroup.m2mplf.adapters.io.Port;
import com.alarexgroup.m2mplf.adapters.io.PortAdapter;
import com.alarexgroup.m2mplf.adapters.io.PortAdapterListener;
import com.alarexgroup.m2mplf.logging.Logger;

public class MyFirstM2M extends M2Mlet implements PortAdapterListener{
    public PortAdapter portAdapter;
    
    
    public MyFirstM2M() {
    }
    
    
    public void appStart() {
        int [] port1 = {0,1,2,3};
        portAdapter = PortAdapter.getPortAdapter(this);
        try {
            Port p = portAdapter.createOutputPort(port1);
            portAdapter.writePortValue(p,0);
      
        catch (PortIOException ex) {
            ex.printStackTrace();
        }
        
    }

    public void onPortValueChanged(Port port, long value) {
   
    }

  
}
    

Field Summary
static int PORT_DIRECTION_INPUT
          Input port
static int PORT_DIRECTION_OUTPUT
          Output port
 
Method Summary
 Port createInputPort(int[] pinIds, boolean startPooling)
          Method creates input port from array-specified GPIO pins.
 Port createOutputPort(int[] pinIds)
          Creates output port from GPIO
 void destroyPort(Port port)
          This method releases port from usage
static PortAdapter getPortAdapter(PortAdapterListener listener)
          Initializes this adapter and returns referrence
 void onURCEvent(java.lang.String urc)
          This method is called when gets AT command answer.
 int readPortValue(Port port)
          Returns the port's value
 void startPoolingPort(Port port)
          Start port status monitoring.
 void stopPoolingPort(Port port)
          Stops port monitoring.
 void writePortValue(Port port, int value)
          Sets the port value to specified value
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PORT_DIRECTION_INPUT

public static final int PORT_DIRECTION_INPUT
Input port

See Also:
Constant Field Values

PORT_DIRECTION_OUTPUT

public static final int PORT_DIRECTION_OUTPUT
Output port

See Also:
Constant Field Values
Method Detail

getPortAdapter

public static PortAdapter getPortAdapter(PortAdapterListener listener)
Initializes this adapter and returns referrence

Parameters:
listener - interface for handling port events.
Returns:
referrence to the active adapter

createInputPort

public Port createInputPort(int[] pinIds,
                            boolean startPooling)
                     throws PortIOException
Method creates input port from array-specified GPIO pins. GPIO1 has value of 0, GPIO10 has value of 9.
Status of input port is monitorable. If it is changed, method PortAdapterListener.onPortValueChanged(com.alarexgroup.m2mplf.adapters.io.Port, long) is automatically called

Parameters:
pinIds - array with numbers of GPIOs, that should create the port.
startPooling - true, if port status monitoring should be commenced immediatelly
Returns:
port referrence
Throws:
PortIOException - In case of trouble with creating, e.g. when GPIO pin is alredy in other port

createOutputPort

public Port createOutputPort(int[] pinIds)
                      throws PortIOException
Creates output port from GPIO

Parameters:
pinIds - array of GPIO numbers, that should create the port
Returns:
port
Throws:
PortIOException - In case of trouble with creating, e.g. when GPIO pin is alredy in other port

destroyPort

public void destroyPort(Port port)
This method releases port from usage

Parameters:
port - AT_COMMAND AT^SDPORT

readPortValue

public int readPortValue(Port port)
Returns the port's value

Parameters:
port - specific port, whose value we want to know
Returns:
value

writePortValue

public void writePortValue(Port port,
                           int value)
Sets the port value to specified value

Parameters:
port - Port to which we wil lwrite the value
value - value to be written

startPoolingPort

public void startPoolingPort(Port port)
                      throws PortIOException
Start port status monitoring. You can monitor multiple ports at once.
If the port's status is changed, methoda PortAdapterListener.onPortValueChanged(com.alarexgroup.m2mplf.adapters.io.Port, long) is automatically called

Parameters:
port - monitored port
Throws:
PortIOException - In case of problems

stopPoolingPort

public void stopPoolingPort(Port port)
                     throws PortIOException
Stops port monitoring.

Parameters:
port - monitored port
Throws:
PortIOException - in case of trouble

onURCEvent

public void onURCEvent(java.lang.String urc)
Description copied from interface: ATCommanderListener
This method is called when gets AT command answer.

Specified by:
onURCEvent in interface ATCommanderListener
Parameters:
urc - - URC string