ABle to connect to zigbee dongle now
This commit is contained in:
parent
6214c01157
commit
3b949b13f7
3 changed files with 13 additions and 10 deletions
|
|
@ -26,7 +26,7 @@ public class HalZigbeeController implements HalSensorController, HalEventControl
|
|||
|
||||
private ZigBeePort serialPort;
|
||||
private ZigBeeDataStore dataStore;
|
||||
private ZigBeeNetworkManager networkManager;
|
||||
protected ZigBeeNetworkManager networkManager;
|
||||
|
||||
private HalSensorReportListener sensorListener;
|
||||
private HalEventReportListener eventListener;
|
||||
|
|
@ -50,16 +50,12 @@ public class HalZigbeeController implements HalSensorController, HalEventControl
|
|||
dataStore = new ZigBeeDataStore();
|
||||
|
||||
ZigBeeTransportTransmit dongle = getDongle("CC2531");
|
||||
ZigBeeNetworkManager networkManager = new ZigBeeNetworkManager(dongle);
|
||||
networkManager = new ZigBeeNetworkManager(dongle);
|
||||
networkManager.setNetworkDataStore(dataStore);
|
||||
|
||||
ZigBeeStatus initResponse = networkManager.initialize();
|
||||
System.out.println("NetworkManager.initialize() returned " + initResponse);
|
||||
|
||||
System.out.println("PAN ID = " + networkManager.getZigBeePanId());
|
||||
System.out.println("Extended PAN ID = " + networkManager.getZigBeeExtendedPanId());
|
||||
System.out.println("Channel = " + networkManager.getZigBeeChannel());
|
||||
|
||||
if (dongle instanceof ZigBeeDongleTiCc2531) {
|
||||
ZigBeeDongleTiCc2531 tiDongle = (ZigBeeDongleTiCc2531) dongle;
|
||||
tiDongle.setLedMode(1, false);
|
||||
|
|
@ -89,7 +85,6 @@ public class HalZigbeeController implements HalSensorController, HalEventControl
|
|||
serialPort.close();
|
||||
}
|
||||
|
||||
|
||||
// --------------------------
|
||||
// Hal Overrides
|
||||
// --------------------------
|
||||
|
|
|
|||
|
|
@ -179,7 +179,7 @@ public class ZigBeeJSerialCommPort implements ZigBeePort {
|
|||
|
||||
@Override
|
||||
public void write(int value) {
|
||||
if (serialPort != null)
|
||||
if (serialPort == null)
|
||||
throw new RuntimeException("Unable to write, Serial port is not open.");
|
||||
|
||||
try {
|
||||
|
|
@ -196,10 +196,13 @@ public class ZigBeeJSerialCommPort implements ZigBeePort {
|
|||
|
||||
@Override
|
||||
public int read(int timeout) {
|
||||
if (serialPort != null)
|
||||
if (serialPort == null)
|
||||
throw new RuntimeException("Unable to read, Serial port is not open.");
|
||||
|
||||
try {
|
||||
if (serialPort.getReadTimeout() != timeout)
|
||||
serialPort.setComPortTimeouts(SerialPort.TIMEOUT_READ_BLOCKING, timeout, 0);
|
||||
|
||||
return serialInputstream.read();
|
||||
} catch (IOException e) {
|
||||
logger.error("Was unable to read from serial port.", e);
|
||||
|
|
@ -209,7 +212,7 @@ public class ZigBeeJSerialCommPort implements ZigBeePort {
|
|||
|
||||
@Override
|
||||
public void purgeRxBuffer() {
|
||||
if (serialPort != null)
|
||||
if (serialPort == null)
|
||||
return;
|
||||
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -40,6 +40,11 @@ public class HalZigbeeControllerTest {
|
|||
HalZigbeeController controller = new HalZigbeeController();
|
||||
controller.initialize("COM3");
|
||||
|
||||
System.out.println("PAN ID = " + controller.networkManager.getZigBeePanId());
|
||||
System.out.println("Extended PAN ID = " + controller.networkManager.getZigBeeExtendedPanId());
|
||||
System.out.println("Channel = " + controller.networkManager.getZigBeeChannel());
|
||||
controller.networkManager.permitJoin(50);
|
||||
|
||||
System.out.println("Press ENTER to exit application.");
|
||||
System.in.read();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue