我想要一个简单的答案,如何按下一个按钮对安卓(使用basic4android),并获得一个VB6程序来接受数据和响应。安卓和运行VB6程序的计算机都连接到同一个WiFi。
Erel给了我一个网址,但在阅读了几个小时后,我似乎找不到一个简单的安卓代码和VB6代码的例子。
发布于 2012-11-19 15:12:01
我不知道basic4android,但计算机上的一个简单的VB6项目可以如下所示:
'1 form with :
' 1 textbox : name=Text1
' 1 winsock control : name=Winsock1
Option Explicit
Private Sub Form_Load()
Text1.Move 0, 0, ScaleWidth, ScaleHeight 'position the textbox
With Winsock1
.LocalPort = 5001 'set the port to listen on
.Listen 'start listening
End With 'Winsock1
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
With Winsock1
If .State <> sckClosed Then .Close 'close the port when not closed (you could also use another winsock control to accept the connection)
.Accept requestID 'accept the connection request
End With 'Winsock1
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim strData As String
Winsock1.GetData strData 'get the data
ProcessData strData 'process the data
End Sub
Private Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
MsgBox Description, vbCritical, "Error " & CStr(Number)
End Sub
Private Sub ProcessData(strData As String)
Text1.SelText = strData 'show the data
End Sub以下是一些备注:
此项目使用侦听winsock控件来接受连接,因此在此之后,您将不再侦听新的连接请求。当您计划发送大量数据时,您可能应该对数据进行缓冲,并在数据完成时对其进行处理。
发布于 2017-04-30 15:30:24
在VB6端,使用MSComm控件通过其中一个COM端口进行串口通信。OnComm将捕获接收事件。可以将蓝牙转换器连接到端口以处理无线通信。https://msdn.microsoft.com/en-us/library/aa259393(v=vs.60).aspx
在B4A端,使用串行库通过RFCOMM (一个虚拟串行COM端口)与蓝牙设备连接。https://www.b4x.com/android/help/serial.html
https://stackoverflow.com/questions/13444843
复制相似问题