在bacnet4j中获取无类定义的错误

时间:2018-04-06 07:32:11

标签: java bacnet4j

我正在尝试使用bacnet4j。但无法找到任何教程或指南。我正在使用Bacnet-stack模拟器进行测试。 我尝试使用此代码来检查我的功能,我也尝试过localdevice但是这两种情况我在这个软件包com.serotonin.bacnet4j.npdu.Network中没有出现类定义错误。

package bacnet_4_j_test;
import com.serotonin.bacnet4j.LocalDevice;
import com.serotonin.bacnet4j.RemoteDevice;
import com.serotonin.bacnet4j.RemoteObject;
import com.serotonin.bacnet4j.ServiceFuture;
import com.serotonin.bacnet4j.event.DeviceEventAdapter;
import com.serotonin.bacnet4j.exception.BACnetException;
import com.serotonin.bacnet4j.exception.ErrorAPDUException;
import com.serotonin.bacnet4j.npdu.ip.IpNetwork;
import com.serotonin.bacnet4j.service.acknowledgement.ReadPropertyAck;
import 
com.serotonin.bacnet4j.service.acknowledgement.ReadPropertyMultipleAck;
import com.serotonin.bacnet4j.service.confirmed.*;
import com.serotonin.bacnet4j.service.unconfirmed.WhoIsRequest;
import com.serotonin.bacnet4j.transport.DefaultTransport;
import com.serotonin.bacnet4j.transport.Transport;
import com.serotonin.bacnet4j.type.constructed.ReadAccessResult;
import com.serotonin.bacnet4j.type.constructed.ReadAccessSpecification;
import com.serotonin.bacnet4j.type.constructed.SequenceOf;
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.primitive.ObjectIdentifier;
import com.serotonin.bacnet4j.type.primitive.Real;
import com.serotonin.bacnet4j.util.DiscoveryUtils;

import java.util.ArrayList;
import java.util.List;
/**
 *
 * @author kaushikdas
 */
public class Bacnet_4_j_test {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws Exception {
        IpNetwork network = new IpNetwork("192.168.2.255", IpNetwork.DEFAULT_PORT);
        Transport transport = new DefaultTransport(network);
        transport.setTimeout(500000);
        transport.setSegTimeout(15000);
        final LocalDevice localDevice = new LocalDevice(1338, transport);

        localDevice.getEventHandler().addListener(new DeviceEventAdapter() {
            public void iAmReceived(RemoteDevice device) {
                System.out.println("Discovered device " + device);
                localDevice.addRemoteDevice(device);

                final RemoteDevice remoteDevice = localDevice.getRemoteDevice(device.getAddress());

                remoteDevice.setSegmentationSupported(Segmentation.segmentedBoth);
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            try {
                                DiscoveryUtils.getExtendedDeviceInformation(localDevice, remoteDevice);
                            } catch (BACnetException e) {
                                e.printStackTrace();
                            }
                            System.out.println(remoteDevice.getName() + " " + remoteDevice.getVendorName() + " " + remoteDevice.getModelName() + " " + remoteDevice.getAddress() + " " + remoteDevice.getProtocolRevision() + " " + remoteDevice.getProtocolVersion());

                            ReadPropertyAck ack = localDevice.send(remoteDevice, new ReadPropertyRequest(remoteDevice.getObjectIdentifier(), PropertyIdentifier.objectList)).get();
                            SequenceOf<ObjectIdentifier> value = ack.getValue();

                            for (ObjectIdentifier id : value) {

                                List<ReadAccessSpecification> specs = new ArrayList<ReadAccessSpecification>();
                                specs.add(new ReadAccessSpecification(id, PropertyIdentifier.presentValue));
                                specs.add(new ReadAccessSpecification(id, PropertyIdentifier.units));
                                specs.add(new ReadAccessSpecification(id, PropertyIdentifier.objectName));
                                specs.add(new ReadAccessSpecification(id, PropertyIdentifier.description));
                                specs.add(new ReadAccessSpecification(id, PropertyIdentifier.objectType));
                                ReadPropertyMultipleRequest multipleRequest = new ReadPropertyMultipleRequest(new SequenceOf<ReadAccessSpecification>(specs));

                                ReadPropertyMultipleAck send = localDevice.send(remoteDevice, multipleRequest).get();
                                SequenceOf<ReadAccessResult> readAccessResults = send.getListOfReadAccessResults();

                                System.out.print(id.getInstanceNumber() + " " + id.getObjectType() + ", ");
                                for (ReadAccessResult result : readAccessResults) {
                                    for (ReadAccessResult.Result r : result.getListOfResults()) {
                                        System.out.print(r.getReadResult() + ", ");
                                    }
                                }
                                System.out.println();
                            }

                            ObjectIdentifier mode = new ObjectIdentifier(ObjectType.analogValue, 11);

                            ServiceFuture send = localDevice.send(remoteDevice, new WritePropertyRequest(mode, PropertyIdentifier.presentValue, null, new Real(2), null));
                            System.out.println(send.getClass());
                            System.out.println(send.get().getClass());

                        } catch (ErrorAPDUException e) {
                            System.out.println("Could not read value " + e.getApdu().getError() + " " + e);
                        } catch (BACnetException e) {
                            e.printStackTrace();
                        }

                    }
                }).start();
            }

            @Override
            public void iHaveReceived(RemoteDevice device, RemoteObject object) {
                System.out.println("Value reported " + device + " " + object);
            }
        });

        localDevice.initialize();
        localDevice.sendGlobalBroadcast(new WhoIsRequest());

        List<RemoteDevice> remoteDevices = localDevice.getRemoteDevices();
        for (RemoteDevice device : remoteDevices) {
            System.out.println("Remote dev " + device);
        }

        System.in.read();
        localDevice.terminate();
    }

}

但是我收到了这个错误。

Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at com.serotonin.bacnet4j.npdu.Network.<clinit>(Network.java:43)
at bacnet_4_j_test.Bacnet_4_j_test.main(Bacnet_4_j_test.java:43)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 2 more

如果有人有任何教程,请提供。

1 个答案:

答案 0 :(得分:0)

您缺少slf4j依赖项。将slf4j添加到类路径中它应该可以工作。