Sub Process_Globals
Dim Serial1 As Serial
Dim TextReader1 As TextReader
Dim TextWriter1 As TextWriter
Dim Timer1 As Timer
Dim connected As Boolean
End Sub
Sub Globals
Dim btnSend As Button
Dim txtLog As EditText
Dim txtSend As EditText
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
Serial1.Initialize("Serial1")
Timer1.Initialize("Timer1", 200)
End If
Activity.LoadLayout("1")
Activity.AddMenuItem("Connect", "mnuConnect")'add itemmenu
Activity.AddMenuItem("Disconnect", "mnuDisconnect")
End Sub
Sub Activity_Resume
If Serial1.IsEnabled = False Then' dar sorat khammush bodan bluetooth
Msgbox("Please enable Bluetooth.", "")
Else
Serial1.Listen
End If
End Sub
Sub mnuConnect_Click
Dim PairedDevices As Map
PairedDevices = Serial1.GetPairedDevices
Dim l As List
l.Initialize
For i = 0 To PairedDevices.Size - 1
l.Add(PairedDevices.GetKeyAt(i))
Next
Dim res As Int
res = InputList(l, "Choose device", -1) 'show listBluetooth
If res <> DialogResponse.CANCEL Then
Serial1.Connect(PairedDevices.Get(l.Get(res))) 'Etesal be macc address
End If
End Sub
Sub Serial1_Connected (Success As Boolean)
If Success Then
ToastMessageShow("Connected successfully", False)'dar sorat vasl shodan
TextReader1.Initialize(Serial1.InputStream)'txt ro mikhone
TextWriter1.Initialize(Serial1.OutputStream)'minvise
Timer1.Enabled = True
connected = True
Else
connected = False
Timer1.Enabled = False
Msgbox(LastException.Message, "Error connecting.")
End If
End Sub
Sub mnuDisconnect_Click
Serial1.Disconnect
connected = False
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub btnSend_Click
If connected Then
TextWriter1.WriteLine(txtSend.Text)
TextWriter1.Flush
txtSend.Text = ""
End If
End Sub
Sub Timer1_Tick
If connected Then
If TextReader1.Ready Then 'check if there is any data waiting to be read
txtLog.Text = txtLog.Text & TextReader1.ReadLine & CRLF
txtLog.SelectionStart = txtLog.Text.Length
End If
End If
End Sub
سوال
ghadamrost 41
سلام
دوستان این پروزه تو شبیه ساز به درستی اجرا میشه اما وقتی رو دو تا گوشی تست میکنم خطا میده
http://freeupload.ir/k6ar0vo54r5i/Objects.rar.html
Sub Process_Globals Dim Serial1 As Serial Dim TextReader1 As TextReader Dim TextWriter1 As TextWriter Dim Timer1 As Timer Dim connected As Boolean End Sub Sub Globals Dim btnSend As Button Dim txtLog As EditText Dim txtSend As EditText End Sub Sub Activity_Create(FirstTime As Boolean) If FirstTime Then Serial1.Initialize("Serial1") Timer1.Initialize("Timer1", 200) End If Activity.LoadLayout("1") Activity.AddMenuItem("Connect", "mnuConnect")'add itemmenu Activity.AddMenuItem("Disconnect", "mnuDisconnect") End Sub Sub Activity_Resume If Serial1.IsEnabled = False Then' dar sorat khammush bodan bluetooth Msgbox("Please enable Bluetooth.", "") Else Serial1.Listen End If End Sub Sub mnuConnect_Click Dim PairedDevices As Map PairedDevices = Serial1.GetPairedDevices Dim l As List l.Initialize For i = 0 To PairedDevices.Size - 1 l.Add(PairedDevices.GetKeyAt(i)) Next Dim res As Int res = InputList(l, "Choose device", -1) 'show listBluetooth If res <> DialogResponse.CANCEL Then Serial1.Connect(PairedDevices.Get(l.Get(res))) 'Etesal be macc address End If End Sub Sub Serial1_Connected (Success As Boolean) If Success Then ToastMessageShow("Connected successfully", False)'dar sorat vasl shodan TextReader1.Initialize(Serial1.InputStream)'txt ro mikhone TextWriter1.Initialize(Serial1.OutputStream)'minvise Timer1.Enabled = True connected = True Else connected = False Timer1.Enabled = False Msgbox(LastException.Message, "Error connecting.") End If End Sub Sub mnuDisconnect_Click Serial1.Disconnect connected = False End Sub Sub Activity_Pause (UserClosed As Boolean) End Sub Sub btnSend_Click If connected Then TextWriter1.WriteLine(txtSend.Text) TextWriter1.Flush txtSend.Text = "" End If End Sub Sub Timer1_Tick If connected Then If TextReader1.Ready Then 'check if there is any data waiting to be read txtLog.Text = txtLog.Text & TextReader1.ReadLine & CRLF txtLog.SelectionStart = txtLog.Text.Length End If End If End Subلینک ارسال
به اشتراک گذاری در سایت های دیگر
5 پاسخ به این سوال تاکنون داده شده است
ارسالهای توصیه شده
بایگانی شده
این موضوع بایگانی و قفل شده و دیگر امکان ارسال پاسخ نیست.