Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VB6中的串行通信_Vb6 - Fatal编程技术网

VB6中的串行通信

VB6中的串行通信,vb6,Vb6,我是vb6和通信应用程序的新手,我尝试运行一个在两个串行端口之间发送和接收数据的示例(我通过com0comsoft安装了两个串行端口) 在本例中,我希望用户在textbox1中键入charracters,然后单击命令按钮,textbox1中的charracters将显示在textbox2中 Private Sub Command1_Click() com1.Output = Text1.Text End Sub Private Sub Form_Load() com1.CommPort = 1

我是vb6和通信应用程序的新手,我尝试运行一个在两个串行端口之间发送和接收数据的示例(我通过com0comsoft安装了两个串行端口)

在本例中,我希望用户在textbox1中键入charracters,然后单击命令按钮,textbox1中的charracters将显示在textbox2中

Private Sub Command1_Click()
com1.Output = Text1.Text
End Sub

Private Sub Form_Load()
com1.CommPort = 1
com1.Settings = "9600,n,8,1"
com1.PortOpen = True
com2.CommPort = 2
com2.Settings = "9600,n,8,1"
com2.PortOpen = True

Text1.Text = ""
Text2.Text = ""
End Sub

Private Sub com2_OnComm()
If com2.CommEvent = comEvReceive Then
    Text2.Text = Text2.Text + com2.Input

End If
End Sub
我在示例中筛选了
表单
,并在com0com端口中设置,我没有足够的声誉来发布图像,所以我将其上传到flickr

但当我尝试在textbox1中键入charracters并单击按钮来运行这个示例时,什么都没有发生

那我做错了什么?。如果是,我如何从com1端口到COM2端口获取数据?或者任何建议


谢谢你的阅读

我认为您需要更仔细地查看文档

下面是一个最小的示例,其中COM3/COM4是我机器上的循环端口:

Option Explicit

Private Sub Command1_Click()
    If Len(Text1.Text) > 0 Then
        MSComm1.Output = Text1.Text
        Text1.Text = vbNullString
    End If
    Text1.SetFocus
End Sub

Private Sub Form_Load()
    With MSComm1
        .CommPort = 3
        .Settings = "256000,n,8,1"
        .Handshaking = comNone
        .SThreshold = 0 'No events after send completions.
        .RThreshold = 0 'No events after receive completions.
        .PortOpen = True
    End With
    With MSComm2
        .CommPort = 4
        .Settings = "256000,n,8,1"
        .EOFEnable = False
        .Handshaking = comNone
        .InputMode = comInputModeText
        .RThreshold = 1 'Event for each character received.  Terribly
                        'inefficient but if char-by-char events are
                        'required there isn't much choice.
        .SThreshold = 0 'No events after send completions.
        .PortOpen = True
    End With
End Sub

Private Sub Form_Unload(Cancel As Integer)
    MSComm1.PortOpen = False
    MSComm2.PortOpen = False
End Sub

Private Sub MSComm2_OnComm()
    With MSComm2
        If .CommEvent = comEvReceive Then
            .InputLen = 0
            Text2.SelStart = &H7FFF
            Text2.SelText = .Input
        End If
    End With
End Sub

你确定电缆正确吗?有电缆吗?我以为他用的是一个设备驱动程序,它实现了两个背对背的端口。是的,我用软件实现了两个串行端口。谢谢,你的代码帮了我很多,我得到了我想要的。