از دوستان کسی میدونه چه طور میشه توسط c# به pwm_buzzer mini2440 دسترسی پیدا کرد و اونو به صدا در اورد؟!
اطلاعیه
Collapse
No announcement yet.
دسترسی به pwm-buzzer mini2440 توسط c#
Collapse
X
-
پاسخ : دسترسی به pwm-buzzer mini2440 توسط c#
سلام و درود بر شما دوست عزیز
راستش من تا حالا با این برد کار نکردم ( فقط از نزدیک سعادت دیدن این برد را داشتم :mrgreen: )
ولی علاوه بر کمک گرفتن از دوستان عزیز در سایت میتونید به گروه زیر بپیوندین و سوالاتتون یا حتی سوالات دیگر دوستان ( که عمدتا غیر ایرانی هستن ) را مشاهده کنید.
http://groups.google.com/group/mini2440
موفق باشید**همیشه به این فکر کن که خداوند با توست**
-
پاسخ : دسترسی به pwm-buzzer mini2440 توسط c#
سلام
برای wince 6 این کد کار میکنه . ولی در wince5 تست نکردم ( فکر کنم کار نکنه ) . نحوه دسترسی در ce6 با DLL هست و در CE5 بصورت memory map .
کد vb.net
Public Class Buzzer
<DllImport("coredll.dll"> _
Public Shared Function DeviceIoControl(ByVal hDevice As Integer, ByVal dwIoControlCode As Integer, ByVal lpInBuffer As Byte(), ByVal nInBufferSize As Integer, ByVal lpOutBuffer As Byte(), ByVal nOutBufferSize As Integer, ByRef lpBytesReturned As Integer, ByVal lpOverlapped As IntPtr) As Integer
End Function
<DllImport("coredll.dll"> _
Public Shared Function CreateFile(ByVal lpFileName As String, ByVal dwDesiredAccess As UInteger, ByVal dwShareMode As UInteger, ByVal lpSecurityAttributes As IntPtr, ByVal dwCreationDisposition As UInteger, ByVal dwFlagsAndAttributes As UInteger, ByVal hTemplateFile As IntPtr) As IntPtr
End Function
Private Shared _pwmFile As IntPtr = CreateFile("PWM1:", &H40000000, 0, IntPtr.Zero, 3, 0, IntPtr.Zero)
Private Sub New()
End Sub
Public Shared Sub Beep()
Beep(4000, 20)
End Sub
Public Shared Sub Beep(ByVal Frequency As UInteger, ByVal DurationMS As Integer)
Dim freq As UInteger = Frequency
Dim buffer(4) As Byte
Dim accessType As Integer = 2
buffer(0) = CType((Frequency And &HFF), Byte)
Frequency = Frequency >> 8
buffer(1) = CType((Frequency And &HFF), Byte)
Frequency = Frequency >> 8
buffer(2) = CType((Frequency And &HFF), Byte)
Frequency = Frequency >> 8
buffer(3) = CType((Frequency And &HFF), Byte)
DeviceIoControl(_pwmFile, accessType, buffer, 4, buffer, 0, accessType, IntPtr.Zero)
Dim t As New System.Threading.Timer(AddressOf TurnOff, Nothing, DurationMS, System.Threading.Timeout.Infinite)
End Sub
Private Shared Sub TurnOff(ByVal obj As Object)
Dim buffer(4) As Byte
Dim accessType As Integer = 1
DeviceIoControl(_pwmFile, accessType, buffer, 4, buffer, 0, accessType, IntPtr.Zero)
End Sub
End Class
کد c#
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
public class Buzzer
{
[DllImport("coredll.dll"]
public static extern int DeviceIoControl(int hDevice, int dwIoControlCode, byte[] lpInBuffer, int nInBufferSize, byte[] lpOutBuffer, int nOutBufferSize, ref int lpBytesReturned, IntPtr lpOverlapped);
[DllImport("coredll.dll"]
public 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()
{
Interaction.Beep(4000, 20);
}
public static void Beep(uint Frequency, int DurationMS)
{
uint freq = Frequency;
byte[] buffer = new byte[5];
int accessType = 2;
buffer[0] = Convert.ToByte((Frequency & 0xff));
Frequency = Frequency >> 8;
buffer[1] = Convert.ToByte((Frequency & 0xff));
Frequency = Frequency >> 8;
buffer[2] = Convert.ToByte((Frequency & 0xff));
Frequency = Frequency >> 8;
buffer[3] = Convert.ToByte((Frequency & 0xff));
DeviceIoControl(_pwmFile, accessType, buffer, 4, buffer, 0, ref accessType, IntPtr.Zero);
System.Threading.Timer t = new System.Threading.Timer(TurnOff, null, DurationMS, System.Threading.Timeout.Infinite);
}
private static void TurnOff(object obj)
{
byte[] buffer = new byte[5];
int accessType = 1;
DeviceIoControl(_pwmFile, accessType, buffer, 4, buffer, 0, ref accessType, IntPtr.Zero);
}
}
این کد کلاس هست . کافی روتین beep را از کلاس اجرا کنید
در ساب buzzer میتونید فرکانس و زمان را تعیین کنید
نوفن پردازش هوشمند
دیدگاه
-
پاسخ : دسترسی به pwm-buzzer mini2440 توسط c#
نوشته اصلی توسط ARSTسلام
برای wince 6 این کد کار میکنه . ولی در wince5 تست نکردم ( فکر کنم کار نکنه ) . نحوه دسترسی در ce6 با DLL هست و در CE5 بصورت memory map .
کد vb.net
دیدگاه
دیدگاه