在事件处理程序中检查答复是否是个好主意? [英] Is Checking for a reply in an Event Handler a good idea?

查看:68
本文介绍了在事件处理程序中检查答复是否是个好主意?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我的追求继续.我问过一些有关暂停使用Serial Comms允许答复的程序的问题,现在我需要检查过去的答复,我使用了从事件处理程序调用的单独函数.这次似乎不起作用,因此我正在讨论如何按照大致思路在处理程序中进行检查.

Hi All,

My quest continues. I have asked some questions about pauseing a program that uses Serial Comms to allow for a reply, Now I need to check that reply in the past I have used a seperate function caled from the event handler. This does not appear to be working this time so I am debating about having the check done in the handler as follows a rough idea.

if(data.Contains("E"))
{
//goto Error Recieved Function
}


因为它们全都以"E"开头,所以此命令会从板上返回错误消息吗?


Will this check for error message back from the board as they all start with ''E''

if (data.Contains("OK"))
{
// send next command
} 


检查看板上是否有OK.现在到了棒子部分,我无法使用starndard字符串,因为它们已被读取到我可以用来字符串化的字节数组中,但是我不确定该问题是否存在
谢谢
Glenn


Check to see if an OK comes back from the board. Now comes the stick part I can''t use the starndard string as they are being read to a byte array I could use to string but I''m not sure of the problems with that
Thanks
Glenn

推荐答案

假定董事会:
  • 在其他任何数据之前发送确认(或错误).
  • 使用ASCII编码(非UNICODE).
Assuming that the board:
  • Sends the acknowledge (or error) before any other data.
  • uses ASCII encoding (not UNICODE).
if (data[0]==0x45)
{
 // handle the 'error' meesage here
}
else if (data[0] == 0x4F && data[1] == 0x4B)
{
 // handle the 'success' message here
}


这篇关于在事件处理程序中检查答复是否是个好主意?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