none
有關Buffer的問題 RRS feed

  • 問題

  • 想請問~這兩行有底線的程式中的Buffer
    要如何解釋??   是從哪裡先定義出Buffer的性質??

    Imports System.IO.Ports
    Public Class Form1
        Private comport As SerialPort
        Private totalLength As Int32 = 0
        Private Delegate Sub Display(ByVal buffer As Byte())

        Private Sub DisplayText(ByVal buffer As Byte())
            Dim str(3) As String
            Dim x As String
            Dim y As String
            str(0) = 123456789321654987
            str(1) = String.Format("{0}{1}", BitConverter.ToString(buffer), Environment.NewLine)
            x = str(0)
            y = str(1)
            TextBox1.Text = Mid(x, 1, 3)
            TextBox2.Text &= y
            totalLength += buffer.Length
            Label2.Text = totalLength.ToString()


        End Sub

        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            comport = New SerialPort("COM3", 9600, Parity.None, 8, StopBits.One)
            AddHandler comport.DataReceived, AddressOf comport_DataReceived
            If comport.IsOpen = False Then
                comport.Open()
            End If

        End Sub

        Private Sub Button_ClearTextbox_Click(sender As System.Object, e As System.EventArgs) Handles Button_ClearTextbox.Click
            TextBox1.Clear()
        End Sub

        Private Sub comport_DataReceived(sender As Object, e As SerialDataReceivedEventArgs)
            Dim buffer(1024) As Byte
            Dim length As Int32 = DirectCast(sender, SerialPort).Read(buffer, 0, buffer.Length)
            Array.Resize(buffer, length)
            Dim d As New Display(AddressOf DisplayText)
            Me.Invoke(d, New Object() {buffer})
        End Sub
    2016年1月27日 上午 08:21

解答

所有回覆