Here's a C# class that controls the buzzer on the board. I think it will only run on the new CE6 images which have system support for the buzzer. This makes it super easy to make the buzzer work! I can convert it to VB.Net if people want it...
Code: Select all
class Buzzer {
[DllImport("coredll.dll", EntryPoint = "DeviceIoControl", SetLastError = true)]
internal static extern int DeviceIoControlCE(int hDevice, int dwIoControlCode, byte[] lpInBuffer, int nInBufferSize, byte[] lpOutBuffer, int nOutBufferSize, ref int lpBytesReturned, IntPtr lpOverlapped);
[DllImport("coredll", SetLastError = true)]
private static extern IntPtr CreateFile(string lpFileName, uint dwDesiredAccess, uint dwShareMode, IntPtr lpSecurityAttributes, uint dwCreationDisposition, uint dwFlagsAndAttributes, IntPtr hTemplateFile);
private static IntPtr _pwmFile = CreateFile("PWM1:", 0x40000000, 0, IntPtr.Zero, 3, 0, IntPtr.Zero);
private Buzzer() {
}
public static void Beep() {
Beep(1000, 20);
}
public static void Beep(uint Frequency, int DurationMS) {
uint frequency = Frequency;
byte[] buffer = new byte[4];
int accessType = 2;
buffer[0] = (byte)(frequency & 0xff);
frequency = frequency >> 8;
buffer[1] = (byte)(frequency & 0xff);
frequency = frequency >> 8;
buffer[2] = (byte)(frequency & 0xff);
frequency = frequency >> 8;
buffer[3] = (byte)(frequency & 0xff);
DeviceIoControlCE((int)_pwmFile, accessType, buffer, 4, buffer, 0, ref accessType, IntPtr.Zero);
var t = new System.Threading.Timer(TurnOff, null, DurationMS, System.Threading.Timeout.Infinite);
}
private static void TurnOff(Object obj) {
byte[] buffer = new byte[4];
int accessType = 1;
DeviceIoControlCE((int)_pwmFile, accessType, buffer, 4, buffer, 0, ref accessType, IntPtr.Zero);
}
}