从串行设备接收字符串。如何拆分它 [英] Receive String From a serial Device. How to Split it

查看:69
本文介绍了从串行设备接收字符串。如何拆分它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!我有一个串行设备,它以38400的波特率向我发送数据,我得到它像这样" ?@ D00014C000 000 " .I
可以看到数据进入ritchtextbox但是我想要做的是使用字符串中的一些字符列表框。 


例如我想要字符" 14C "出现在  listbox3
我尝试过 
子串  和  mid  功能
但是listbox lidnt正常工作并丢失字符或混淆它们。这是我的代码。有什么建议吗?

Hello everyone!! I have a serial device which sends me data at the baudrate of 38400 and i get it like this "?@D00014C000 000".I can see data comes in on a ritchtextbox but what im trying to do is to use some characters from the string in a list box. 
For example i want characters "14C" appears in the listbox3. I tried the substring and mid function but listbox lidnt work properly and losses characters or confuse them . Here is my code. Any suggestions please??

Imports System
Imports System.ComponentModel
Imports System.Threading
Imports System.IO.Ports
 
Public Class frmMain
    Dim myPort As Array
    Delegate Sub SetTextCallback(ByVal [text] As String)
  
 
    'Serial Port Receiving Code Starts Here ....
    Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
        ReceivedText(SerialPort1.ReadExisting())
 
    End Sub
    'Serial Port Receiving Code Ends Here ....
 
    'Serial Port Receiving Code(Invoke) Starts Here ....
    Private Sub ReceivedText(ByVal [text] As String)
        If Me.rtbReceived.InvokeRequired Then
            Dim x As New SetTextCallback(AddressOf ReceivedText)
            Me.Invoke(x, New Object() {(text)})
 
           
 
        Else
            Me.rtbReceived.Text &= [text]
              Dim fine As String = Mid([text], 7, 3)
            Dim list As Integer = ListBox3.Items.Add(fine)
        End If
 
    End Sub
 

End Class

推荐答案

你好palavras,

Hi palavras,

>> I尝试了子串和mid函数,但listbox lidnt工作正常,丢失字符或混淆它们。

>>I tried the substring and mid function but listbox lidnt work properly and losses characters or confuse them .

请你提供一些截图来描述它是如何变得混乱,因为我使用以下代码在我的项目中测试它:

Could you please provide some screenshots to describe how it gets messy, because I test it in my project with the following code:

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Me.RichTextBox1.Text &= "?@D00014C000 000"
        Dim Text As String = "?@D00014C000 000"
        Dim fine As String = Mid(Text, 7, 3)
        Dim list As Integer = ListBox1.Items.Add(fine)
    End Sub

但它并没有混淆:

如此请求se为您的问题提供更多信息。

So please provide more information for your issue.

另外,您使用哪种语言? VB.NET?还是VB6?

Also, which language do you use? VB.NET? Or VB6?

问候,

Stanly


这篇关于从串行设备接收字符串。如何拆分它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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