hi.i have a question....Astream_newdata() function not work!!!!
what's happen??
my code is:
#Region Module Attributes
#FullScreen: False
#IncludeTitle: True
#ApplicationLabel: BCDtest
#VersionCode: 1
#VersionName:
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
'Activity module
Sub Process_Globals
Dim serial1 As Serial
Dim foundDevices As List
'Dim Connected As Boolean
'Dim Textreader1 As TextReader
Dim AStream As AsyncStreams
Private bc As ByteConverter
Dim cc As String
'Dim Timer1 As Timer
End Sub
Sub Globals
Dim btnSearchForDevices As Button
Dim btnExit As Button
Dim txtInput As EditText
Dim txtLog As EditText
Dim btnSend As Button
Dim btnKEY As Button
Dim btnID As Button
Dim btnFiger As Button
Dim btnIC As Button
Dim btnMSR As Button
Dim button1 As Button
Dim panel1 As Panel
End Sub
'Sub Timer1_Tick
' If Connected Then
' If Textreader1.Ready Then 'check if there is any data waiting to be read
' Msgbox("have_data!","")
' Msgbox(Textreader1.ReadAll,"")
' Log("cc:" & Textreader1.ReadLine)
' txtLog.Text = txtLog.Text & Textreader1.ReadLine & CRLF
' txtLog.SelectionStart = txtLog.Text.Length
' End If
' End If
'End Sub
Sub AStream_Error
ToastMessageShow("连接中断.", True)
btnSend.Enabled = False
txtInput.Enabled = False
'Textreader1.close
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout ("1")
If FirstTime Then
serial1.Initialize ("serial1")
'Timer1.Initialize("Timer1", 500)
End If
txtLog.Width = 100%x
button1.Text="KEY1"
panel1.Visible =False
Timer1.Enabled =False
End Sub
Sub AStream_NewData (Buffer() As Byte)
LogMessage("You", BytesToString(Buffer, 0, Buffer.Length, "UTF8"))
End Sub
Sub Activity_Resume
If serial1.IsEnabled =False Then
Msgbox("请打开蓝牙!","")
'Timer1.Enabled =False
Else
serial1.Listen
End If
End Sub
Sub Activity_Pause (UserClosed As Boolean)
If UserClosed Then
AStream.close
Textreader1.close
End If
End Sub
Sub btnExit_Click
AStream.close
serial1.Disconnect
ExitApplication
End Sub
Sub btnSearchForDevices_Click
Dim PairedDevices As Map
Dim i As Long
PairedDevices=serial1.GetPairedDevices
foundDevices.Initialize
For i=0 To PairedDevices.Size-1
foundDevices.Add(PairedDevices.GetKeyAt(i))
Next
Dim res As Int
res=InputList(foundDevices,"选择设备:",-1)
If res<>DialogResponse.CANCEL Then
serial1.Connect(PairedDevices.Get(foundDevices.get(res)))
End If
End Sub
Sub Serial1_Connected (Success As Boolean)
ProgressDialogHide
Log("connected: " & Success)
If Success = False Then
Log(LastException.Message)
ToastMessageShow("Error connecting: " & LastException.Message, True)
panel1.Visible =False
Else
If AStream.IsInitialized = False Then
'AStream.InitializePrefix(serial1.InputStream, True, serial1.OutputStream, "AStream")
AStream.InitializePrefix(serial1.InputStream, False, serial1.OutputStream, "AStream")
End If
panel1.Visible =True
'Textreader1.Initialize(serial1.InputStream)
'Timer1.Enabled =True
Connected=True
'AStream.Initialize (serial1.OutputStream)
End If
End Sub
Sub txtInput_EnterPressed
If btnSend.Enabled = True Then btnSend_Click
End Sub
Sub btnSend_Click
'AStream.Write(txtInput.Text.GetBytes("UTF8"))
AStream.Write(bc.HexToBytes(SubRepalce(txtInput.Text," ","")))
txtInput.SelectAll
txtInput.RequestFocus
LogMessage("Me", txtInput.Text)
End Sub
Sub btnKEY_Click
cc="1a 25 12 41"
AStream.Write(bc.HexToBytes(SubRepalce(cc," ","")))
End Sub
Sub btnID_Click
cc="1a 25 12 42"
AStream.Write(bc.HexToBytes(SubRepalce(cc," ","")))
End Sub
Sub btnFiger_Click
cc="1a 25 12 43"
AStream.Write(bc.HexToBytes(SubRepalce(cc," ","")))
End Sub
Sub btnIC_Click
cc="1a 25 12 44"
AStream.Write(bc.HexToBytes(SubRepalce(cc," ","")))
End Sub
Sub btnMSR_Click
cc="1a 25 12 45"
AStream.Write(bc.HexToBytes(SubRepalce(cc," ","")))
End Sub
Sub button1_click
'Dim buffer() As Byte
'buffer = txtInput.Text.GetBytes("UTF8")'将编辑框里的内容分到数组上
cc="1b 53 46 00 01 0f 0d 0a"
AStream.Write(bc.HexToBytes(SubRepalce(cc," ","")))'写出内容
End Sub
Sub LogMessage(From As String, Msg As String)
txtLog.Text = txtLog.Text & From & ": " & Msg & CRLF
txtLog.SelectionStart = txtLog.Text.Length
End Sub
Sub Byte2Hex(b As Int) As String
Dim hex As String = "0123456789ABCDEF"
Dim l,h As Int
l=Bit.And(b,0xf)
h=Bit.And(Bit.ShiftRight(b,4),0xf) ' <- safety fix
Return (hex.CharAt(h) & hex.CharAt(l))
End Sub
Sub SubRepalce(chain As String, search As String, replaced As String)
If chain.IndexOf(search) = 0 Then Return chain
Dim gauche, droite As String
Do While chain.IndexOf(search)>0
chain = chain.substring2(0,chain.IndexOf(search)) & replaced & _
chain.SubString(chain.IndexOf(search)+search.Length)
Loop
Return chain
End Sub
what's happen??
my code is:
#Region Module Attributes
#FullScreen: False
#IncludeTitle: True
#ApplicationLabel: BCDtest
#VersionCode: 1
#VersionName:
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
'Activity module
Sub Process_Globals
Dim serial1 As Serial
Dim foundDevices As List
'Dim Connected As Boolean
'Dim Textreader1 As TextReader
Dim AStream As AsyncStreams
Private bc As ByteConverter
Dim cc As String
'Dim Timer1 As Timer
End Sub
Sub Globals
Dim btnSearchForDevices As Button
Dim btnExit As Button
Dim txtInput As EditText
Dim txtLog As EditText
Dim btnSend As Button
Dim btnKEY As Button
Dim btnID As Button
Dim btnFiger As Button
Dim btnIC As Button
Dim btnMSR As Button
Dim button1 As Button
Dim panel1 As Panel
End Sub
'Sub Timer1_Tick
' If Connected Then
' If Textreader1.Ready Then 'check if there is any data waiting to be read
' Msgbox("have_data!","")
' Msgbox(Textreader1.ReadAll,"")
' Log("cc:" & Textreader1.ReadLine)
' txtLog.Text = txtLog.Text & Textreader1.ReadLine & CRLF
' txtLog.SelectionStart = txtLog.Text.Length
' End If
' End If
'End Sub
Sub AStream_Error
ToastMessageShow("连接中断.", True)
btnSend.Enabled = False
txtInput.Enabled = False
'Textreader1.close
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout ("1")
If FirstTime Then
serial1.Initialize ("serial1")
'Timer1.Initialize("Timer1", 500)
End If
txtLog.Width = 100%x
button1.Text="KEY1"
panel1.Visible =False
Timer1.Enabled =False
End Sub
Sub AStream_NewData (Buffer() As Byte)
LogMessage("You", BytesToString(Buffer, 0, Buffer.Length, "UTF8"))
End Sub
Sub Activity_Resume
If serial1.IsEnabled =False Then
Msgbox("请打开蓝牙!","")
'Timer1.Enabled =False
Else
serial1.Listen
End If
End Sub
Sub Activity_Pause (UserClosed As Boolean)
If UserClosed Then
AStream.close
Textreader1.close
End If
End Sub
Sub btnExit_Click
AStream.close
serial1.Disconnect
ExitApplication
End Sub
Sub btnSearchForDevices_Click
Dim PairedDevices As Map
Dim i As Long
PairedDevices=serial1.GetPairedDevices
foundDevices.Initialize
For i=0 To PairedDevices.Size-1
foundDevices.Add(PairedDevices.GetKeyAt(i))
Next
Dim res As Int
res=InputList(foundDevices,"选择设备:",-1)
If res<>DialogResponse.CANCEL Then
serial1.Connect(PairedDevices.Get(foundDevices.get(res)))
End If
End Sub
Sub Serial1_Connected (Success As Boolean)
ProgressDialogHide
Log("connected: " & Success)
If Success = False Then
Log(LastException.Message)
ToastMessageShow("Error connecting: " & LastException.Message, True)
panel1.Visible =False
Else
If AStream.IsInitialized = False Then
'AStream.InitializePrefix(serial1.InputStream, True, serial1.OutputStream, "AStream")
AStream.InitializePrefix(serial1.InputStream, False, serial1.OutputStream, "AStream")
End If
panel1.Visible =True
'Textreader1.Initialize(serial1.InputStream)
'Timer1.Enabled =True
Connected=True
'AStream.Initialize (serial1.OutputStream)
End If
End Sub
Sub txtInput_EnterPressed
If btnSend.Enabled = True Then btnSend_Click
End Sub
Sub btnSend_Click
'AStream.Write(txtInput.Text.GetBytes("UTF8"))
AStream.Write(bc.HexToBytes(SubRepalce(txtInput.Text," ","")))
txtInput.SelectAll
txtInput.RequestFocus
LogMessage("Me", txtInput.Text)
End Sub
Sub btnKEY_Click
cc="1a 25 12 41"
AStream.Write(bc.HexToBytes(SubRepalce(cc," ","")))
End Sub
Sub btnID_Click
cc="1a 25 12 42"
AStream.Write(bc.HexToBytes(SubRepalce(cc," ","")))
End Sub
Sub btnFiger_Click
cc="1a 25 12 43"
AStream.Write(bc.HexToBytes(SubRepalce(cc," ","")))
End Sub
Sub btnIC_Click
cc="1a 25 12 44"
AStream.Write(bc.HexToBytes(SubRepalce(cc," ","")))
End Sub
Sub btnMSR_Click
cc="1a 25 12 45"
AStream.Write(bc.HexToBytes(SubRepalce(cc," ","")))
End Sub
Sub button1_click
'Dim buffer() As Byte
'buffer = txtInput.Text.GetBytes("UTF8")'将编辑框里的内容分到数组上
cc="1b 53 46 00 01 0f 0d 0a"
AStream.Write(bc.HexToBytes(SubRepalce(cc," ","")))'写出内容
End Sub
Sub LogMessage(From As String, Msg As String)
txtLog.Text = txtLog.Text & From & ": " & Msg & CRLF
txtLog.SelectionStart = txtLog.Text.Length
End Sub
Sub Byte2Hex(b As Int) As String
Dim hex As String = "0123456789ABCDEF"
Dim l,h As Int
l=Bit.And(b,0xf)
h=Bit.And(Bit.ShiftRight(b,4),0xf) ' <- safety fix
Return (hex.CharAt(h) & hex.CharAt(l))
End Sub
Sub SubRepalce(chain As String, search As String, replaced As String)
If chain.IndexOf(search) = 0 Then Return chain
Dim gauche, droite As String
Do While chain.IndexOf(search)>0
chain = chain.substring2(0,chain.IndexOf(search)) & replaced & _
chain.SubString(chain.IndexOf(search)+search.Length)
Loop
Return chain
End Sub