Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

Reader Background


This section assumes the reader is experienced with the tools (LonMaker, NodeBuilder, etc.) and mechanisms needed program a Neuron processor from Echelon. What follows is an example that illustrates how to send and receive information through the NIM-6 inter-processor link.

Anchor
_Toc269456548
_Toc269456548


Example: Schema Setup



Anchor
_Ref222913058
_Ref222913058
Anchor
_Toc223176036
_Toc223176036
Anchor
_Toc224024233
_Toc224024233
Anchor
_Toc269456551
_Toc269456551
Anchor
_Toc278366154
_Toc278366154
Anchor
_Toc279736912
_Toc279736912
Anchor
_Toc278367732
_Toc278367732
Anchor
_Toc269456553
_Toc269456553

The figure above shows a LonTalk Input Operator linked to a NIM-6 module and transmitting a floating point value. The information flow from an analog input (Ain1) through a variable (fResTemp) to the Input Operator with a Link Key of 'Temp'. This information is to be transferred to the Neuron.
Note that both the data Type and Neuron Link Key settings are critical for the transfer to take place. The setting in the associated operator must match the settings in the Neuron C code.

Neuron Setup and Programming Overview


NodeBuilder


When setting up a project in Echelon's NodeBuilder tool, follow these general steps:

  1. Select a project name
  2. Set Transceiver type to TP/FT-10
  3. Use the calculator function when setting the program ID. Below are the suggested values to start with:
    1. Manufacturer: Enter Number as 0
    2. Select Category, Device Class, and Usage as per your application. If you are not sure, use Industrial, Industrial (130.00), and Industrial.
    3. Select Channel type as TP/FT-10
    4. Use Model Number of 02
  4. Choose the NIM6 as the device template. If the NIM6 is not in the list, select none for now and follow the directions in the next paragraph.
  5. Finish new project creation



If you need to add the NIM6 as a template, right click on the User Templates in the Hardware Templates folder and select insert copy. Select the 'NIM6.NbHwt' file*. Right click on your device in the device templates folder, select settings, and choose the NIM6 for both the development and release hardware templates.

It is suggested that all the Fairmount Automation LonTalk files* are stored in the same directory as your *.nc source.

To add the Chameleon NIM-6 library file to your project, right click on the libraries folder in the device and select insert. Choose a custom library and select 'ChameleonAPILib.lib' file*.

To adding the Chameleon NIM-6 source files to your project, right click on the Source files directory and add both the 'ChameleonAPIlib.h' and 'fawhencode.nc' files*.

Required Additions to the Neuron C (.nc) Source Code


Your Neuron C source code will need to have the following modifications / additions to talk with the NIM-6 main processor through the inter-processor link:

  • Suggest starting with the 'FADemoApp.nc' file* as a template for your Neuron program.
  • Make sure the following is added: #include "ChameleonAPIlib.h"
  • Define input and output variables and strings for each User structures to link to Chameleon. For example:
    • far FAVarBlock OutputOperatorTableName [xx];
    • far FAVarBlock InputOperatorTableName [xx];
  • Define the inter-processor communications bus:
    • IO_0 parallel slave p_bus;
  • The 'void LinkVars() function' sets the template of data to send to the Chameleon main processor (Up) or receive from the Chameleon main processor (Down):
    • ChameleonLinkVariableUp call
    • ChameleonLinkVariableDown call
  • Include / modify the 'when(reset)' section of code with the following:
    • Initialize the interprocessor API with ChameleonInit(); call
    • Setup the variables to communicate with LinkVars(); call
    • Sync the latest information to the Chameleon processor with CHAMELEONREQUESTUPLOAD(); call
  • Whenever the communication variables associated with the 'Up' direction need to be updated, then you must call CHAMELEONREQUESTUPLOAD();
  • Need to define a global boolean bReceivedUpdate=FALSE;
  • Insert #include 'fawhencode.nc' in the body of the source. This code will respond to the interprocessor bus activity

Include a 'when(bReceivedUpdate == TRUE)' function and in this function copy the variables from the 'Down' link (i.e. from the Chameleon main processor to the Neuron) and reset bReceivedUpdate to false.
*Note: All of the configuration, library, and example files referenced in this section are available for download at the Fairmount Automation software library website.

Example: Neuron C Code




