Vb.net 如何使用visual basic通过串行通信逐字节读取数据?

Vb.net 如何使用visual basic通过串行通信逐字节读取数据?,vb.net,visual-studio-2013,serial-port,microcontroller,serial-communication,Vb.net,Visual Studio 2013,Serial Port,Microcontroller,Serial Communication,我试图从STM32板读取一些串行数据到GUI,同时,我在关闭串行通信端口时遇到问题 我正在使用2013 Visual Studio,并选择Visual Basic作为我的编程语言。我想从微控制器发送的是我逐字节发送的一些串行数据。例如,我将发送”) 但还是不行。 以下是关闭按钮部分: 'Visual Basic --> for disconnect button Private Sub Button5_Click_1(sender As Object, e As EventArgs) Ha

我试图从STM32板读取一些串行数据到GUI,同时,我在关闭串行通信端口时遇到问题

我正在使用2013 Visual Studio,并选择Visual Basic作为我的编程语言。我想从微控制器发送的是我逐字节发送的一些串行数据。例如,我将发送
”)

但还是不行。 以下是关闭按钮部分:

'Visual Basic --> for disconnect button
Private Sub Button5_Click_1(sender As Object, e As EventArgs) Handles Button5.Click
    SerialPort1.Close()
End Sub
每次我按下这个按钮后,它都会被卡住和挂起。我需要重新启动程序才能解决这个问题。这部分有什么想法吗

简单总结一下,我的问题如下:

  • 我真的不知道如何使用serialport.readbyte()和serialport.read()。我真的需要它,因为我想一个字节一个字节地分离数据,以便轻松地处理它

  • serialport.close()按钮总是挂起,我不知道为什么

  • 我希望有人能帮我解决这些问题。提前谢谢你的帮助,如果我的帖子乱七八糟的话,我很抱歉


    再次感谢!Buff\u Rx是一个字节数组,不能分配给整数:

    Dim i As Integer = buff_rx
    

    你看了吗?我不知道你是如何发送字节的,但要知道在.NET中(VB和C#),字符长度为2字节。buff_rx是如何声明的?为什么要设置i,它是一个整数=buff_rx,它是一个字节?@AlessandroMandelli buff_rx是一个字节数组,啊..这就是问题的根源吗?我以为我们可以立即从字节存储到整数?@RobertBaron嗨,是的,我已经检查过了,但不幸的是它没有回答我的问题问题
    //Microcontroller side, data sending
    tx3_buff[0] = '<'; //ascii code: 60
    tx3_buff[1] = 'b'; //ascii code: 98
    tx3_buff[2] = 'c'; //ascii code: 99
    tx3_buff[3] = 'd'; //ascii code: 100
    tx3_buff[4] = 'e'; //ascii code: 101
    tx3_buff[5] = 'f'; //ascii code: 102
    tx3_buff[6] = 'g'; //ascii code: 103
    tx3_buff[7] = 'h'; //ascii code: 104
    tx3_buff[8] = 'i'; //ascii code: 105
    tx3_buff[9] = '>'; //ascii code: 62
    
    160  16 161 33 198 18 52 68 84 200 232 16 40 200
    
    'Visual Basic --> for disconnect button
    Private Sub Button5_Click_1(sender As Object, e As EventArgs) Handles Button5.Click
        SerialPort1.Close()
    End Sub
    
    Dim i As Integer = buff_rx