Visual Studio中的DDE链接

时间:2014-05-13 17:48:18

标签: c# dde

我正在使用Visual Studio(C#)程序(已编译/发布),并希望使用DDE链接(WinWedge)来监视数据。流入WinWedge的数据将是读取的数据。正在读取的数据将连接到仪表,仪表将根据数据进行调整。我知道如何在VB Excel宏中执行此操作,但我想使用更强大的语言,如C#。我不知道如何编写代码,但我使用的是开源NDde,并希望有助于解决如何对此进行编码以进行连接。 (来源:http://ndde.codeplex.com/

Excel VBA宏:

Sub GetSWData()
Dim R As Long
Dim Chan As Long
Dim Feed_1, Feed_1_Units, Feed_2, Feed_2_Units, Dout_1, Dout_1_Units, Dout_2, Dout_2_Units As Variant
Dim vDat As Variant
Dim sDat As String

' Find the next blank row in Column A (Sheet 2)
R = ThisWorkbook.Sheets("Data").Cells(65000, 1).End(xlUp).Row + 1

Chan = DDEInitiate("WinWedge", "Com12") ' Establish DDE link to WinWedge on Com1

Feed_1 = DDERequest(Chan, "Field(3)")
ThisWorkbook.Sheets("Data").Cells(R, 2).Value = Feed_1(1)
Feed_1_Units = DDERequest(Chan, "Field(4)")
ThisWorkbook.Sheets("Data").Cells(R, 3).Value = Feed_1_Units(1)

ThisWorkbook.Sheets("Static").Cells(2, 2).Value = Feed_1(1)
ThisWorkbook.Sheets("Static").Cells(2, 3).Value = Feed_1_Units(1)

Feed_2 = DDERequest(Chan, "Field(9)")
ThisWorkbook.Sheets("Data").Cells(R, 4).Value = Feed_2(1)
Feed_2_Units = DDERequest(Chan, "Field(10)")
ThisWorkbook.Sheets("Data").Cells(R, 5).Value = Feed_2_Units(1)

ThisWorkbook.Sheets("Static").Cells(2, 4).Value = Feed_2(1)
ThisWorkbook.Sheets("Static").Cells(2, 5).Value = Feed_2_Units(1)

Dout_1 = DDERequest(Chan, "Field(15)")
ThisWorkbook.Sheets("Data").Cells(R, 6).Value = Dout_1(1)
Dout_1_Units = DDERequest(Chan, "Field(16)")
ThisWorkbook.Sheets("Data").Cells(R, 7).Value = Dout_1_Units(1)

ThisWorkbook.Sheets("Static").Cells(2, 6).Value = Dout_1(1)
ThisWorkbook.Sheets("Static").Cells(2, 7).Value = Dout_1_Units(1)

Dout_2 = DDERequest(Chan, "Field(21)")
ThisWorkbook.Sheets("Data").Cells(R, 8).Value = Dout_2(1)
Dout_2_Units = DDERequest(Chan, "Field(22)")
ThisWorkbook.Sheets("Data").Cells(R, 9).Value = Dout_2_Units(1)

ThisWorkbook.Sheets("Static").Cells(2, 8).Value = Dout_2(1)
ThisWorkbook.Sheets("Static").Cells(2, 9).Value = Dout_2_Units(1)

' Close the DDE channel
DDETerminate Chan

' Insert a date/time stamp in the sheet in the same row as the data
ThisWorkbook.Sheets("Data").Cells(R, 1).Value = Now

ThisWorkbook.Sheets("Static").Cells(2, 1).Value = Now

End Sub

它完美无缺;它从WinWedge获取字段(param)并将其放入单元格中。对于C#程序,我想将WinWedge连接到我的C#应用​​程序,只是能够引用字段(值),以便实时更新仪表。

0 个答案:

没有答案