The Neuron C code for this data transfer follows:

Anchor
_Toc278367733
_Toc278367733
Anchor
_Toc278367734
_Toc278367734
Anchor
_Toc278367735
_Toc278367735

////////////////////////////////////////////////////////////////////
//
Anchor
_Toc269456559
_Toc269456559
Example Neuron C Application shell demonstrating Chameleon API
//
Anchor
_Toc269456560
_Toc269456560
Copyright 2005, Fairmount Automation Inc.
//
Anchor
_Toc269456561
_Toc269456561
All rights reserved
////////////////////////////////////////////////////////////////////
Anchor
_Toc269456564
_Toc269456564
#pragma num_alias_table_entries 10
////////////////////////////////////////////////////////////////////
//
Anchor
_Toc269456567
_Toc269456567
Header Files
////////////////////////////////////////////////////////////////////
Anchor
_Toc269456569
_Toc269456569
#include <string.h>
Anchor
_Toc269456570
_Toc269456570
#include <mem.h>
Anchor
_Toc269456571
_Toc269456571
#include "ChameleonAPIlib.h"
Anchor
_Toc269456572
_Toc269456572
#include <float.h>
Anchor
_Toc269456573
_Toc269456573
#include <s32.h>
Anchor
_Toc269456574
_Toc269456574
#include <string.h>
////////////////////////////////////////////////////////////////////
//
Anchor
_Toc269456577
_Toc269456577
Network Variable Declarations
////////////////////////////////////////////////////////////////////
Anchor
_Toc269456579
_Toc269456579
#pragma enable_sd_nv_names
Anchor
_Toc269456580
_Toc269456580
#pragma set_node_sd_string "Sample Neuron/NIM application program"
//
Anchor
_Toc269456582
_Toc269456582
Input variables
Anchor
_Toc269456583
_Toc269456583
network input boolean RemEstop;
Anchor
_Toc269456584
_Toc269456584
network output boolean LocalEstop;
Anchor
_Toc269456585
_Toc269456585
network output float_type Temp;
Anchor
_Toc269456586
_Toc269456586
network output float_type State;
Anchor
_Toc269456587
_Toc269456587
network output float_type Speed;
Anchor
_Toc269456588
_Toc269456588
network output float_type SetPt;

////////////////////////////////////////////////////////////////////
//
Anchor
_Toc269456592
_Toc269456592
Chameleon Linked Variable Declarations
////////////////////////////////////////////////////////////////////
Anchor
_Toc269456594
_Toc269456594
far char pKeysdi[1][15]={"RemEStop"};
Anchor
_Toc269456595
_Toc269456595
far char pKeysdo[1][15]={"LocalEStop"};
Anchor
_Toc269456596
_Toc269456596
far char pKeysao[4][15]={"Temp", "State", "Speed", "SetPt"};
Anchor
_Toc269456597
_Toc269456597
boolean FA_DigitalIn;
Anchor
_Toc269456598
_Toc269456598
boolean FA_DigitalOut;
Anchor
_Toc269456599
_Toc269456599
float_type FA_AnalogOut[4];
////////////////////////////////////////////////////////////////////
//
Anchor
_Toc269456602
_Toc269456602
user structures to link to Chameleon
////////////////////////////////////////////////////////////////////
Anchor
_Toc269456604
_Toc269456604
far FAVarBlock OutputOperatorTable[5];
Anchor
_Toc269456605
_Toc269456605
far FAVarBlock InputOperatorTable[1];
////////////////////////////////////////////////////////////////////
//
Anchor
_Toc269456608
_Toc269456608
Timer Declarations
////////////////////////////////////////////////////////////////////
Anchor
_Toc269456610
_Toc269456610
mtimer repeating looptimer=1000;
//
Anchor
_Toc269456611
_Toc269456611
timer optimer;

