c# - 以编程方式访问 Motorola MC9500 运动传感器?

标签 c# windows-mobile-6.5 motion-detection motorola-emdk

我目前正在为 Motorola MC9500 开发 Windows Mobile 应用程序,该应用程序具有 Windows Mobile 6.5。 我尝试过使用 Symbol 的 EMDK 库来访问设备的内置运动传感器,但没有成功。

.NET v2.7 的 EMDK 中有 Symbol.Sensor 类库,该类库应该可以访问所有内置传感器,但我不知道如何使用它。

Symbol.Sensor.SensorManager manager = new Symbol.Sensor.SensorManager();

我在这里收到一个 MissingMethodException 异常,说... “找不到 PInvoke DLL SensorsAPI.dll。”

我应该如何使用 C# 访问运动传感器?

如果还有其他选择,请告知。

最佳答案

我将发布一个 dllImport 示例作为@HemendraSharma 评论的继续。上面的代码是为移动设备编写的,用于更改系统时间。

using System;
using System.Runtime.InteropServices;

namespace changeHour
{   

public class cDateTime  
{       

    [StructLayout(LayoutKind.Sequential)]       
    private struct SystemTime
    {           
        public ushort uYear;            
        public ushort uMonth;           
        public ushort uDayOfWeek;           
        public ushort uDay;         
        public ushort uHour;            
        public ushort uMinute;          
        public ushort uSecond;          
        public ushort uMilliseconds;            

        public SystemTime(
            ushort uYear, 
            ushort uMonth, 
            ushort uDay, 
            ushort uHour, 
            ushort uMinute, 
            ushort uSecond)
        {               
            this.uYear = uYear;             
            this.uMonth = uMonth;               
            this.uDayOfWeek = 0;                
            this.uDay = uDay;               
            this.uHour = uHour;             
            this.uMinute = uMinute;             
            this.uSecond = uSecond;             
            this.uMilliseconds = 0;         
        }       
    }       

    [DllImport("Coredll.dll")]          
    private static extern bool SetLocalTime(ref SystemTime st);

           [DllImport("Coredll.dll")]           
           private static extern uint SetSystemTime(ref SystemTime st);     



    public static bool SetDateTime(
        int iYear, 
        int iMonth, 
        int iDay, 
        int iHour, 
        int iMinute, 
        int iSecond)        
           {            
        SystemTime st = 
            new SystemTime
            (
            Convert.ToUInt16(iYear), 
            Convert.ToUInt16(iMonth), 
            Convert.ToUInt16(iDay), 
            Convert.ToUInt16(iHour), 
            Convert.ToUInt16(iMinute), 
            Convert.ToUInt16(iSecond)
            );          
        return SetLocalTime(ref st);        
    }

    public static uint SetDateTimeSystem(
        int iYear,
        int iMonth,
        int iDay,
        int iHour,
        int iMinute,
        int iSecond)
    {
        SystemTime st =
            new SystemTime
            (
            Convert.ToUInt16(iYear),
            Convert.ToUInt16(iMonth),
            Convert.ToUInt16(iDay),
            Convert.ToUInt16(iHour),
            Convert.ToUInt16(iMinute),
            Convert.ToUInt16(iSecond)
            );
        return SetSystemTime(ref st);
    }       


    public static bool SetDateTime(DateTime dt)     
    {           
        return SetDateTime
            (
            dt.Year, 
            dt.Month, 
            dt.Day, 
            dt.Hour, 
            dt.Minute, 
            dt.Second
            );      
    }       


    public static bool SetDate(int iYear, int iMonth, int iDay)
    {           
        DateTime dt = DateTime.Now;         
        return SetDateTime(
            iYear, 
            iMonth, 
            iDay, 
            dt.Hour, 
            dt.Minute, 
            dt.Second);     
    }       

    public static bool SetDate(DateTime date)       
    {           DateTime time = DateTime.Now;           
        return SetDateTime(
            date.Year, 
            date.Month, 
            date.Day, 
            time.Hour, 
            time.Minute, 
            time.Second);       
    }       

    public static bool SetTime(int iHour, int iMinute, int iSecond)
    {           
        DateTime dt = DateTime.Now;         
        return SetDateTime(
            dt.Year, 
            dt.Month, 
            dt.Day, 
            iHour, 
            iMinute, 
            iSecond);       
    }       


    public static bool SetTime(DateTime time)       
    {           
        DateTime date = DateTime.Now;           
        return SetDateTime(
            date.Year, 
            date.Month, 
            date.Day, 
            time.Hour, 
            time.Minute, 
            time.Second);       
    }       

}
 }

关于c# - 以编程方式访问 Motorola MC9500 运动传感器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17107705/

相关文章:

c# - 如何使用 Simple Injector 从 ValidationContext 获取服务?

c# - 如何使用投影缓冲区来支持 Visual Studio 编辑器中的嵌入式语言

windows-mobile - 存在文件共享冲突。 SQL Server CE 3.5 SP2

c# - 如果不能命名互斥锁,它有什么用?

c++ - 如何在 FFMPEG 中填充/计算 motion_val?

opencv - 从另一个运动物体快速跟踪运动物体

c# - 如何在 ASP.NET Core 的 Swagger 中包含 XML 注释文件

c# - 键入时的 RichTextBox 事件

java - 将 SSL 证书导入 J9 keystore 时出现 Keytool 错误

Android SensorManager.getOrientation() 返回 -PI/2 和 PI/2 之间的间距