积极答复者
手機接收8051使用COM port+藍芽模組發出訊號疑問

问题
答案
-
hello,jclove
请问你在电脑上使用超级终端接收8051+蓝牙模块的信号,是通过串口的吧?还是电脑上有蓝牙模块,通过蓝牙模块和8051+蓝牙模块进行通信的?
如果是串口通信的话,那就需要你的手机也有串口,使用.NET CF 下的Serialport类就可以搞定。
如果是蓝牙的话,其实就是进行手机上的蓝牙通信。可以参考Jake的Blog:http://www.cnblogs.com/procoder/archive/2009/04/13/Windows_Mobile_Index.html。其中的Bluetooth标签下的文章,是关于Windows Mobile上开发蓝牙的资料。
施炯- 已标记为答案 Guang-Ming Bian - MSFTModerator 2010年4月19日 11:12
全部回复
-
hello,jclove
请问你在电脑上使用超级终端接收8051+蓝牙模块的信号,是通过串口的吧?还是电脑上有蓝牙模块,通过蓝牙模块和8051+蓝牙模块进行通信的?
如果是串口通信的话,那就需要你的手机也有串口,使用.NET CF 下的Serialport类就可以搞定。
如果是蓝牙的话,其实就是进行手机上的蓝牙通信。可以参考Jake的Blog:http://www.cnblogs.com/procoder/archive/2009/04/13/Windows_Mobile_Index.html。其中的Bluetooth标签下的文章,是关于Windows Mobile上开发蓝牙的资料。
施炯- 已标记为答案 Guang-Ming Bian - MSFTModerator 2010年4月19日 11:12
-
感謝幫忙
我目前有在試下面的程式碼
我想先把接收資料搞定
可是都有問題
請幫忙看看問題在那??
感謝
-----------------------------------------------------------------
Imports System.Runtime.InteropServices
PublicClass Form1
Dim infileHandler As Long
Dim outfileHandler As Long
Dim numReadWrite As Integer
Dim t1 As System.Threading.Thread
Dim stopThread AsBoolean = False
Private Sub MenuItem3_Click(ByVal senderAs System.Object, ByVal eAs System.EventArgs) Handles MenuItem3.Click
connect() '第一步驟
End Sub
Public Sub connect()
'---port number for Bluetooth connection
Dim inPort AsShort = 6
'---Opens the port for Bluetooth--INVALID_HANDLE_VALUE= -1
infileHandler = CreateFile("COM" & inPort &":", _
&H80000000, 0, 0, 3, 0, 0)
Application.DoEvents()
'---invoke the thread to receive incoming messages
stopThread = False
t1 = New Threading.Thread(AddressOf receiveLoop)
t1.Start()
End Sub
Public Sub receiveLoop()
'---receive the message through the serial port
Dim inbuff(300) AsByte
Dim retCode AsInteger = ReadFile(infileHandler, _
inbuff, _
inbuff.Length, _
numReadWrite, _
0)
Application.DoEvents()
While True
If retCode = 0 Or stopThreadThen
'---either error or stop is requested
Exit While
Else
Dim updateDelegate As New _
myDelegate(AddressOf updateMessageLog)
updateDelegate.Invoke(byteArrayToString(inbuff))
ReDim inbuff(300)
retCode = ReadFile(infileHandler, _
inbuff, _
inbuff.Length, _
numReadWrite, _
0)
Application.DoEvents()
End If
End While
End Sub
Public DelegateSub myDelegate(ByVal strAs String)
Public Sub updateMessageLog(ByVal strAs String)
If str.Length > 0 Then
TextBox2.Text += "-->" & str 'error
End If
End Sub
Function byteArrayToString(ByVal b()As Byte) As String
'---e.g. {a,b,c,d,e,f,g} to "abcdefg"
Dim str AsString
Dim enc As System.Text.ASCIIEncoding
enc = New System.Text.ASCIIEncoding
str = enc.GetString(b, 0, b.Length())
Return str
End Function
-
hello
如果使用蓝牙作为虚拟串口的话,需要首先建立Bluetooth virtual serial port.
可以通过API来建立,或者通过注册表来实现。
具体请参考Jake的Blog:Windows Moible, Wince 使用.NET Compact Framework的进行蓝牙(Bluetooth)开发 之 蓝牙虚拟串口 (Bluetooth Virtual Serial Port)
里面已经讲的比较清楚了
Good Luck!
施炯