Anchor
_Toc269456614
_Toc269456614
IO_0 parallel slave p_bus; // slave A mode
Anchor
_Toc269456615
_Toc269456615
booleanbReceivedUpdate=FALSE;
Anchor
_Toc269456617
_Toc269456617
void LinkVars()
Anchor
_Toc269456618
_Toc269456618
{
Anchor
_Toc269456619
_Toc269456619
int i,j;
Anchor
_Toc269456621
_Toc269456621
for (i=0;i<1;i++){
Anchor
_Toc269456622
_Toc269456622
ChameleonLinkVariableUp(&InputOperatorTable[i], &pKeysdi[i][0], FA_DigitalIn);
Anchor
_Toc269456623
_Toc269456623
}
Anchor
_Toc269456624
_Toc269456624
for (i=0;i<1;i++){
Anchor
_Toc269456625
_Toc269456625
ChameleonLinkVariableDown(&OutputOperatorTable[i], &pKeysdo[i][0], FA_DigitalOut);
Anchor
_Toc269456626
_Toc269456626
}
Anchor
_Toc269456627
_Toc269456627
for (i=0,j=15;i<4;i+,j+){
Anchor
_Toc269456628
_Toc269456628
ChameleonLinkVariableDown(&OutputOperatorTable[j], &pKeysao[i][0], FA_AnalogOut[i]);
Anchor
_Toc269456629
_Toc269456629
}
Anchor
_Toc269456631
_Toc269456631
}
////////////////////////////////////////////////////////////////////
//
Anchor
_Toc269456634
_Toc269456634
Initialize application in the reset task
////////////////////////////////////////////////////////////////////
Anchor
_Toc269456636
_Toc269456636
when (reset)
Anchor
_Toc269456637
_Toc269456637
{
Anchor
_Toc269456638
_Toc269456638
int i;
Anchor
_Toc269456640
_Toc269456640
i=0;
Anchor
_Toc269456641
_Toc269456641
// initialize the API
Anchor
_Toc269456642
_Toc269456642
ChameleonInit();
Anchor
_Toc269456644
_Toc269456644
// link the chameleon variables
Anchor
_Toc269456645
_Toc269456645
LinkVars();
Anchor
_Toc269456647
_Toc269456647
// request an upload to synchronize the variable table
Anchor
_Toc269456648
_Toc269456648
CHAMELEONREQUESTUPLOAD();
Anchor
_Toc269456649
_Toc269456649
}

////////////////////////////////////////////////////////////////////
//
Anchor
_Toc269456653
_Toc269456653
Post any updates of network variables up to Chameleon
////////////////////////////////////////////////////////////////////
Anchor
_Toc269456655
_Toc269456655
when (nv_update_occurs)
Anchor
_Toc269456656
_Toc269456656
{
Anchor
_Toc269456657
_Toc269456657
// copy var
Anchor
_Toc269456658
_Toc269456658
FA_DigitalIn = RemEstop;
Anchor
_Toc269456660
_Toc269456660
// schedule a data upload to the module
Anchor
_Toc269456661
_Toc269456661
CHAMELEONREQUESTUPLOAD();
Anchor
_Toc269456662
_Toc269456662
}

////////////////////////////////////////////////////////////////////
//
Anchor
_Toc269456666
_Toc269456666
handle processing for any variable update from Chameleon
////////////////////////////////////////////////////////////////////
Anchor
_Toc269456668
_Toc269456668
when (bReceivedUpdate == TRUE)
Anchor
_Toc269456669
_Toc269456669
{
Anchor
_Toc269456671
_Toc269456671
// copy the values from Chameleon to the network variables
Anchor
_Toc269456673
_Toc269456673
if (OutputOperatorTable[0].bUpdated)
Anchor
_Toc269456674
_Toc269456674
LocalEstop = FA_DigitalOut;
Anchor
_Toc269456676
_Toc269456676
if (OutputOperatorTable[1].bUpdated)
Anchor
_Toc269456677
_Toc269456677
Temp = FA_AnalogOut[0];
Anchor
_Toc269456679
_Toc269456679
if (OutputOperatorTable[2].bUpdated)
Anchor
_Toc269456680
_Toc269456680
State = FA_AnalogOut[1];
Anchor
_Toc269456682
_Toc269456682
if (OutputOperatorTable[3].bUpdated)
Anchor
_Toc269456683
_Toc269456683
Speed = FA_AnalogOut[2];
Anchor
_Toc269456685
_Toc269456685
if (OutputOperatorTable[4].bUpdated)
Anchor
_Toc269456686
_Toc269456686
SetPt = FA_AnalogOut[3];
Anchor
_Toc269456688
_Toc269456688
bReceivedUpdate = FALSE;// clear update flag
Anchor
_Toc269456689
_Toc269456689
}