Chapter 2 - Create a Device Id for Your Driver & Associate it to Your Ping Request

While following the examples in this chapter, please replace the text jarFileName, yourDriver and yourCompany as previously described in the Preparation section):

  1. Make a class named BYourDriverDeviceId that extends BDdfDeviceId. Create this in a package named com.yourCompany.yourDriver.identify. Add a slotomatic properties declaration and declare any properties that you needed for coding the toByteArray method in the previous chapter. In the property declaration for each property, add the MGR_INCLUDE slot facet as shown in the following examples.
  2. NOTE: The Dev in BDdfDeviceId, and in many other locations throughout the developer driver, stands for Developer.

    To do this, create a text file named BYourDriverDeviceId.java in the jarFileName/src/com/yourCompany/yourDriver/identify folder. Inside the text file, start with the text that follows. The multi-line comment that immediately follows the Java class declaration is the Niagara slotomatic declaration. In the properties section, declare any properties that you needed for the toByteArray method in the previous chapter.

    package com.yourCompany.yourDriver.identify;
    
    import javax.baja.sys.*;
    
    import com.tridium.ddf.identify.*;
    
    import com.yourCompany.yourDriver.comm.req.*;
    
    public class BYourDriverDeviceId
      extends BDdfDeviceId
    {
      /*-
      class BYourDriverDeviceId
      {
        properties
        {
          unitNumber : int
            -- This is the unitNumber in our hypothetical protocol.
            default{[0]}
            slotfacets{[MGR_INCLUDE]}
        }
      }
      -*/
    }
    

  3. Override the 'getPingRequestType()' method and return BYourDriverPingRequest.TYPE. To do this, insert the following text to the line immediately before the closing brace.
  4.   public Type getPingRequestType( )
      {
        return BYourDriverPingRequest.TYPE;
      }
    

  5. Run the Niagara AX slot utility on your driver.
  6. To do this, open a Niagara Console and do the following, replacing directoryAboveYourCompanyYourDriverFolder with the path to the folder that contains the outer-most yourCompanyYourDriver folder, as created in the Preparation section.

    
    d:\Niagara-3.2.x> cd d:/directoryAboveYourCompanyYourDriverFolder
    d:\directoryAboveYourCompnayYourDriverFolder> slot -mi yourCompanyYourDriver
    
    

    The slotomatic utility parses the slotomatic comment that you added to the top of the BYourDriverPingRequest and BYourDriverDeviceId classes and generates the boiler-plate code necessary to add frozen properties to those classes. The -mi option works in Niagara AX versions 3.2 and later. It causes the slotomatic utility to also add an entry to your driver's module-include.xml file that is necessary for each Niagara AX type in your driver.

  7. Do a full build on your driver and resolve any compiler errors.
  8. To do this, open a Niagara Console from a Niagara 3.2.x release (or later) and do the following, replacing directoryAboveYourCompanyYourDriverFolder with the path to the folder that contains the outer-most yourCompanyYourDriver folder, as created in the Preparation section.

    
    d:\Niagara-3.2.x> cd d:/directoryAboveYourCompanyYourDriverFolder
    d:\directoryAboveYourCompnayYourDriverFolder> build yourCompanyYourDriver full
    
    

  9. Resolve any errors that might appear in the console window. Proceed after you achieve a completely successful build that is free of any Java and Niagara AX build errors.
  10. Return to the toByteArray method that you created in the previous chapter. Verify that you pull any data you need to make your byte array from the variable named yourDriverDeviceId and that you call the getters that were generated automatically by the Niagara AX slot utility in this chapter.