Customize the Plug-in

Top  Previous  Next

In this portion of the tutorial, we will extend the plug-in created in the last section.  We will add a couple of configuration items and then modify the parse() routine to honor them.

Modify the plug-in

1.Disable the tutorial.exe signal in DigiView and close the signal editor.
2.Launch CPPExamples.sln in Visual Studio Express.
3.Double-click on 'tutorial -> Source Files -> tutorial.cpp' in the Solution Explorer.
4.Edit the body of the source code to match the code below.  The changed lines are shown in RED.
5.Right-click on 'tutorial' and select 'Rebuild'.  You should have a functional plug-in.
6.If you receive an error about file copy failing or access denied, the old plug-in version is probably locked. Review Disable and Task Manager.  Once the old plug-in is released, rebuild the new version to invoke the copy operation again or manually copy it to the DigiView plugin directory.
7.The newly compiled plug-in should have replaced the older version and is ready to use.
8.Click on the signal name 'tutorial.exe' in DigiView's waveform display to open the signal's editor.
9.The signal editor will appear and the signal will be auto-enabled.  Notice that there are 2 new configuration options.  Play with them and notice the effects are immediately displayed in the waveform preview.
10.Click 'OK' on the signal editor and notice the changes to the 'tutorial.exe' waveform.

Changes to tutorial.cpp. (new/modified lines are in RED)

#include "../Cmdparser.cpp"

 

// our configuration items

static bool doframe;

static bool showblue;

 

void OnLoad() {}       // no one-time initialization needed

void SetInitItem(unsigned char ID, unsigned char subID, int value) {}

 

void SetCfgItem(unsigned char ID, unsigned char subID, int value) {

if (ID == 0) doframe  = (value == 1);

if (ID == 1) showblue = (value == 1);

}

void StartOfData() {}  // no start-of-parsing initialization needed

void EndOfData() {}    // no end-of-parsing finalization needed

void OnUnLoad() {}     // no final cleanup needed

 

void GetStrList(int ID, vector<string> &strl)

{        switch (ID)

       

       case 0: strl.push_back("My first Custom Plug-in V.0001"); break;

       case 1:

               strl.push_back("Frame on 0 or 8,checkbox,0");

               strl.push_back("Field Color:,radio,0,YELLOW,BLUE");

               break;

       case 2:

               strl.push_back("State,YELLOW,BLACK,{}");

               strl.push_back("State2,BLUE,WHITE,{}");

               strl.push_back("SOF,GREEN,WHITE,SOF");

               break;

       case 3:  strl.push_back("STATE"); break; // use STATE pre-parser

       case 4:  strl.push_back("1");        break; // require framework V 1

       }

}

 

void Parse(int64 timestamp, Data64 data)

// echo all data events as individual formatted fields

if ((data.bytes[6] & 0x80) == 0x80)  //is a data event

{ if (doframe & ((data.lowint == 0)|(data.lowint == 8)))

      StartFrame(timestamp,data,2);

   else if (showblue) StartField(timestamp,data,1);

   else StartField(timestamp,data,0); 

}

}

Explanation

We modified the GetStrList() case 1 so that we could tell the DigiView application about the 2 new options we wanted presented to the user. See Configuration Editors for complete documentation on the available editors, their syntax and return values.

Next, we modified the SetCFGItem() call so the DigiView application could tell us what options the user chose. Notice that the SetCFGItem ID parameter tells us which configuration item we are receiving.  These correspond to the  order we specified the configuration items in the GetSTRList() case 1 above.

We also modified the GetStrList() case 2 to define 2 additional format strings. Now we have 3 different formats we can use. See Field Formats for complete documentation of field format strings.

Finally, we modified Parse() to use the new configuration information to format the display.

Conclusion

We extended the plug-in to allow the user to change the field color and to choose whether or not to frame when it sees a 0 or 8. We also substituted 'SOF' for the actual data in the start of frame field.  This added only about 12 lines of code and the source to the entire plug-in still fits on one page.