C#的DDE工控应用的B/S开发

1:项目前提:上海市排水公司积水点监测系统升级,现有DDE服务,那只能通过DDECLIENT去访问了。客户又是要求B/S系统,这次又是放弃C/S系统进行开发.现在:整个项目使用 "设备" - DDESERVER - DDEClient - 中间件 - WEB 这样一个架构.(该项目已通过城投公司领导的汇报确认)2:特点,主要完成DdeClient,与中间件服务业务功能.而中间件的服务主要是将数
摘要由CSDN通过智能技术生成

1:项目前提:上海市排水公司积水点监测系统升级,现有DDE服务,那只能通过DDECLIENT去访问了。客户又是要求B/S系统,这次又是放弃C/S系统进行开发.现在:整个项目使用 "设备" - DDESERVER - DDEClient - 中间件 - WEB 这样一个架构.(该项目已通过城投公司领导的汇报确认)

2:特点,主要完成DdeClient,与中间件服务业务功能.而中间件的服务主要是将数据提供给B/S

DDE思路:通过Advise动态交换DDE服务上的数据,通过POKE向DDE服务写数据,用于反控与参数设置!
注意:DDE API需要用户调用API自己封装,点NET并不提供DDE的开发模块!

3:内部运行的图,可参考“OPC的开发”,http://blog.csdn.net/zerodj/archive/2006/01/25/588289.aspx
4:DDE得到数据后,使用特定的公式转换出实际需要显示的数据!

5:DDE上Advise的事件
private static void MyClient_Advise(object sender, DdeClient.AdviseEventArgs args)
  {
   string sPrmValue = System.Text.Encoding.ASCII.GetString(args.Data).Replace(System.Environment.NewLine, "");
   string sPrmName  = args.Item;
   string sWhere = "PENAME = '" + sPrmNa

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
DDE(Dynamic Data Exchange)是一种在 Windows 操作系统中使用的进程间通信(IPC)机制。使用DDE,一个应用程序可以向另一个应用程序发送数据或请求数据。在C#中,可以使用System.Windows.Forms命名空间中的DdeClient类来实现DDE客户端。 以下是一个简单的DDE客户端示例,它将连接到Microsoft Excel并获取单元格A1的值: ```csharp using System; using System.Windows.Forms; using System.Runtime.InteropServices; using System.Security.Permissions; namespace DDEClientExample { public partial class Form1 : Form { private const int WM_DDE_ACK = 0x03; private const int WM_DDE_DATA = 0x05; [DllImport("user32.dll")] private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam); [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)] protected override void WndProc(ref Message m) { if (m.Msg == WM_DDE_DATA) { // Get the data from the DDE server string data = Marshal.PtrToStringAuto(m.LParam); // Display the data MessageBox.Show(data); } else if (m.Msg == WM_DDE_ACK) { // The DDE server has acknowledged our connection request MessageBox.Show("Connected to DDE server."); } base.WndProc(ref m); } public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { // Connect to Microsoft Excel DdeClient ddeClient = new DdeClient("excel", "sheet1"); // Subscribe to the DDE server's events ddeClient.Disconnected += DdeClient_Disconnected; ddeClient.Advise += DdeClient_Advise; // Connect to the DDE server ddeClient.Connect(); // Request data from the DDE server byte[] data = ddeClient.Request("A1"); // Disconnect from the DDE server ddeClient.Disconnect(); } private void DdeClient_Disconnected(object sender, EventArgs e) { MessageBox.Show("Disconnected from DDE server."); } private void DdeClient_Advise(object sender, DdeAdviseEventArgs e) { // Handle DDE advise events here } } } ``` 在此示例中,我们使用 DdeClient 类连接到 Microsoft Excel 的“sheet1”工作表,并使用 Request 方法获取单元格 A1 的值。我们还订阅了 DDE 服务器的 Disconnected 和 Advise 事件。 请注意,DDE 已经过时,Microsoft 建议使用其他通信机制,例如 COM、.NET Remoting 或 WCF。如果可能的话,应该尽量避免使用 DDE
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值