简体   繁体   English

如何使用C#从嵌入式系统(Windows CE 6.0)中的设备接收自定义消息?

[英]How to receive custom message from a device in embedded system (Windows CE 6.0) using C#?

I have a device with a fingerprint sensor attached to it. 我有一个连接了指纹传感器的设备。 The device is running windows CE 6.0. 设备正在运行Windows CE 6.0。 I am currently using C# to develop an application for the device. 我目前正在使用C#开发该设备的应用程序。

My question is: 我的问题是:

I use pInvoke to initialize communication with the sensor. 我使用pInvoke初始化与传感器的通信。 However, I am still confused on how can I configure my application to realize whenever the sensor is touched. 但是,我仍然对如何配置应用程序以实现只要触摸传感器就感到困惑。 In other word, how can I capture an event triggered by my sensor in my application. 换句话说,如何捕获我的传感器在应用程序中触发的事件。

Any advice is much appreciated, thanks. 任何建议都非常感谢,谢谢。

**Update (trying to automatically tell my form what to do when I click the close window button) **更新(当我单击关闭窗口按钮时,试图自动告诉我该怎么做)

public partial class Form1 : Form
{
    internalMessageWindow msgReceived;

public Form1()
    {
        InitializeComponent();
        this.msgReceived = new internalMessageWindow(this);
    }

 private void Form1_Load(object sender, EventArgs e)
    {
        msgReceived.MsgEvntArg += new EventHandler<MessageGetEvent>(messageWindow_MsgEvntArg);
    }

     void messageWindow_MsgEvntArg(object sender, MessageGetEvent e)
    {
        MessageBox.Show(e.message.ToString());
    }
}

public class MessageGetEvent : EventArgs
{
    private Message _message;

    public MessageGetEvent(Message msg)
    {
        _message = msg;
    }

    public Message message
    {
        get { return _message; }
    }
}

public class internalMessageWindow : MessageWindow
{
        public const int WM_CLOSE = 0x0010; 

    Form referedForm;

    public event EventHandler<MessageGetEvent> MsgEvntArg;

    public internalMessageWindow(Form referedForm)
    {
        this.referedForm = referedForm;
    }

    protected override void WndProc(ref Message msg)
    {
        if (MsgEvntArg != null)
            MsgEvntArg(this, new MessageGetEvent(msg));


    //switch (msg.Msg)
        //{
        //    // If message is of interest, invoke the method on the form that
        //    // functions as a callback to perform actions in response to the message.
        //    case WM_CLOSE:
        //        if (MsgEvntArg != null)
        //        MsgEvntArg(this, new MessageGetEvent(msg));
        //        
        //        break;
        //}

        base.WndProc(ref msg);

    }
}

You should provide a bit more information about the sensor and how it's connected to your board/processor. 您应该提供有关传感器及其与主板/处理器的连接方式的更多信息。 It may require a driver (if it's connected via USB, for example) or you may need to understand which interface and driver you should use to exchange information. 它可能需要驱动程序(例如,如果通过USB连接),或者您可能需要了解用于交换信息的接口和驱动程序。 If it's UART windows CE provides standard APIs, if it's another bus (I2C, SPI etc.) you may need to discover how to interface with the bus driver (some companies provide application libraries to do that). 如果是UART,则Windows CE提供标准的API,如果它是另一种总线(I2C,SPI等),则可能需要发现如何与总线驱动程序接口(某些公司提供应用程序库来执行此操作)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM