将串行端口与新的Port类一起使用

编程入门 行业动态 更新时间:2024-10-15 22:28:19
本文介绍了将串行端口与新的Port类一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

您好, 我正在学习串行端口编程.因此,我研究了MSDN中的代码示例-VB101SamplesBCL2 download.microsoft/download/c/2/3/c2318968-80aa-43de-a755-9c0763a2dca8/VB101SamplesBCL2.msi 运行"UsingTheSerialPort"的解决方案时,显示错误: 它突出显示了一个句子 textBox2.Text = SerialPort1.ReadLine()-第40行,并说: 未处理InvalidOperationException-跨线程操作无效:控件'textBox2'是从不是在其上创建线程的线程访问的." 有人可以帮我调试吗? 谢谢 Hi, I'm learning the serial port programming. So, I study the code samples from MSDN - VB101SamplesBCL2 download.microsoft/download/c/2/3/c2318968-80aa-43de-a755-9c0763a2dca8/VB101SamplesBCL2.msi While ran the solution of "UsingTheSerialPort", It shows error: It highlights one sentence textBox2.Text = SerialPort1.ReadLine() -- Line 40 ,and says : "InvalidOperationException was unhandled - Cross-thread operation not valid: Control 'textBox2' accessed from a thread other than the thread it was created on." Anyone can give me help to debug? Thanks 推荐答案

我认为您需要发布代码.如果您是我,我将设置一个全局变量字符串并将其存储在SerialPort1.readline中.然后使用标签显示该变量.通常使用文本框将文本输入到字符串中.它有很多例程 涉及到它.从串行端口返回的字符串可能具有无法与文本框一起使用的字符,具体取决于其设置方式. 同样,您似乎正在一个线程中获取串行端口数据,并试图将文本框显示给另一个线程.没有您的代码,我无法确定这是否是问题所在.

I think you need to post your code. If I were you I would set up a global variable string and store the SerialPort1.readline in. Then use a label to display that varaiable. A textbox is normally used to enter text into a string. It has numerous routines that are involved with it. The string being returned from the serial port may have characters that can not be used with the textbox depending on the way it is set up. Also it appears that you are getting the serial port data in one thread and trying to display the textbox to another thread. Without you code I cannot determine if this is the problem or not.

柯蒂斯

更多推荐

将串行端口与新的Port类一起使用

本文发布于:2023-10-07 13:11:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1469473.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:端口   Port

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!