-
Notifications
You must be signed in to change notification settings - Fork 15
/
CreateTpuartMonitor.java
63 lines (54 loc) · 2.55 KB
/
CreateTpuartMonitor.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
Calimero 2 - A library for KNX network access
Copyright (c) 2016, 2023 B. Malinowsky
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
import io.calimero.FrameEvent;
import io.calimero.KNXException;
import io.calimero.link.KNXNetworkMonitor;
import io.calimero.link.KNXNetworkMonitorTpuart;
import io.calimero.link.LinkListener;
import io.calimero.link.MonitorFrameEvent;
/**
* This example shows how to establish a client network monitor ({@link KNXNetworkMonitor}) to a KNX TP1 network using
* TP-UART serial communication. Minimum requirements are Calimero version 3.0-SNAPSHOT and Java SE 17 (java.base).
* <p>
* You can safely run this example; the (established) monitor connection is completely passive. No KNX messages are sent
* to the KNX network. The network monitor will run for 10 seconds to let you monitor some KNX frames.
*
* @author B. Malinowsky
*/
public class CreateTpuartMonitor
{
/** Specify the serial port of your KNX TP-UART device. */
private static final String portId = "/dev/ttyACM0";
public static void main(final String[] args) throws KNXException, InterruptedException
{
System.out.println("This example establishes a KNX monitor connection using TP-UART on port '" + portId + "'");
// Create the TP-UART monitoring link to a TP1 KNX network.
// The second argument indicates that we want the monitor to provide decoded raw frames for us.
try (KNXNetworkMonitor knxMonitor = new KNXNetworkMonitorTpuart(portId, true)) {
System.out.println("Connection established");
// add listener to notify us of any indication, and provide us with the decoded raw frame
knxMonitor.addMonitorListener(new LinkListener() {
@Override
public void indication(final FrameEvent e)
{
System.out.println(e.getFrame() + ": " + ((MonitorFrameEvent) e).getRawFrame());
}
});
// let's wait some seconds to monitor KNX frames
Thread.sleep(10000);
}
}
}