All Forums
 Microsoft Windows CE
 eVC Application Development
 Soft Reset Through Code
 Forum Locked
 Send Topic to a Friend
 Printer Friendly
Author Topic  

ctacke

877 Posts

Posted - 19 Aug 2002 :  13:29:12  Show Profile  Email Poster
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  Show Profile  Email Poster
Is there a simple way to access this from VB.NET?
Go to Top of Page

akidder

1519 Posts

Posted - 09 Apr 2004 :  14:02:07  Show Profile  Email Poster
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
Go to Top of Page

ctacke

877 Posts

Posted - 12 Apr 2004 :  10:03:51  Show Profile  Email Poster
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);
}
Go to Top of Page

skydyvyr

2 Posts

Posted - 12 Apr 2004 :  19:55:18  Show Profile  Email Poster
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
Go to Top of Page

ctacke

877 Posts

Posted - 13 Apr 2004 :  11:19:13  Show Profile  Email Poster
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.
Go to Top of Page
  Topic  
 Forum Locked
 Send Topic to a Friend
 Printer Friendly
Jump To:
Eurotech Support Forums © Eurotech Inc. Go To Top Of Page
This page was generated in 0.03 seconds. Snitz Forums 2000