【C#】初始化三菱运动卡
-
添加三菱dll引用
-
WPF实现
2.1、方法一:引用AxInterop.ActUtlTypeLib.dll实现
添加WindowsFormsIntegration 引用
初始化代码
//解决因为第三方控件报错,将实例化的对象添加到控件合集中
System.Windows.Controls.Grid CTSGrid = new System.Windows.Controls.Grid();
System.Windows.Forms.Integration.WindowsFormsHost host = null;
host = new System.Windows.Forms.Integration.WindowsFormsHost();
host.Child = actUtlTypeLib.AxActUtlType;
((ISupportInitialize)actUtlTypeLib.AxActUtlType).BeginInit();
CTSGrid.Children.Add(host);
((ISupportInitialize)actUtlTypeLib.AxActUtlType).EndInit();
2.2、方法二:引用Interop.ActUtlTypeLib.dll实现
初始化
ActUtlType AxActUtlType= new ActUtlType();
/// 打开线路连接
/// </summary>
/// <param name="stationNumber"></param>
/// <returns></returns>
public bool Connect(int stationNumber)
{
AxActUtlType.ActLogicalStationNumber = stationNumber;
if (0 == AxActUtlType.Connect())
{
IsConnected = true;
return true;
}
return false;
}
/// <summary>
/// 关闭线路连接
/// </summary>
/// <returns></returns>
public int Disconnect()
{
IsConnected = false;
return AxActUtlType.Disconnect();
}
/// <summary>
/// 读设备数据
/// </summary>
/// <param name="deviceName"></param>
/// <param name="size"></param>
/// <param name="oInt"></param>
/// <returns></returns>
public bool Reader(string deviceName, int size, out int[] oInt)
{
oInt = new int[size];
if (Reader(deviceName, size * 2, out short[] oInt2))
{
for (int i = 0; i < size; i++)
{
oInt[i] = (oInt2[i * 2 + 1] << 16) + oInt2[i * 2];
}
return true;
}
return false;
}
- WINFROM实现
初始化代码
//解决因为第三方控件报错,将实例化的对象添加到控件合集中
((ISupportInitialize)(this.axActUtlType1)).BeginInit();
this.Controls.Add(axActUtlType1);
((ISupportInitialize)(this.axActUtlType1)).EndInit();