解决C#调用DLL托管于非托管匹配的问题。
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
@@ -25,7 +26,6 @@
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
|
||||
+13
-4
@@ -49,13 +49,22 @@ namespace Sys
|
||||
SSI_STATUS_MACHINE_UNINITIALIZED,
|
||||
SSI_STATUS_UNKNOWN_ERROR
|
||||
};
|
||||
[DllImport("MachineInterfaceDll.dll")]
|
||||
[DllImport("MachineInterfaceDll.dll",CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern SSI_STATUS_MOTION Machine_Startup(bool bOfflineOnly, EHOME_MACHINE_MODE cHomeMachineMode);
|
||||
[DllImport("MachineInterfaceDll.dll")]
|
||||
|
||||
[DllImport("MachineInterfaceDll.dll", EntryPoint = "Machine_Shutdown",
|
||||
SetLastError = true, CharSet = CharSet.Unicode,
|
||||
ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern SSI_STATUS_MOTION Machine_Shutdown();
|
||||
[DllImport("MachineInterfaceDll.dll")]
|
||||
|
||||
[DllImport("MachineInterfaceDll.dll", EntryPoint = "Machine_GetDIO",
|
||||
SetLastError = true, CharSet = CharSet.Unicode,
|
||||
ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern SSI_STATUS_MOTION Machine_GetDIO(EIO_PORT Channel, ref Byte bDISts);
|
||||
[DllImport("MachineInterfaceDll.dll")]
|
||||
|
||||
[DllImport("MachineInterfaceDll.dll", EntryPoint = "Machine_SetDO",
|
||||
SetLastError = true, CharSet = CharSet.Unicode,
|
||||
ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern SSI_STATUS_MOTION Machine_SetDO(EIO_PORT Channel, Byte bDOSts);
|
||||
|
||||
}
|
||||
|
||||
@@ -12,11 +12,55 @@ namespace ConsoleTestDll
|
||||
MACHINEINTERFACEDLL.SSI_STATUS_MOTION rStatus;
|
||||
Console.WriteLine("Machine_Startup.");
|
||||
rStatus = MACHINEINTERFACEDLL.Machine_Startup(false, MACHINEINTERFACEDLL.EHOME_MACHINE_MODE.HOME_XYZ);
|
||||
Console.WriteLine("RStatus:{0}\n",rStatus);
|
||||
Console.WriteLine("RStatus:{0}\n", rStatus);
|
||||
Byte bDISts = 0;
|
||||
Console.WriteLine("Machine_GetDIO.");
|
||||
rStatus = MACHINEINTERFACEDLL.Machine_GetDIO(MACHINEINTERFACEDLL.EIO_PORT.LIMIT_SWITCH_J4, ref bDISts);
|
||||
Console.WriteLine("RStatus:{0}\n", rStatus);
|
||||
bool IOStatus = false;
|
||||
int iComp1 = 1;
|
||||
int iComp2 = 0;
|
||||
int i = 0;
|
||||
Console.WriteLine("IOStatus:");
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
iComp2=iComp1 << i;
|
||||
if ((bDISts & iComp2) == iComp2)
|
||||
{
|
||||
IOStatus = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
IOStatus = false;
|
||||
}
|
||||
Console.WriteLine("{0} ", IOStatus);
|
||||
}
|
||||
|
||||
Console.WriteLine("Wait...");
|
||||
Console.ReadLine();
|
||||
Console.WriteLine("Machine_GetDIO.");
|
||||
bDISts = 0;
|
||||
rStatus = MACHINEINTERFACEDLL.Machine_GetDIO(MACHINEINTERFACEDLL.EIO_PORT.LIMIT_SWITCH_J4, ref bDISts);
|
||||
Console.WriteLine("RStatus:{0}\n", rStatus);
|
||||
i = 0;
|
||||
Console.WriteLine("IOStatus:");
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
iComp2 = iComp1 << i;
|
||||
if ((bDISts & iComp2) == iComp2)
|
||||
{
|
||||
IOStatus = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
IOStatus = false;
|
||||
}
|
||||
Console.WriteLine("{0} ", IOStatus);
|
||||
}
|
||||
Console.WriteLine("Machine_Shutdown");
|
||||
rStatus = MACHINEINTERFACEDLL.Machine_Shutdown();
|
||||
Console.WriteLine("RStatus:{0}\n", rStatus, ".\n");
|
||||
Console.WriteLine("Press enter key to exit...");
|
||||
Console.WriteLine("RStatus:{0}\n", rStatus);
|
||||
Console.WriteLine("Press enter key to exit...");
|
||||
Console.ReadLine();
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user