B4J Question [solved] Problem to read/send text messages via serial port

TomKluz

Active Member
Licensed User
Mr Erel,

Due to your suggestion I am starting a new thread, to follow the problem about reading/sending text messages via serial port. I have change a little your example of chat to declare astream value in normal AsyncStream mode (not prefix). I have got at last something but it is only a letter B and nothing else. On the ater site is an Arduino board sending constantly a measured value as text using Serial.println(Value), where Value is a text ("+21.34" for example). I chave attached corrected chat fle, Log is clear, no info at all.
Regarding AsyncStreamText I have got an info that I am out of library reference.
Which library cantains a reference about AsyncStreamText ? and where is a kind of manual to read about a case like mine ?

Sorry to ask such simple questions (for me thay are not).

Tomasz
 

Attachments

  • Chat_to_send.zip
    34.5 KB · Views: 231

Erel

B4X founder
Staff member
Licensed User
Longtime User
You need to start from the beginning.
Delete the FXML layout file. Learn how to use the internal designer.
Why not use B4R to program the Arduino? It will be simpler.
AsyncStreamsText class is attached.

Watch the video tutorials. Everything will be simpler.

https://www.b4x.com/etp.html
 

Attachments

  • AsyncStreamsText.bas
    1.8 KB · Views: 245
Upvote 0

TomKluz

Active Member
Licensed User
Arduino is already done. It is 2 axis inclinometer plus horizontal rotation angle measurement and works really nice. I have started 2 month ago with that project from 0 and had no idea about B4X. Recently, in my opinion, it is no sense to rewrite everything.
I know that layout of chat example is not so good but acceptable for a moment. I would like to achive a good result in reading from serial port and sending a simple commands to Arduino. As I wrote a goal is bluetooth connection and finally Android app.
Thanks for AsyncStreamText class. Should I put it into AdditionalLibraries folder ?

Thanks so much
 
Last edited by a moderator:
Upvote 0

TomKluz

Active Member
Licensed User
Surtenly there is no ather choice, we have to learn in every possible way. I would like only to see first a little light on the horyzont. A little hope, that overtaking a bluetooth protocol is possible. If so, I will start to dress an upp with nice layouts, colours and other features.
What does it mean "to add it to your project" ?
Tomasz
 
Upvote 0

TomKluz

Active Member
Licensed User
Seems to be that first piece of ice has been broken. Chat PC example has start to receive a data from Arduino and send simple commands back which are accepted.
Finally I didn't use AsyncStreamsText class but only AstnsStreams in non prefix mode. The problem was to set a proper port speed to 9600 because Arduino is using this.
Anyway it is a really hard job for me yet.
Now a time to dress has come.
 
Upvote 0

TomKluz

Active Member
Licensed User
I have made a simple change in an example file. I have noticed that data format coming via serial port to PC is not stable. Every string has to have 6 places like +XX.XX and in most cases is Ok but sometimes is straggled (cuted) into a pieces like on a picture. I have include also a code. So far I am testing a string lenght and printing only if it is 6. May I ask for the advice why it happens ? Or mayby I have to change something in Arduino soft ?
Tomasz
 

Attachments

  • Scrraggly strings.jpg
    Scrraggly strings.jpg
    25.1 KB · Views: 202
  • Mały.zip
    36.9 KB · Views: 212
Upvote 0

TomKluz

Active Member
Licensed User
Mr Erel,
I have seen it few times, but surtenly didn't understand.
Do you mean that I have use Custom Type and B4JSerializator function ? I am wormly asking you to suggest more precise, please.
On the other site is sitting a real begginer (or maybe a donkey).
Thank you in advance .Tomasz
P.S. May you suggest what to do to make stand alone exe app from b4j file ?
How to create a jar file ? Sorry for this primitive questions. I have been looking for the answers in your community but didn't really found.
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
How to create a jar file ?
You should start a new thread for each question.

Do you mean that I have use Custom Type and B4JSerializator function ?
No. The video explains that unless you are using AsyncStreams in prefix mode, you should expect messages to be split or merged.
 
Upvote 0

TomKluz

Active Member
Licensed User
So in this case you think that AsyncStreams in prefix mode is the only solution ? Should I try to convert data sended by Arduino to look like prefix mode ?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
So in this case you think that AsyncStreams in prefix mode is the only solution ?
Not at all. You just need to understand that the message can be split. It is up to you to properly build the messages. A simple solution is to end each message with an end of line character and use AsyncStreamsText.
 
Upvote 0

TomKluz

Active Member
Licensed User
Have tryed to use AsyncStreamText and it works. Finally I am getting a clear and fluent reading on PC display.
It was extremly hard to obtain this stage. I am having problems to reach a documentation about your language, every cammand has so many variants. There is no detailed description. This is an enviroment for somone with experience from anothers in my opinion. Anyway, I am happy to see above mentioned PC display and probably will
ask more questions in near future. Thank you very much for now.
Tomasz
 
Upvote 0
Top