Author |
Topic |
|
ctacke
877 Posts |
Posted - 19 Aug 2002 : 13:29:12
|
Can I soft reset my ADS system through code?
Yes. A soft reset can be performed programmatically using the KernelIoControl API like this:
#define CTL_CODE( DeviceType, Function, Method, Access ) ( \ ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method)) #define FILE_DEVICE_HAL 0x00000101 #define METHOD_BUFFERED 0 #define FILE_ANY_ACCESS 0
#define IOCTL_HAL_REBOOT CTL_CODE(FILE_DEVICE_HAL, 15, METHOD_BUFFERED, FILE_ANY_ACCESS)
extern "C" __declspec(dllimport) BOOL KernelIoControl( DWORD dwIoControlCode, LPVOID lpInBuf, DWORD nInBufSize, LPVOID lpOutBuf, DWORD nOutBufSize, LPDWORD lpBytesReturned);
void SoftReset() {KernelIoControl(IOCTL_HAL_REBOOT, NULL,0, NULL, 0, 0);}
Aternatively you can call CreateProcess to launch restart.exe which in turn makes this same call.
----------------- Chris Tacke, eMVP Applied Data Support |
|
skydyvyr
2 Posts |
Posted - 07 Apr 2004 : 18:55:16
|
Is there a simple way to access this from VB.NET? |
|
|
akidder
1519 Posts |
Posted - 09 Apr 2004 : 14:02:07
|
You may be able to P/Invoke it, but I'm not familiar enough with VB.NET to give you a definitive answer.
We'll give a more detailed response at this topic in the next day or two. Cheers, Drew |
|
|
ctacke
877 Posts |
Posted - 12 Apr 2004 : 10:03:51
|
Here are managed versions of the code:
--------- [VB] Imports System.Runtime.InteropServices
<DllImport("coredll.dll", EntryPoint:="KernelIoControl", SetLastError:=True)> _ Private Shared Function KernelIoControl( _ ByVal dwIoControlCode As Integer, _ ByVal lpInBuf As IntPtr, _ ByVal nInBufSize As Integer, _ ByVal lpOutBuf As IntPtr, _ ByVal nOutBufSize As Integer, _ ByRef lpBytesReturned As Integer) As Boolean End Function
Private Const IOCTL_HAL_REBOOT As Integer = &H101003C
Public Function DeviceReset() As Boolean Dim b As Integer = 0 Return KernelIoControl(IOCTL_HAL_REBOOT, IntPtr.Zero, 0, IntPtr.Zero, 0, b) End Function
--------- [C#] using System.Runtime.InteropServices;
[DllImport("CoreDll.dll", SetLastError=true, CharSet=CharSet.Auto)] internal static extern bool KernelIoControl(int dwIoControlCode, IntPtr lpInBuf, int nInBufSize, IntPtr lpOutBuf, int nOutBufSize, ref int lpBytesReturned);
public bool DeviceReset() { int b = 0; return KernelIoControl(0x0101003C,IntPtr.Zero,0,IntPtr.Zero,0, ref b); }
|
|
|
skydyvyr
2 Posts |
Posted - 12 Apr 2004 : 19:55:18
|
I've tried to implement the code snippet you set with no success...
I've placed the code inside of a module within my project named ADSmartIO.vb. As a result, I've had to modify your code slightly to get it to run (and be called from other forms in my project) but I don't see how I broke it.
--Begin Code--
_ Private Shared Function KernelIoControl( _ ByVal dwIoControlCode As Integer, _ ByVal lpInBuf As IntPtr, _ ByVal nInBufSize As Integer, _ ByVal lpOutBuf() As Byte, _ ByVal nOutBufSize As Integer, _ ByRef lpBytesReturned As Integer) As Boolean End Function
Private Const IOCTL_HAL_REBOOT As Integer = &H4040003C
Public Shared Function DeviceReset() As Boolean Return KernelIoControl(IOCTL_HAL_REBOOT, Nothing, 0, Nothing, 0, Nothing) End Function
--End Code--
When I call the above code by:
Dim MyBool as Boolean MyBool = ADSmartIO.DeviceReset()
DeviceReset() returns False and the device (BitsyX running WinCE.NET build 4.20.01) does not reboot or throw any errors that I can find.
Any further suggestions?
TIA |
|
|
ctacke
877 Posts |
Posted - 13 Apr 2004 : 11:19:13
|
Yep. I didn't fully test the managed code before posting it. I made modifications to the code above and tested it under both languages and it now works. |
|
|
|
Topic |
|
|
|