zoukankan      html  css  js  c++  java
  • COM to PS2(将串口读到的信息直接转换成键盘的输入信息)

    1、使用MSComm读串口信息

    Private Sub Command1_Click()

        If Me.MSComm1.PortOpen = True Then Me.MSComm1.PortOpen = False
       
        Me.MSComm1.CommPort = Me.cbCom.ListIndex + 1
        Me.MSComm1.Settings = Me.txtSettings.Text
        Me.MSComm1.InputLen = 0
        Me.MSComm1.PortOpen = True

    End Sub

    Private Sub MSComm1_OnComm()
    Dim readline As String
        Select Case MSComm1.CommEvent
            Case comEvReceive
                '开始接收
                readline = MSComm1.Input
                  
                formatData readline
            Case Else
        End Select
    End Sub

    2、将读到的信息做些处理

    Private Sub formatData(ByVal str As String)
        '判断字符串是否以回车换行结束,如果是去掉
        If Asc(Mid(str, Len(str), 1)) = 10 And Asc(Mid(str, Len(str) - 1, 1)) = 13 Then
            str = Mid(str, 1, Len(str) - 2)
        End If
        '添加回车换行功能
        If selectEnter Then str = str + Chr(13) + Chr(10)
        '添加Tab功能
        If selectTab Then str = str + Chr(9)
        sendstring (str)
    End Sub

    3、出发键盘信息

    Private Sub sendstring(ByVal str As String)
        SendKeys str
    End Sub

    c#

     private void sp_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
            {
                string data = "";
                data = sp.ReadLine();

                sendData(data);
            }

            private void sendData(string data)
            {
                SendKeys.SendWait(data);
                if (this.checkBox1.Checked)
                {
                    SendKeys.SendWait("{enter}");
                }
                if (this.checkBox2.Checked)
                {
                    SendKeys.SendWait("{tab}");
                }
            }

    SendKeys.Send(data)不能用。

  • 相关阅读:
    python并发编程之gevent协程(四)
    python并发编程之asyncio协程(三)
    python并发编程之multiprocessing进程(二)
    python并发编程之threading线程(一)
    python设计模式之内置装饰器使用(四)
    python设计模式之装饰器详解(三)
    python设计模式之迭代器与生成器详解(五)
    EF code First数据迁移学习笔记
    15.02.13-代码小技巧
    Route学习笔记之Area的Route注册
  • 原文地址:https://www.cnblogs.com/TNTZWC/p/1503781.html
Copyright © 2011-2022 走看看