[.NET] rs232迴路測試

看板Visual_Basic作者 ( )時間13年前 (2010/12/06 14:09), 編輯推噓2(200)
留言2則, 1人參與, 最新討論串1/1
對不起 我是剛接觸vb 想請問一下 我在做rs232迴路測試 但由於筆電沒有rs232孔位 所以改用 usb轉rs232(已安裝其驅動程式) 將其2和3腳位相連 做迴路測試 程式照書本上打 我是vb2008 (visual basic 2005與自動化系統監控) 但好像不能動 程式如下 還移是黃色一段有問題? 有人可以幫幫忙嗎 Imports System.IO.Ports Imports System.Text Public Class Form1 Dim RS232 As SerialPort Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load For Each sp As String In SerialPort.GetPortNames() cmbCOM.Items.Add(sp) Next cmbCOM.Sorted = True cmbCOM.SelectedIndex = 0 btnStart.Enabled = True btnClose.Enabled = False btnSend.Enabled = False End Sub Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click Dim mBaudRate As Integer Dim mParity As IO.Ports.Parity Dim mDataBit As Integer Dim mStopbit As IO.Ports.StopBits Dim mPortName As String mPortName = cmbCOM.SelectedItem.ToString mBaudRate = 9600 mParity = Parity.None mDataBit = 8 mStopbit = StopBits.One RS232 = New IO.Ports.SerialPort(mPortName, mBaudRate, mParity, mDataBit, mStopbit) RS232.Encoding = Encoding.Unicode RS232.Open() btnStart.Enabled = False btnSend.Enabled = True btnClose.Enabled = True Timer1.Interval = 100 Timer1.Enabled = True End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim InString As String InString = "" Try RS232.ReadTimeout = 1000 InString = RS232.ReadExisting() If InString.Length = 0 Then Exit Sub Else txtReceive.Text += InString End If Catch ex As Exception MessageBox.Show("霈胥辖航炊 : "+ex.ToString,"航炊梄缷", MessageBoxButtons.OK,MessageBoxIcon.Exclamation) End Try End Sub Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click btnStart.Enabled = True RS232.Close() btnSend.Enabled = False btnClose.Enabled = False End Sub Private Sub btnEnd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnd.Click End End Sub End Class -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 111.248.48.232 ※ 編輯: l80110 來自: 111.248.48.232 (12/06 14:15) ※ 編輯: l80110 來自: 111.248.48.232 (12/06 14:15)

12/06 20:52, , 1F
你沒有 Handles RS232.DataRecevied
12/06 20:52, 1F

12/06 21:09, , 2F
也沒有寫值進去..
12/06 21:09, 2F
文章代碼(AID): #1C_7uRcL (Visual_Basic)