Menu

Any User Docs?

Help
Ansari S.H
2009-04-07
2023-09-19
  • Ansari  S.H

    Ansari S.H - 2009-04-07

    Hi All,

    Is there any documentation available for BACnet4j,regarding

    1. List of features
    2. How to use?
    3. API Docs?

    With Regs
    :Ansari S.H

     
  • Bruce Boyes

    Bruce Boyes - 2014-03-17

    Same question. The handful of source files I looked at had no method comments; nothing useful to javadoc. Is there any API documentation? Has source documentation been stripped?

     
  • Adam Batakji

    Adam Batakji - 2016-05-18

    Its 2016 and now I am looking for some documentation. Does it exist?

     
  • Dennis V McEnaney

    Out of interest, I also found it hard to easily find a sample, so (as part of answering a question) I posted a modified example here:

    https://stackoverflow.com/questions/76543619/bacnet-inside-docker-container/76564916#76564916

    Here (in isolation) is the code - but the post has some more information:

    // cls & java -classpath Lib\bacnet4j-3.2.2.jar;Lib\slf4j-api-1.7.9.jar;Lib\commons-lang3-3.12.0.jar Main.java
    
    // https://github.com/MangoAutomation/BACnet4J/tree/master/release/3.2.2/
    //    "Download" button - https://github.com/MangoAutomation/BACnet4J/tree/master/release/3.2.2/bacnet4j-3.2.2.jar
    
    // https://repo1.maven.org/maven2/org/slf4j/slf4j-api/1.7.9/
    //     https://repo1.maven.org/maven2/org/slf4j/slf4j-api/1.7.9/slf4j-api-1.7.9.jar
    
    // https://commons.apache.org/proper/commons-lang/download_lang.cgi/
    //     https://dlcdn.apache.org//commons/lang/binaries/commons-lang3-3.12.0-bin.zip
    
    //  DVM  ;)
    
    import java.util.List;
    
    import com.serotonin.bacnet4j.LocalDevice;
    import com.serotonin.bacnet4j.RemoteDevice;
    import com.serotonin.bacnet4j.event.DeviceEventAdapter;
    import com.serotonin.bacnet4j.exception.BACnetException;
    import com.serotonin.bacnet4j.exception.BACnetTimeoutException;
    import com.serotonin.bacnet4j.npdu.ip.IpNetwork;
    import com.serotonin.bacnet4j.npdu.ip.IpNetworkUtils;
    import com.serotonin.bacnet4j.npdu.Network;
    import com.serotonin.bacnet4j.service.acknowledgement.ReadPropertyAck;
    import com.serotonin.bacnet4j.service.confirmed.ReadPropertyRequest;
    import com.serotonin.bacnet4j.transport.DefaultTransport;
    import com.serotonin.bacnet4j.transport.Transport;
    import com.serotonin.bacnet4j.type.constructed.Address;
    import com.serotonin.bacnet4j.type.constructed.SequenceOf;
    import com.serotonin.bacnet4j.type.constructed.ServicesSupported;
    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.OctetString;
    import com.serotonin.bacnet4j.type.primitive.Unsigned16;
    import com.serotonin.bacnet4j.type.primitive.UnsignedInteger;
    import com.serotonin.bacnet4j.util.RequestUtils;
    
    class Main
    {
        private static LocalDevice localDevice;
    
        public static void main(String[] args)
            throws Exception
        {
            System.out.println();
    
            // CONFIGURE:  For your own NIC/network card
            // (- UDPv4 'Broadcast' address)
            IpNetwork network = new IpNetwork("192.168.1.255", 47814);
    
            Transport transport = new DefaultTransport(network);
            // transport.setTimeout(15000);
            // transport.setSegTimeout(15000);
    
            localDevice = new LocalDevice(1234, transport);
    
            try
            {
                localDevice.initialize();
    
                localDevice.getEventHandler().addListener(new Listener());
                // localDevice.sendLocalBroadcast(new WhoIsRequest());
                // localDevice.sendGlobalBroadcast(new WhoIsRequest());
    
                // Using NIC/IP End-Point '192.168.1.7'/'192.168.1.7:47814'
                // (- 'c0,a8,1,7,ba,c6'); using the same IP address as
                // the target device but with a different port # -
                // '47814' vs/to '47810'
                for (Address addr : localDevice.getAllLocalAddresses())
                {
                    System.out.println("\t" + addr);
                }
    
                System.out.println();
    
                // CONFIGURE:  For your own device
                Address targAddr = IpNetworkUtils.toAddress("192.168.1.7", 47810);
    
                System.out.println("TargAddr = '" + targAddr.toString() + "'");
                System.out.println();
    
                // localDevice.addRemoteDevice(targAddr, 999);
                RemoteDevice targDevice = localDevice.findRemoteDevice(targAddr, 999);
                if (targDevice != null)
                {
                    System.out.println(targDevice.toString());
                    System.out.println();
    
                    getExtendedDeviceInformation(targDevice);
    
                    System.out.println("Object-Name = '" + targDevice.getName() + "'");
                    System.out.println();
    
                    System.out.println("Vendor-Identifier = '" + targDevice.getVendorId() + "'");
                    System.out.println("Vendor-Name = '" + targDevice.getVendorName() + "'");
                    System.out.println();
    
                    System.out.println("Protocol-Version = '" + targDevice.getProtocolVersion() + "'");
                    System.out.println("Protocol-Revision = '" + targDevice.getProtocolRevision() + "'");
    
                    System.out.println();
                    System.out.println("Services-Supported = '" + targDevice.getServicesSupported() + "'");
                }
    
                Thread.sleep(3000);
            }
            catch (BACnetTimeoutException exc)
            {
                System.out.flush();
    
                System.err.println(exc.getMessage());
                System.err.flush();
            }
            catch (BACnetException exc)
            {
                System.out.flush();
    
                System.err.println(exc.getMessage());
                System.err.flush();
            }
            catch (Exception exc)
            {
                System.out.flush();
    
                System.err.println(exc.getMessage());
                System.err.flush();
            }
            finally
            {
                localDevice.terminate();
    
                System.out.println();
    
                System.out.flush();
            }
        }
    
        static class Listener extends DeviceEventAdapter
        {
            // I haven't tested the 'iAmReceived()' code/method - I borrowed it from elsewhere
            @Override
            public void iAmReceived(RemoteDevice d)
            {
                try
                {
                    System.out.println("IAm received from " + d);
                    System.out.println("Segmentation: " + d.getSegmentationSupported());
                    d.setSegmentationSupported(Segmentation.noSegmentation);
    
                    Address a = new Address(new Unsigned16(0), new OctetString(new byte[] { (byte) 0xc0, (byte) 0xa8, 0x1,
                            0x5, (byte) 0xba, (byte) 0xc0 }));
    
                    System.out.println("Equals: " + a.equals(d.getAddress()));
                    getExtendedDeviceInformation(d);
                    System.out.println("Done getting extended information");
    
                    List oids = ((SequenceOf) RequestUtils.sendReadPropertyAllowNull(localDevice, d,
                            d.getObjectIdentifier(), PropertyIdentifier.objectList)).getValues();
                    System.out.println(oids);
                }
                catch (BACnetException e)
                {
                    e.printStackTrace();
                }
            }
        }
    
        static void getExtendedDeviceInformation(RemoteDevice d)
            throws BACnetException
        {
            ObjectIdentifier oid = d.getObjectIdentifier();
    
            ReadPropertyAck ack;
    
            // -
    
            System.out.println("ExtDevInfo:  Getting 'Object-Name' .  .   .");
    
            ack =
                (ReadPropertyAck)
                    (
                        localDevice.send(
                            d,
                            new ReadPropertyRequest(
                                oid,
                                PropertyIdentifier.objectName)).get()
                    );
    
            d.setName(ack.getValue().toString());
    
            // -
    
            System.out.println("ExtDevInfo:  Getting 'Vendor-Identifier' .  .   .");
    
            ack =
                (ReadPropertyAck)
                    (
                        localDevice.send(
                            d,
                            new ReadPropertyRequest(
                                oid,
                                PropertyIdentifier.vendorIdentifier)).get()
                    );
    
            d.setVendorId(((Unsigned16) ack.getValue()).intValue());
    
            // -
    
            System.out.println("ExtDevInfo:  Getting 'Vendor-Name' .  .   .");
    
            ack =
                (ReadPropertyAck)
                    (
                        localDevice.send(
                            d,
                            new ReadPropertyRequest(
                                oid,
                                PropertyIdentifier.vendorName)).get()
                    );
    
            d.setVendorName(ack.getValue().toString());
    
    
            // -
    
            System.out.println("ExtDevInfo:  Getting 'Protocol-Version' .  .   .");
    
            ack =
                (ReadPropertyAck)
                    (
                        localDevice.send(
                            d,
                            new ReadPropertyRequest(
                                oid,
                                PropertyIdentifier.protocolVersion)).get()
                    );
    
            d.setProtocolVersion((UnsignedInteger) ack.getValue());
    
            // -
    
            System.out.println("ExtDevInfo:  Getting 'Protocol-Revision' .  .   .");
    
            ack =
                (ReadPropertyAck)
                    (
                        localDevice.send(
                            d,
                            new ReadPropertyRequest(
                                oid,
                                PropertyIdentifier.protocolRevision)).get()
                    );
    
            d.setProtocolRevision((UnsignedInteger) ack.getValue());
    
            // -
    
            // Get the device's supported services
            System.out.println("ExtDevInfo:  Getting 'Protocol-Services-Supported' .  .   .");
    
            ack =
                (ReadPropertyAck)
                    (
                        localDevice.send(
                            d,
                            new ReadPropertyRequest(
                                oid,
                                PropertyIdentifier.protocolServicesSupported))
                    ).get();
    
            d.setServicesSupported((ServicesSupported) ack.getValue());
    
            // -
    
            System.out.println();
        }
    }
    

    DVM ;)

     

Log in to post a comment.