C # wince buzzer voice C # Call the device driver Function

Source: Internet
Author: User

Using system;
Using system. Collections. Generic;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. text;
Using system. Windows. forms;
Using system. runtime. interopservices;
Using system. Threading;

Namespace createfile
{
Unsafe public partial class form1: Form
{
Const uint32 open_existing = 3;
Const uint32 generic_read = 0x80000000;
Const uint32 generic_write = 0x40000000;
Const int32 invalid_handle_value =-1;

Private intptr hport;

// PWM control word, source tq2440/src/Drivers/pwmdriver. h file
Const uint32 ioctl_pwm_set_prescaler = 1;
Const uint32 ioctl_pwm_set_divider = 2;
Const uint32 ioctl_pwm_start = 3;
Const uint32 ioctl_pwm_get_frequency = 4;

[Dllimport ("coredll. dll")]
Public static extern intptr createfile (
String lpfilename,
Uint32 dwdesiredaccess,
Uint32 dwsharemode,
Intptr lpsecurityattributes,
Uint32 dwcreationdisposition,
Uint32 dwflagsandattributes,
Intptr htemplatefile
);
[Dllimport ("coredll. dll")]
Public static extern bool deviceiocontrol (
Intptr hdevice,
Uint32 dwiocontrolcode,
Uint32 [] lpinbuffer,
Uint32 ninbuffersize,
Byte [] lpoutbuffer,
Uint32 noutbuffersize,
Uint32 lpbytesreturned,
Intptr lpoverlapped
);

Public form1 ()
{
Initializecomponent ();
Hport = createfile ("pwm1:", generic_read | generic_write, 0, intptr. Zero, open_existing, 0,

Intptr. Zero );

If (hport = (intptr) invalid_handle_value)
{
MessageBox. Show ("Open PWM driver fail ");
}

}

Private void button#click (Object sender, eventargs E)
{
Uint32 [] buff = new uint32 [3] {0,488,244}; // 488,244 Source
/* Int freq = 800; // initial working frequency value
# Define s3c2440_pclk 50000000 // pclk is 50 MHz
# Define prescaler0 15 // pre-Division
# Define mux0 8 // timer frequency division Value
# Define tcntb0 (s3c2440_pclk/128/freq) // operating frequency
# Define tcmpb0 (tcntb0> 1) // duty cycle. The default value is 50%.

Byte prescale [2] = {0, prescaler0 };
Byte divider [2] = {0, mux0 };
DWORD buff [3] = {0, tcntb0, tcmpb0 };*/
Uint32 [] prescale = new uint32 [2] {0, 15 };
Uint32 [] divider = new uint32 [2] {0, 8 };
// Initialize the hardware
Deviceiocontrol (hport, ioctl_pwm_set_prescaler, prescale, 2, null, 0, 0, intptr. Zero );
Deviceiocontrol (hport, ioctl_pwm_set_divider, divider, 2, null, 0, 0, intptr. Zero );

// Deviceiocontrol (hport, ioctl_pwm_start, buff, 3, null, 0, 0, intptr. Zero );
Thread t = new thread (HH );
Button2.enabled = false;
Timer1.enabled = true;
T. Start ();
While (button2.enabled = false );
T. Abort ();
}
Public void HH ()
{
Uint32 [] buff = new uint32 [3] {0,488,244}; // 488,244 Source
Deviceiocontrol (hport, ioctl_pwm_start, buff, 3, null, 0, 0, intptr. Zero );
}

Private void timereffectick (Object sender, eventargs E)
{
Button2.enabled = true;
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.