Guest User

Untitled

a guest
Apr 16th, 2011
350
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.     Copyright (C) 2006-2009 Serotonin Software Technologies Inc.
  3.     @author Matthew Lohbihler
  4.  */
  5. package com.bacnet.webservice;
  6.  
  7. import com.serotonin.bacnet4j.LocalDevice;
  8. import com.serotonin.bacnet4j.RemoteDevice;
  9. import com.serotonin.bacnet4j.RemoteObject;
  10. import com.serotonin.bacnet4j.service.acknowledgement.ReadPropertyAck;
  11. import com.serotonin.bacnet4j.service.confirmed.ReadPropertyRequest;
  12. import com.serotonin.bacnet4j.service.confirmed.WritePropertyRequest;
  13. import com.serotonin.bacnet4j.service.unconfirmed.WhoHasRequest;
  14. import com.serotonin.bacnet4j.service.unconfirmed.WhoIsRequest;
  15. import com.serotonin.bacnet4j.type.Encodable;
  16. import com.serotonin.bacnet4j.type.enumerated.PropertyIdentifier;
  17. import com.serotonin.bacnet4j.type.primitive.CharacterString;
  18. import com.serotonin.bacnet4j.type.primitive.Null;
  19. import com.serotonin.bacnet4j.type.primitive.Real;
  20. import com.serotonin.bacnet4j.type.primitive.UnsignedInteger;
  21.  
  22. /**
  23.  * @author Matthew Lohbihler
  24.  */
  25. public class CommandPriorityTest {
  26.     private static LocalDevice localDevice;
  27.     private static RemoteDevice remoteDevice;
  28.     private static RemoteObject remoteObject;
  29.    
  30.     public static void main(String[] args) throws Exception {
  31.         String objectName = "Command Priority Test";
  32.         localDevice = new LocalDevice(101, "255.255.255.255");
  33.         localDevice.setPort(47808);
  34.         localDevice.initialize();
  35.        
  36.         // Who is
  37.         localDevice.sendBroadcast(47808, null, new WhoIsRequest());
  38.         Thread.sleep(1000);
  39.        
  40.         // Who has
  41.         localDevice.sendBroadcast(47808, null, new WhoHasRequest(null, new CharacterString(objectName)));
  42.        
  43.         // Wait a bit for responses to come in.
  44.         Thread.sleep(1000);
  45.        
  46.         // Find the device
  47.         remoteDevice = localDevice.getRemoteDevices().get(0);
  48. //        localDevice.getExtendedDeviceInformation(remoteDevice);
  49. //        List<ObjectIdentifier> oids = ((SequenceOf<ObjectIdentifier>)localDevice.sendReadPropertyAllowNull(
  50. //                remoteDevice, remoteDevice.getObjectIdentifier(), PropertyIdentifier.objectList)).getValues();
  51. //        for ()
  52. //        remoteDevice.setObject(new RemoteObject())
  53.        
  54.        
  55.         // Find the object.
  56.         for (RemoteObject o : remoteDevice.getObjects()) {
  57.             if (o.getObjectName().equals(objectName)) {
  58.                 remoteObject = o;
  59.                 break;
  60.             }
  61.         }
  62.            
  63.         getPresentValue();
  64.         getPriorityArray();
  65.        
  66.         setPresentValue(new Real(16), 16);
  67.         getPresentValue();
  68.         getPriorityArray();
  69.        
  70.         setPresentValue(new Real(15), 15);
  71.         getPresentValue();
  72.         getPriorityArray();
  73.        
  74.         setPresentValue(new Null(), 16);
  75.         getPresentValue();
  76.         getPriorityArray();
  77.        
  78.         setPresentValue(new Real(16), 16);
  79.         getPresentValue();
  80.         getPriorityArray();
  81.        
  82.         setPresentValue(new Real(10), 10);
  83.         getPresentValue();
  84.         getPriorityArray();
  85.        
  86.         setPresentValue(new Null(), 10);
  87.         getPresentValue();
  88.         getPriorityArray();
  89.        
  90.         setPresentValue(new Null(), 15);
  91.         getPresentValue();
  92.         getPriorityArray();
  93.        
  94.         setPresentValue(new Null(), 16);
  95.         getPresentValue();
  96.         getPriorityArray();
  97.        
  98.        
  99.         localDevice.terminate();
  100.     }
  101.    
  102.     private static void getPresentValue() throws Exception {
  103.         ReadPropertyRequest rpr = new ReadPropertyRequest(remoteObject.getObjectIdentifier(),
  104.                 PropertyIdentifier.presentValue);
  105.         ReadPropertyAck ack = (ReadPropertyAck)localDevice.send(remoteDevice, rpr);
  106.         System.out.println("Present value: "+ ack.getValue());
  107.     }
  108.    
  109.     private static void getPriorityArray() throws Exception {
  110.         ReadPropertyRequest rpr = new ReadPropertyRequest(remoteObject.getObjectIdentifier(),
  111.                 PropertyIdentifier.priorityArray);
  112.         ReadPropertyAck ack = (ReadPropertyAck)localDevice.send(remoteDevice, rpr);
  113.         System.out.println("Priority array: "+ ack.getValue());
  114.     }
  115.    
  116.     private static void setPresentValue(Encodable value, int priority) throws Exception {
  117.         WritePropertyRequest wpr = new WritePropertyRequest(remoteObject.getObjectIdentifier(),
  118.                 PropertyIdentifier.presentValue, null, value, new UnsignedInteger(priority));
  119.         localDevice.send(remoteDevice, wpr);
  120.     }
  121. }
RAW Paste Data