using System; using System.Text; using System.Runtime.InteropServices; using System.Security; using System.Security.Permissions; namespace Mesnac.Equip.AllenBradley.AB5000.Net { public class DTL32 { public struct DtlDriver { public ushort wType; public ushort wLength; public ushort wMfgMask; public ushort wNetworkType; public ushort wDriverID; public ushort wDstDriverID; public uint dwHandle; public uint dwStation; public uint dwMaxStation; public ushort wCapabilities; public ushort wMTU; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public char[] szDriverName; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public char[] szDriverAlias; public byte bAddrRadix; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] public byte[] bReserved; } private class DllImport { [DllImport("DTL32.dll")] public extern static int DTL_INIT(uint id); [DllImport("DTL32.dll")] public extern static int DTL_UNINIT(uint dwError); [DllImport("DTL32.dll")] public extern static int DTL_DRIVER_LIST(IntPtr dtlDriver, ref uint drivers, int timeout); [DllImport("DTL32.dll")] public extern static int DTL_DRIVER_OPEN(uint id, string name, int timeout); [DllImport("DTL32.dll")] public extern static int DTL_DRIVER_CLOSE(uint id, int timeout); [DllImport("DTL32.dll")] public extern static int DTL_C_DEFINE(ref uint id, StringBuilder defString); [DllImport("DTL32.dll")] public extern static int DTL_UNDEF(uint id); [DllImport("DTL32.dll")] public extern static int DTL_READ_W(uint name_id, ushort[] buff, ref int state, int timeout); [DllImport("DTL32.dll")] public extern static int DTL_WRITE_W(uint name_id, ushort[] buff, ref int state, int timeout); } public static int DTL_INIT(uint tableSize) { new UIPermission(UIPermissionWindow.AllWindows).Demand(); return DllImport.DTL_INIT(tableSize); } public static int DTL_UNINIT(uint dwError) { new UIPermission(UIPermissionWindow.AllWindows).Demand(); return DllImport.DTL_UNINIT(dwError); } public static int DTL_DRIVER_LIST(IntPtr dtlDriver, ref uint drivers, int timeout) { new UIPermission(UIPermissionWindow.AllWindows).Demand(); return DllImport.DTL_DRIVER_LIST(dtlDriver, ref drivers, timeout); } public static int DTL_DRIVER_OPEN(uint id, string name, int timeout) { new UIPermission(UIPermissionWindow.AllWindows).Demand(); return DllImport.DTL_DRIVER_OPEN(id, name, timeout); } public static int DTL_DRIVER_CLOSE(uint id, int timeout) { new UIPermission(UIPermissionWindow.AllWindows).Demand(); return DllImport.DTL_DRIVER_CLOSE(id, timeout); } public static int DTL_C_DEFINE(ref uint id, string defString) { new UIPermission(UIPermissionWindow.AllWindows).Demand(); StringBuilder def = new StringBuilder(); def.Append(defString); return DllImport.DTL_C_DEFINE(ref id, def); } public static int DTL_UNDEF(uint id) { new UIPermission(UIPermissionWindow.AllWindows).Demand(); return DllImport.DTL_UNDEF(id); } public static int DTL_READ_W(uint name_id, ushort[] buff, ref int state, int timeout) { new UIPermission(UIPermissionWindow.AllWindows).Demand(); return DllImport.DTL_READ_W(name_id, buff, ref state, timeout); } public static int DTL_WRITE_W(uint name_id, ushort[] buff, ref int state, int timeout) { new UIPermission(UIPermissionWindow.AllWindows).Demand(); return DllImport.DTL_WRITE_W(name_id, buff, ref state, timeout); } } }