发表于:2003-02-13 09:00:00
5楼
That is very easy to do !
If you have a network called "myNetwork1" which have a subSystem called "Subsystem 1" which is what LonMaker (LMW) will produce for you by default. In this subSystem you could have a device called e.g. "Device 1". The device could have a NodeBuilder 3 neuron C application that look like this:
msg_tag tag_out;
...
...
...
void generic_send_msg(int code, int data[], int length) {
int i;
// Send a message to the tag_out
msg_out.tag = tag_out;
msg_out.code = code;
for (i=0; i < length; i++)
msg_out.data[i] = data[i];
msg_send();
}
when (msg_arrives)
{
int code;
int data[1];
code = msg_in.code;
data[0] = msg_in.data[0];
switch (code) {
case 11:
data[0] = data[0] + 5; // Add 1 to received msg data element 1
generic_send_msg(code, data, 1);
break;
case 12:
data[0] = data[0] + 6; // Add 2 to received msg data element 1
generic_send_msg(code, data, 1);
break;
default:
// For all other msg codes do nothing!
break;
}
}
a) Create and deploy above NB3 device
b) Create a dynamic msg point on e.g. you network interface device virtual function block and bind Device 1 msg_out to it. This is important as otherwise the device will not propagate the outbound messages to the network!
Now, lets say you have a excel spreadsheet in which you wand to monitor what messages are being send and received from and to the device.
1) Create a new Excel spreadsheet
2) Enter <=LNSDDE|myNetwork1.Subsystem 1.MT!Device 1.msg_in> in cell "A1" (without the <>)
3) Enter <=LNSDDE|myNetwork1.Subsystem 1.MT!Device 1.msg_out> in cell "A2" (without the <>)
4) create a button and e.g. called the default "CommandButton1" and define the following VB program for the button using VB for applications:
Private Sub CommandButton1_Click()
Dim chan As Long
// Initiate DDE on topic
chan = DDEInitiate("LNSDDE", "myNetwork1.Subsystem 1.MT")
DDEPoke chan, "Device 1.msg_out", Range("A3")
DDETerminate (chan)
End Sub
5) Enter "11" in cell "A3" and hit the button "CommandButton1" and you should see the value "11.00...." which is the value send to the device written written in cell "A2" and the msg returned by the NC application in cell "A1" which should be "11,5" (code = 11, data[0] = 5)
6) Enter "12" in cell "A3" and hit the button "CommandButton1" and you should see the value "12.00...." which is the value send to the device written in cell "A2" and the msg returned by the NC application in cell "A1" which should be "12,6" (code = 12, data[0] = 6)
7) If you enter "13" in cell "A3" and hit the button "CommandButton1" then you should not see any update of cell "A1" and "A2"