Example #1
0
  /** Get all the SCRAMNet channels from the xPC formatted file */
  protected boolean getSCRAMNetChannels() {
    ReadxPCXMLConfig xmlfile = new ReadxPCXMLConfig(new File(xmlPath));
    xml = xmlfile.getxPCConfig();

    // Get the number of Channels
    rbnbChannelNames = new String[xml.getnumxPCReadBlocks()];
    for (int i = 0; i < rbnbChannelNames.length; i++)
      rbnbChannelNames[i] = xml.getxPCReadName(i) + " " + xml.getxPCReadUnits(i);

    return true;
  }
Example #2
0
  /** Main data push from SCRAMNet */
  private boolean execute() {
    if (!connected) return false;

    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
    sdf.setTimeZone(TimeZone.getTimeZone("UTC"));

    // Connect to SCRAMNet
    ScramNetIO scr = new ScramNetIO();
    scr.initScramnet();

    // Create a new Channel map
    ChannelMap cmap = new ChannelMap();

    // Gather all the channels
    int channelId[] = new int[rbnbChannelNames.length];
    for (int i = 0; i < rbnbChannelNames.length; i++) {
      try {
        // add the channels
        channelId[i] = cmap.Add(rbnbChannelNames[i]);
      } catch (SAPIException e) {
        System.err.println(
            "Failed to add SCRAMNet channel to channel map; name = " + rbnbChannelNames[i]);
        disconnect();
        return false;
      }

      try {
        cmap.PutUserInfo(channelId[i], "Channel_Name=" + rbnbChannelNames[i]);
      } catch (SAPIException e) {
        System.err.println("Failed to register SCRAMnet channel metadata.");
      }
    }

    try {
      source.Register(cmap);
    } catch (SAPIException e) {
      System.err.println("Failed to register SCRAMnet channel metadata.");
    }

    while (true) {
      // Read SCRAMNet channel depending on if its DAQ or other
      for (int i = 0; i < rbnbChannelNames.length; i++) {
        float scrdata[] = new float[1];

        if (xml.getxPCReadisDAQ(i).equals("true")) {
          scrdata[0] =
              (float)
                  scr.readDAQ(
                      xml.getxPCReadLocation(i),
                      xml.getxPCReadGain(i),
                      xml.getxPCReadVoffset(i),
                      xml.getxPCReadVslope(i),
                      xml.getxPCReadEUoffset(i),
                      xml.getxPCReadEUslope(i));
        } else {
          scrdata[0] =
              scr.readFloat(Integer.parseInt(xml.getxPCReadLocation(i)))
                  * (float) xml.getxPCReadGain(i);
        }

        // Push data to turbine
        try {
          cmap.PutTimeAuto("timeofday");
          cmap.PutDataAsFloat32(channelId[i], scrdata);
        } catch (SAPIException e) {
          System.err.println("Failed to put SCRAMNet data into channel map.");
          scr.unmapScramnet();
          return false;
        }
      }

      // Flush output
      try {
        source.Flush(cmap, true);
      } catch (SAPIException e) {
        e.printStackTrace();
        System.err.println("Failed to flush channel output data to server.");
        scr.unmapScramnet();
        return false;
      }

      try {
        // Delay between
        Thread.sleep(delay);
      } catch (InterruptedException e) {
      }
    }
  }