如何使用bacnet4j API连接Scada BACnet设备模拟器?

时间:2015-03-10 05:58:53

标签: java bacnet

我使用Scada Bacnet Device模拟器创建两个设备,该模拟器在localhost上运行。命名为设备0和设备1.我有bacnet4j测试代码,也可以在localhost中运行。我试图获取那些设备对象的属性。但我得到了以下错误。

  

线程中的异常" main" com.serotonin.bacnet4j.exception.BACnetTimeoutException:等待id 0的响应时超时       在com.serotonin.bacnet4j.transport.Transport.sendSegments(Transport.java:273)       在com.serotonin.bacnet4j.transport.Transport.send(Transport.java:188)       在com.serotonin.bacnet4j.LocalDevice.send(LocalDevice.java:376)       在Test2.getObjectList(Test2.java:63)       在Test2.main(Test2.java:52)

     

`

import java.net.InetAddress;  
import java.net.InetSocketAddress;  

import com.serotonin.bacnet4j.LocalDevice;  
import com.serotonin.bacnet4j.RemoteDevice;  
import com.serotonin.bacnet4j.RemoteObject;
//import com.serotonin.bacnet4j.event.DefaultDeviceEventListener;  
import com.serotonin.bacnet4j.enums.MaxApduLength;
import com.serotonin.bacnet4j.event.DeviceEventListener;
import com.serotonin.bacnet4j.npdu.ip.IpNetwork;
import com.serotonin.bacnet4j.obj.BACnetObject;
import com.serotonin.bacnet4j.service.acknowledgement.ReadPropertyAck;  
import com.serotonin.bacnet4j.service.confirmed.ReadPropertyRequest;  
import com.serotonin.bacnet4j.service.confirmed.ReinitializeDeviceRequest.ReinitializedStateOfDevice;
import com.serotonin.bacnet4j.transport.Transport;
import com.serotonin.bacnet4j.type.Encodable;
import com.serotonin.bacnet4j.type.constructed.Address;
import com.serotonin.bacnet4j.type.constructed.Choice;
import com.serotonin.bacnet4j.type.constructed.DateTime;
import com.serotonin.bacnet4j.type.constructed.PropertyValue;
import com.serotonin.bacnet4j.type.constructed.SequenceOf;  
import com.serotonin.bacnet4j.type.constructed.TimeStamp;
import com.serotonin.bacnet4j.type.enumerated.EventState;
import com.serotonin.bacnet4j.type.enumerated.EventType;
import com.serotonin.bacnet4j.type.enumerated.MessagePriority;
import com.serotonin.bacnet4j.type.enumerated.NotifyType;
import com.serotonin.bacnet4j.type.enumerated.ObjectType;  
import com.serotonin.bacnet4j.type.enumerated.PropertyIdentifier;  
import com.serotonin.bacnet4j.type.enumerated.Segmentation;  
import com.serotonin.bacnet4j.type.notificationParameters.NotificationParameters;
import com.serotonin.bacnet4j.type.primitive.Boolean;
import com.serotonin.bacnet4j.type.primitive.CharacterString;
import com.serotonin.bacnet4j.type.primitive.ObjectIdentifier;  
import com.serotonin.bacnet4j.type.primitive.UnsignedInteger;

public class Test2 {  
    public static void main(String[] args) throws Exception {
        IpNetwork network = new IpNetwork("192.168.1.255", 47808, "0.0.0.0");
        /*System.out.println(network.DEFAULT_BIND_IP);
        System.out.println(network.DEFAULT_BROADCAST_IP);
        System.out.println(network.DEFAULT_PORT);*/

    Transport transport = new Transport(network);
    LocalDevice localDevice = new LocalDevice(101, transport);  
    localDevice.getEventHandler().addListener((DeviceEventListener) new Listener());  
    //localDevice.setPort(47808);  
    localDevice.initialize();  

    // Read  
    ReadPropertyRequest read = new ReadPropertyRequest(new ObjectIdentifier(ObjectType.analogInput, 243), PropertyIdentifier.presentValue);  
    getObjectList(localDevice, "192.168.1.210", 47808, 101);  

    localDevice.terminate();  
}  

private static void getObjectList(LocalDevice localDevice, String ip, int port, int deviceId) throws Exception {  
    InetSocketAddress addr = new InetSocketAddress(InetAddress.getByName(ip), port);  
    Address address = new Address(ip, port);

    ReadPropertyRequest read = new ReadPropertyRequest(new ObjectIdentifier(ObjectType.device, deviceId), PropertyIdentifier.objectList);  
    //ReadPropertyAck ack = (ReadPropertyAck) localDevice.send(null, read);
    ReadPropertyAck ack = (ReadPropertyAck) localDevice.send(address,MaxApduLength.UP_TO_1024, Segmentation.segmentedBoth, read); 
    //ReadPropertyAck ack = (ReadPropertyAck) localDevice.send(address, MaxApduLength.UP_TO_1024, segmentationSupported, serviceRequest) 
    System.out.println("IP: " + ip);  
    SequenceOf<ObjectIdentifier> oids = (SequenceOf<ObjectIdentifier>) ack.getValue();  
    for (ObjectIdentifier oid : oids)  
        System.out.println("    " + oid);  

}  

static class Listener implements DeviceEventListener {  
    @Override  
    public void iAmReceived(RemoteDevice d) {  
        System.out.println("IAm received" + d);  
    }

    @Override
    public boolean allowPropertyWrite(BACnetObject arg0, PropertyValue arg1) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public void covNotificationReceived(UnsignedInteger arg0,
            RemoteDevice arg1, ObjectIdentifier arg2, UnsignedInteger arg3,
            SequenceOf<PropertyValue> arg4) {
        // TODO Auto-generated method stub

    }

    @Override
    public void eventNotificationReceived(UnsignedInteger arg0,
            RemoteDevice arg1, ObjectIdentifier arg2, TimeStamp arg3,
            UnsignedInteger arg4, UnsignedInteger arg5, EventType arg6,
            CharacterString arg7, NotifyType arg8, Boolean arg9,
            EventState arg10, EventState arg11, NotificationParameters arg12) {
        // TODO Auto-generated method stub

    }

    @Override
    public void iHaveReceived(RemoteDevice arg0, RemoteObject arg1) {
        // TODO Auto-generated method stub

    }

    @Override
    public void listenerException(Throwable arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void privateTransferReceived(UnsignedInteger arg0,
            UnsignedInteger arg1, Encodable arg2) {
        // TODO Auto-generated method stub

    }

    @Override
    public void propertyWritten(BACnetObject arg0, PropertyValue arg1) {
        // TODO Auto-generated method stub

    }

    @Override
    public void reinitializeDevice(ReinitializedStateOfDevice arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void synchronizeTime(DateTime arg0, boolean arg1) {
        // TODO Auto-generated method stub

    }

    @Override
    public void textMessageReceived(RemoteDevice arg0, Choice arg1,
            MessagePriority arg2, CharacterString arg3) {
        // TODO Auto-generated method stub

    }  
}  
} 

0 个答案:

没有答案