Can I access USB HID on CE embedded from C#?

J

Jeff Louie

A bit of background. I have been asked to offer an independent
programming
study for high school students. I thought it would be really cool to
challenge
them with an embedded coding challenge on a embedded windows ce device.
I have a windows ce embedded device and development system up and
running. Now I want a practical example of an industrial control.
Reading
temperature from a USB device and displaying it in C# _seems_ like a
doable
project and very practical. I found a USB temperature probe that
supports HID
on ce.

http://www.toradex.com/e/usb_sensors.php

Below is the read me file. My question is can I call these methods from
C#? I
don't even know if C# on windows embedded supports PINVOKE. To put it
mildly I am a in a bit over my head here. Any answers appreciated.

Oak USB Sensor HID Driver for Windows CE 5.0
============================================

General
-------
The Oak USB Sensor HID Driver adds support for ToradexÆ USB Sensors to
Windows CE 5.0 operations systems. The driver provides a stream
interface
which allows using standard file system functions to access the device
such
as CreateFile, ReadFile, IOControl, and so on. Treating devices as
special files
is common to many operating systems. Serial ports traditionally have
been
represented by the COMx: special file names, similarly Oak USB Sensors
are
represented by the OAKx: special file names.

For more information about stream interface drivers please refere to
MSDN
documentation:
http://msdn2.microsoft.com/en-us/library/ms923745.aspx


Installation
------------
Copy and run the OakHidCE_v1.0.cab file on your Windows CE 5.0 target
system and choose an appropriate installation directroy. For persistent
driver
installation on ToradexÆ Colibri modules we recommend "\FlashDisk\" as
install dir.


Usage
-----
- Detect Oak sensor hot plugging by the events: OAK_ATTACH_EVENT and
OAK_DETACH_EVENT
(use GetEventData() to determine what sensor has been attached or
detached)

- Open sensor access: hOakDevice=CreateFile(L"OAKx:",....)

- Use/access sensor: ReadFile(hOakDevice,...)
DeviceIoControl(hOakDevice,IOCTL_OAK_...)

- Terminate sensor use: CloseHandle(hOakDevice)


Supported IOCTLs
----------------

- IOCTL_OAK_GET_INPUT_REPORT
- IOCTL_OAK_GET_FEATURE_REPORT
- IOCTL_OAK_SET_OUTPUT_REPORT
- IOCTL_OAK_SET_FEATURE_REPORT

- IOCTL_OAK_GET_INPUT_REPORT_LENGTH
- IOCTL_OAK_GET_OUTPUT_REPORT_LENGTH
- IOCTL_OAK_GET_FEATURE_REPORT_LENGTH

- IOCTL_OAK_GET_INPUT_VALUE_COUNT
- IOCTL_OAK_GET_OUTPUT_VALUE_COUNT

- IOCTL_OAK_GET_INPUT_VALUE_CAPS
- IOCTL_OAK_GET_OUTPUT_VALUE_CAPS

- IOCTL_OAK_GET_STRING_MANUFACT
- IOCTL_OAK_GET_STRING_PRODUCT
- IOCTL_OAK_GET_STRING_SERIAL
- IOCTL_OAK_GET_STRING_INDEXED

- IOCTL_OAK_GET_QUEUE_SIZE
- IOCTL_OAK_SET_QUEUE_SIZE

- IOCTL_OAK_GET_ACCESS_TIMEOUT
- IOCTL_OAK_SET_ACCESS_TIMEOUT

- IOCTL_OAK_GET_PRODUCT_ID


Regards,
Jeff
 
P

Pavel Minaev

A bit of background. I have been asked to offer an independent
programming
study for high school students. I thought it would be really cool to
challenge
them with an embedded coding challenge on a embedded windows ce device.
I have a windows ce embedded device and development system up and
running. Now I want a practical example of an industrial control.
Reading
temperature from a USB device and displaying it in C# _seems_ like a
doable
project and very practical. I found a USB temperature probe that
supports HID
on ce.

http://www.toradex.com/e/usb_sensors.php

Below is the read me file. My question is can I call these methods from
C#? I
don't even know if C# on windows embedded supports PINVOKE. To put it
mildly I am a in a bit over my head here. Any answers appreciated.

Oak USB Sensor HID Driver for Windows CE 5.0
============================================

General
-------
The Oak USB Sensor HID Driver adds support for ToradexÆ USB Sensors to
Windows CE 5.0 operations systems. The driver provides a stream
interface
which allows using standard file system functions to access the device
such
as CreateFile, ReadFile, IOControl, and so on.


Yes, you can call them from C# via P/Invoke. I'm not sure what kind of
Windows you have - is it WinCE or WinNT/XP/Vista Embedded? Anyway,
either one supports P/Invoke, though CE has some limitations.
 
J

Jeff Louie

Hi Pavel... Thanks for the quick reply. I am programming WindowsCE
embedded
using VisualStudio2005onXP and transferring/running the programs to a CE
device over an intranet. With your encouragement I will go ahead and try
to
PINVOKE on CE.

Regards,
Jeff
 
J

Jeff Louie

This compiled and executed on a ce device. Deployment, execution and
debugging also worked over an intranet!

public class SomeClass
{
private uint OldCnt;
public SomeClass()
{
OldCnt = 0;
}
[DllImport ("coredll.dll")]
private static extern uint GetTickCount ();

public uint TicksSinceLast (){
uint ticks = GetTickCount();
uint diff = ticks - OldCnt;
OldCnt = ticks;
return diff;
}
}

public partial class Form1 : Form
{
private SomeClass sc = new SomeClass();
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = "Hello World "+sc.TicksSinceLast();

}

Regards,
Jeff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top