Il Codice del Progetto EIB, un semplice client per la gestione di quattro componenti, configurati su EIB.
La parte del codice in cui si lavora con Calimero, le librerie per la gestione KNX/EIB.
tunnel = new CEMI_Connection(
new InetSocketAddress(InetAddress.getByName("IP_EIB"),
EIBNETIP_Constants.EIBNETIP_PORT_NUMBER), // standard
new TunnellingConnectionType());
[ad#468×60]
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Color;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.net.*;
import java.util.EventObject;
import tuwien.auto.*;
import tuwien.auto.eibxlator.*;
import tuwien.auto.eicl.*;
import tuwien.auto.eicl.util.*;
import tuwien.auto.eicl.struct.cemi.*;
import tuwien.auto.eicl.struct.eibnetip.util.*;
/*
* A Universal Web-Based Visualization Tool for EIB Applications
*
* Prozessrechentechnik Labor
* Giovanni Coppa
* Prof. Dr.-Ing. Ulrich Klages
* University Wolfenbüttel
*
*This program is free software; you can redistribute it and/or
*modify it under the terms of the GNU General Public License
*as published by the Free Software Foundation; either version 2
*of the License, or (at your option) any later version.
*This program is distributed in the hope that it will be useful,
*but WITHOUT ANY WARRANTY; without even the implied warranty of
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
*GNU General Public License for more details.
*You should have received a copy of the GNU General Public License
*along with this program; if not, write to the Free Software
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
public class GUIMain extends JFrame implements ActionListener{
/**
*
*/
private static final long serialVersionUID = 1L;
CEMI_Connection tunnel=null;
private boolean s1=false, s2=false,s3=false,s4=false;
JButton b1,b2,b3,b4;
GUIMain(){
super("EIBDesk Client");
Container c = getContentPane();
JPanel lp = new JPanel(new GridLayout(4,1));
b1 = new JButton("");
b1.setIcon(new ImageIcon("./images/lightoff.png"));
b1.addActionListener((ActionListener) this);
b2 = new JButton("");
b2.setIcon(new ImageIcon("./images/maydayoff.png"));
b2.addActionListener((ActionListener) this);
b3 = new JButton("");
b3.setIcon(new ImageIcon("./images/cogsoff.png"));
b3.addActionListener((ActionListener) this);
b4 = new JButton("");
b4.setIcon(new ImageIcon("./images/sireneoff.png"));
b4.addActionListener((ActionListener) this);
lp.add(b1);
lp.add(b2);
lp.add(b3);
lp.add(b4);
c.add(lp);
}
/**
* @param args
*/
public static void main(String[] args) {
GUIMain gui = new GUIMain();
gui.setSize(141, 600);
gui.setVisible(true);
gui.setBackground(Color.white);
// TODO Auto-generated method stub
}
public void actionPerformed(ActionEvent act) {
// Argumentueberpruefung
//B1 Button 1 Light on / off
if(act.getSource() == b1){
if(!s1){
dexecuteComman("0/0/6", "True");
b1.setIcon(new ImageIcon("./images/lighton.png"));
s1=true;
System.out.println("Light on");
}
else{
dexecuteComman("0/0/6", "False");
b1.setIcon(new ImageIcon("./images/lightoff.png"));
s1=false;
System.out.println("Light off");
}
}
//B2 Sirene an- ausschalten
if(act.getSource() == b2){
if(!s2){
dexecuteComman("0/0/4", "True");
b2.setIcon(new ImageIcon("./images/maydayon.png"));
s2=true;
System.out.println("Sirene on");
}
else{
dexecuteComman("0/0/4", "False");
b2.setIcon(new ImageIcon("./images/maydayoff.png"));
s2=false;
System.out.println("Sirene off");
}
}
//B3 Ventilator an- ausschalten
if(act.getSource() == b3){
if(!s3){
dexecuteComman("0/0/5", "True");
b3.setIcon(new ImageIcon("./images/cogson.png"));
s3=true;
System.out.println("Ventilator on");
}
else{
dexecuteComman("0/0/5", "False");
b3.setIcon(new ImageIcon("./images/cogsoff.png"));
s3=false;
System.out.println("Ventilator off");
}
}
//B4 Alarm an- auschalten
if(act.getSource() == b4){
if(!s4){
dexecuteComman("0/0/3", "True");
b4.setIcon(new ImageIcon("./images/sireneon.png"));
s4=true;
System.out.println("Alarm on");
}
else{
dexecuteComman("0/0/3", "False");
b4.setIcon(new ImageIcon("./images/sireneoff.png"));
s4=false;
System.out.println("Alarm off");
}
}
}
private void dexecuteComman(String p, String action){
/**
* The Discoverer class handles EIBnet/IP search and description requests. To be
* able to accept search and description responses, this class maintains its own
* socket and runs as an independent thread. This is, however, not of concern for
* the client application since thread instantiation is done implicitly in the
* constructor.
*/
try {
tunnel = new CEMI_Connection(
new InetSocketAddress(InetAddress.getByName("IP_EIB"),
EIBNETIP_Constants.EIBNETIP_PORT_NUMBER), // Port Numner standard
new TunnellingConnectionType());
PointPDUXlator dimVal = PDUXlatorList.getPointPDUXlator(
PDUXlatorList.TYPE_BOOLEAN[0], //TYPE_8BIT_UNSIGNED[0],
PointPDUXlator_Boolean.DPT_BOOL[0]); // 8BitUnsigned.DPT_SCALING[0]);
dimVal.setServiceType(PointPDUXlator.A_GROUPVALUE_WRITE);
dimVal.setASDUfromString(action);
CEMI_L_DATA message = new CEMI_L_DATA(
CEMI_L_DATA.MC_L_DATAREQ,
new EIB_Address(),
new EIB_Address(p),
dimVal.getAPDUByteArray());
tunnel.sendFrame(message, CEMI_Connection.WAIT_FOR_CONFIRM);
} catch (EICLException ex) {
System.out.println(ex.getMessage()); // connection error
} catch (UnknownHostException e) {
System.out.println("error2");
}finally{
try {
tunnel.disconnect("do it");
} catch (EICLException e) {
System.out.println(e.getMessage());
}
}
//System.out.println("Commmand is:"+p);
}
}