从串行端口分离数据 [英] Seperate data from Serial Port

查看:60
本文介绍了从串行端口分离数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在开发一个Winform GUI应用程序,它使用串行端口与传感器通信。每次我发送请求时,它都会给我一个回复,如下所示:



请求:readBasicAttr 0

readColorControl 0



我收到这样的回复:



Attr 0x0000 = 1

Attr 0x0000 = 123



现在我想将每个响应放在一个文本框中,但我不知道如何做到这一点。基本上我想把第一个响应放到文本框1,第二个放到文本框2等...



有没有人有这方面的经验?不需要为我编写代码,只需告诉我如何执行此操作,我将自己编写代码



祝你好运

Hi,

I'm developing an Winform GUI Application, that uses the serial port to communicate with a sensor. Everytime I send a request, it sends me a response, like this:

Request: readBasicAttr 0
readColorControl 0

I receive response like this:

Attr 0x0000= 1
Attr 0x0000= 123

Now I want to put each response in a textbox, but i don't know how to do this. Basically I want to put the first response to textbox 1, the second to textbox 2 etc...

Does anyone have experience with this? No need to write the code for me, just tell me how to do this, and I'll write the code myself

Best regards

推荐答案

我强烈建议每个文本框都是一个坏主意 - 它完全可行,但实现和用户都很笨拙。



您是否考虑过使用DataGridView或ListBox?它们都比单独的文本框更灵活。
I would strongly suggest that a textbox each is a bad idea - it's perfectly feasible, but it's clumsy, both to implement and for the user.

Have you considered using a DataGridView or a ListBox instead? Both of them are a lot more flexible than separate textboxes.


OriginalGriff是正确的...你建议的可以做得更好。但是......也许你有充分的理由......我该判断谁?



因此,如果您将它们放在groupbox或其他类似的容器中,您可以迭代子控件数组(它是包含控件的属性)来获取对容器内每个控件的引用。虽然订单通常按照添加到容器中的顺序出现,但不保证订单。但是,给文本框顺序名称,如databoxXX,其中XX是一个递增的数字将允许您按名称引用它们。一个简单的计数器可以递增以生成下一个名字。





祝你好运。
OriginalGriff is right... what you are suggesting can be done better. But... maybe you have a good reason... who am I to judge?

So if you have them in a groupbox or some other container like that, you can iterate the child controls array (it is a property on that containing control) to get a reference to each control within the container. Order isn't guaranteed although they will typically appear in the order they were added to the container. But, giving the text boxes sequential names like "databoxXX" where XX is an increasing number would allow you to reference them by name. A simple counter can be incremented to generate the next name.


Good luck.


这篇关于从串行端口分离数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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