委托已回收
源码如下:using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using OnlineSigmatek;
namespace RefreshListSample
{
/// <summary>
/// Interaktionslogik für Window1.xaml
/// </summary>
public partial class Window1 : Window
{
int iRlb;
Lasal32.SRLVarInfo var1;
Lasal32.SRLVarInfo var2;
uint VarID;
int Data;
public Window1()
{
InitializeComponent();
this.iRlb = 0;
this.var1 = new Lasal32.SRLVarInfo();
this.var2 = new Lasal32.SRLVarInfo();
}
// delegate
public void RefListCallBack(uint dwCallbackData, uint dwAddr, uint dwVarID, int nData)
{
Console.WriteLine("Id=" + dwVarID.ToString() + " Data=" + nData.ToString());
// dwCallbackData ... will be 2345 (user specified)
// dwAddr ........... lasalid of changed server
// dwVarID .......... will be 88 or 99 (user specified)
// nData ............ changed value (datasize <= 32bit) or crc32 of changed data (datasize > 32bit)
//... // user has to act on changed value
VarID = dwVarID;
Data = nData;
textBox1.Text = VarID.ToString();
textBox2.Text = Data.ToString();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
Lasal32.CB_RLADD_FUNCTYPE methptr = new Lasal32.CB_RLADD_FUNCTYPE(RefListCallBack);
this.iRlb = Lasal32.LslRefreshListCreateExt("TCP:10.10.150.37;ApplID=10", 0, 0, 0, null, methptr, 2345, 10000);
if (this.iRlb != 0)
{
if (Lasal32.LslRefreshListGetVarInfo(this.iRlb, "Obj_Csharptest.ListServer", ref this.var1) == true)
Lasal32.LslRefreshListAdd(this.iRlb, ref this.var1, 88, 100, Lasal32.CpReflist.RF_DYNAMIC); // add entry to refreshlist
if (Lasal32.LslRefreshListGetVarInfo(this.iRlb, "Obj_Csharptest.Position", ref this.var2) == true)
Lasal32.LslRefreshListAdd(this.iRlb, ref this.var2, 99, 100, Lasal32.CpReflist.RF_DYNAMIC); // add entry to refreshlist
// ... add some more if you want
Lasal32.LslRefreshListStart(this.iRlb, Lasal32.CpReflist.RF_DYNAMIC); // start refreshlist
// ... watch outputwindow
}
}
private void button2_Click(object sender, RoutedEventArgs e)
{
if(this.iRlb != 0)
Lasal32.LslRefreshListDestroy(this.iRlb); // destroy refreshlist
}
}
}