A basic BACnet IP server example written with Java using the CAS BACnet Stack
- Device: 389001 (Device Rainbow)
- Aanalog_input: 0 (AnalogInput Bronze)
This adapter follows the recommended separation pattern:
- CASBACnetStackAdapter.java - Pure interface wrapper around the native library.
- SimpleServerExample.java - The application's business logic implementation showing how to use the interface wrapper.
Copy these files to your project for the interface wrapper:
CASBACnetStackAdapter.java
ICASBACnetStackLibrary.java
BACnetConstants.java
BACnetException.java
Reference SimpleServerExample.java
for patterns on how to:
- Initialize devices and add objects
- Implement callback handlers for property requests
- Handle message sending/receiving
- Store and manage property values
// Create the interface wrapper
CASBACnetStackAdapter adapter = new CASBACnetStackAdapter();
// Get direct access to the library
ICASBACnetStackLibrary library = adapter.getLibrary();
// Use the library functions directly
library.BACnetStack_AddDevice(12345);
library.BACnetStack_AddObject(12345, BACnetConstants.OBJECT_TYPE_ANALOG_INPUT, 1);
// Register your own callbacks
library.BACnetStack_RegisterCallbackGetPropertyReal(yourCallback);
// Main processing loop
while (true) {
library.BACnetStack_Tick();
Thread.sleep(100);
}
mvn clean compile
mvn mvn exec:java"
- Java 8 or higher
- CAS BACnet Stack native library (DLL/SO file)
- Maven build system
The interface wrapper automatically detects your platform and loads the appropriate library:
- Windows x64:
CASBACnetStack_x64_Release.dll
- Windows x86:
CASBACnetStack_x86_Release.dll
- Linux x64:
libCASBACnetStack_x64_Release.so
- Linux ARM:
libCASBACnetStack_arm7_Release.so
- Linux x86:
libCASBACnetStack_x86_Release.so
Make sure the library is in your system PATH or java.library.path
.
- Chipkin BACnet Explorer
Windows or Linux desktop application for discovering and polling BACnet servers.
Download for free Chipkin BACnet Explorer
- Test from another computer:
# Send Who-Is to discover the Java BACnet server
echo "810400080120FFFF00FF" | xxd -r -p | nc -u <server-ip> 47808
For more advanced implementations, see these successful adapter examples: