zoukankan      html  css  js  c++  java
  • SerialPort基本小例

    SerialPort是用于串口通信的控件与VB6中的MSCOMM控件相似,使用很方便...

    vb.net Code
    Imports System.IO.Ports
    Imports System.Text
    Public Class Form1
    Dim RS232Com As New SerialPort
    Dim mPortName As String
    Public Sub OpenCOM()
    mPortName = Me.CmbCom.SelectedItem.ToString
    RS232Com = New SerialPort(mPortName, 9600, Parity.None, 8, StopBits.One)
    RS232Com.Encoding = Encoding.ASCII
    If Not RS232Com.IsOpen Then RS232Com.Open()
    End Sub
    Public Sub CloseCOM()
    If RS232Com.IsOpen Then RS232Com.Close()
    End Sub

    Private Sub BtnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnOpen.Click
    Call OpenCOM()
    End Sub

    Private Sub BtnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClose.Click
    Call CloseCOM()
    End Sub

    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
    Me.CmbCom.Items.Add(sp)
    Next
    Me.CmbCom.SelectedIndex = 0
    End Sub

    Private Sub BtnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSend.Click
    RS232Com.Write(Me.TextBox1.Text) '即写命令过去
    End Sub
    Private Sub BtnReceived_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnReceived.Click
    Dim sOut As String
    sOut = RS232Com.ReadExisting 'sOut即读到的字符串
    End Sub
    End Class
  • 相关阅读:
    vue-实践1
    node 基本使用
    vue通信
    初始AMD和Common.js
    vue正确引入第三方包
    常见的java设计模式
    springboot加ES实现全局检索
    Cookie丢失的原因
    动态SQL
    用Java实现给图片添加文字
  • 原文地址:https://www.cnblogs.com/wangxiaoyang/p/3577760.html
Copyright © 2011-2022 走看看