...
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[
PDG:1][
PDG:15]={"RemEStop"};
Anchor |
---|
| _Toc269456595 |
---|
| _Toc269456595 |
---|
|
far char pKeysdo[
PDG:1][
PDG:15]={"LocalEStop"};
Anchor |
---|
| _Toc269456596 |
---|
| _Toc269456596 |
---|
|
far char pKeysao[
PDG:4][
PDG:15]={"Temp", "State", "Speed", "SetPt"};
Anchor |
---|
| _Toc269456597 |
---|
| _Toc269456597 |
---|
|
boolean FA_DigitalIn;
Anchor |
---|
| _Toc269456598 |
---|
| _Toc269456598 |
---|
|
boolean FA_DigitalOut;
Anchor |
---|
| _Toc269456599 |
---|
| _Toc269456599 |
---|
|
float_type FA_AnalogOut[
PDG:4];
////////////////////////////////////////////////////////////////////
//
Anchor |
---|
| _Toc269456602 |
---|
| _Toc269456602 |
---|
|
user structures to link to Chameleon
////////////////////////////////////////////////////////////////////
Anchor |
---|
| _Toc269456604 |
---|
| _Toc269456604 |
---|
|
far FAVarBlock OutputOperatorTable[
PDG:5];
Anchor |
---|
| _Toc269456605 |
---|
| _Toc269456605 |
---|
|
far FAVarBlock InputOperatorTable[
PDG: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[
PDG:i], &pKeysdi[
PDG:i][
PDG:0], FA_DigitalIn);
Anchor |
---|
| _Toc269456623 |
---|
| _Toc269456623 |
---|
|
}
Anchor |
---|
| _Toc269456624 |
---|
| _Toc269456624 |
---|
|
for (i=0;i<1;i++){
Anchor |
---|
| _Toc269456625 |
---|
| _Toc269456625 |
---|
|
ChameleonLinkVariableDown(&OutputOperatorTable[
PDG:i], &pKeysdo[
PDG:i][
PDG:0], FA_DigitalOut);
Anchor |
---|
| _Toc269456626 |
---|
| _Toc269456626 |
---|
|
}
Anchor |
---|
| _Toc269456627 |
---|
| _Toc269456627 |
---|
|
for (i=0,j=15;i<4;i+
,j+){
Anchor |
---|
| _Toc269456628 |
---|
| _Toc269456628 |
---|
|
ChameleonLinkVariableDown(&OutputOperatorTable[
PDG:j], &pKeysao[
PDG:i][
PDG:0], FA_AnalogOut[
PDG: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[
PDG:0].bUpdated)
Anchor |
---|
| _Toc269456674 |
---|
| _Toc269456674 |
---|
|
LocalEstop = FA_DigitalOut;
Anchor |
---|
| _Toc269456676 |
---|
| _Toc269456676 |
---|
|
if (OutputOperatorTable[
PDG:1].bUpdated)
Anchor |
---|
| _Toc269456677 |
---|
| _Toc269456677 |
---|
|
Temp = FA_AnalogOut[
PDG:0];
Anchor |
---|
| _Toc269456679 |
---|
| _Toc269456679 |
---|
|
if (OutputOperatorTable[
PDG:2].bUpdated)
Anchor |
---|
| _Toc269456680 |
---|
| _Toc269456680 |
---|
|
State = FA_AnalogOut[
PDG:1];
Anchor |
---|
| _Toc269456682 |
---|
| _Toc269456682 |
---|
|
if (OutputOperatorTable[
PDG:3].bUpdated)
Anchor |
---|
| _Toc269456683 |
---|
| _Toc269456683 |
---|
|
Speed = FA_AnalogOut[
PDG:2];
Anchor |
---|
| _Toc269456685 |
---|
| _Toc269456685 |
---|
|
if (OutputOperatorTable[
PDG:4].bUpdated)
Anchor |
---|
| _Toc269456686 |
---|
| _Toc269456686 |
---|
|
SetPt = FA_AnalogOut[
PDG:3];
Anchor |
---|
| _Toc269456688 |
---|
| _Toc269456688 |
---|
|
bReceivedUpdate = FALSE;// clear update flag
Anchor |
---|
| _Toc269456689 |
---|
| _Toc269456689 |
---|
|
}
LonTalk Operators Image Added Image Modified