SPP over Bluetooth

boadzulu

Member
Licensed User
Longtime User
Hello
I have question about sending ASCII codes over BT in SPP mode.
I have an application written in VS(for PC) and Im using simply (my own)protocol for giving some instructions for AVR processor.
I have modificated Serial Example script for testing it - and I have below results:
1) I need to send "#100" to AVR and Chr(13)(end of line) char.
When I modificated this line:
TextWriter1.WriteLine(txtSend.Text & Chr(13))
TextWriter1.Flush
txtSend.Text = ""
by adding & Chr(13) - it is working when I putting #100 to text box.
But I want to use it without text box and manual putting value - so I tried to use
TextWriter1.WriteLine("#100" & Chr(13))
but it not work. What Im doing wrong?
Thank you.


Regards

P.
@Update
Ok, Its working - I forgot about adding :
TextWriter1.Flush
:)
Next question - when this string is sent to AVR - application is hanged on - its waiting for something for few seconds - and after that I have prompt window + with question about waiting or force closing application.
How it should be resolved + that after sending this string application will come back to main activity?
 
Last edited:

boadzulu

Member
Licensed User
Longtime User
Library missing?
I have tried to use Async streams to resolve this problem - but when I try to compile program I got informtion that Uknown type: socket.
AsyncStreams library is not default library in 1.70 B4A?

Part of code:
Dim Socket1 As socket
Dim AStreams As AsyncStreams

Where I can find this library?
Thank you.
 
Upvote 0

boadzulu

Member
Licensed User
Longtime User
Ok, it was that - thanks.
I will try to do that with Async streams - and I will inform that it works - or not.
 
Upvote 0

boadzulu

Member
Licensed User
Longtime User
Ok.
I have resolved this problem - application was hanging when timer was on - Im not using it - after simply comment it(and checking data in read buffer) - everything works perfect.
I have another question.
When Im sending - for example:
#150 and chr(13)
controller after receiving it - will send reply - for example " 400" or any other value.
How I can read it after sending #150?
I have tried many diffrent examples - I can read it - simply catch like Im doing it on VB :
write("#150" & Chr(13))
Dim number As Byte
number = Val(rx)

Thank you for suggestion which code I should use.

Regards

P.
 
Upvote 0

boadzulu

Member
Licensed User
Longtime User
Hi,
Thank you for reply.
Im not using Asyncstreams - Im sending commands in method:
TextWriter1.WriteLine("#2" & Chr(13) & "914" & Chr(13) & SeekBar3.Value & Chr(13))
TextWriter1.Flush
so - in this situation - how i can read incoming bytes after sending request?

Thank you.


Regards

P.
 
Upvote 0

boadzulu

Member
Licensed User
Longtime User
Yes, I have read.
But as I told above - when timer is on - after sending request to the lamp - application is hanging on.
For better understandign teh problem:
application on android have to send "#100" string - and confirmed by Chr(13)
after that - application on AVR is checking - what string is received - and if it is #100:
Case 100 : Print "working..." ; Chr(26);
And this is not received by android...
I dont know where problem is placed - I tried to use many diffrent code configuration - and its not working for me.
So - I asked for simple solution like wrote above(in VB):
1. sending string to serial
TextWriter1.WriteLine("#100" & Chr(13))

2. waiting for rx string
"
Dim number As Byte
number = Val(rx)
"
Or - if I missed solution on this tutorial - please let me know.
Thanks!

P.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
TextWriter1.WriteLine("#100" & Chr(13))
This line is wrong. You should use TextWriter1.Write. WriteLine add an additional new line character (chr(10)).

You cannot pause the execution of the program. Android doesn't allow it. You should send the request and then handle the response either with a timer or with AsyncStreams event.
 
Upvote 0
Top