Hypnos Active Member Licensed User Longtime User May 7, 2016 #1 Hi Erel and everyone, Can you please give me an example code how to translate the follow code into B4R? Thanks! Code: Copy void setup() { Serial.begin(31250); } void loop() { Serial.write(0x99); Serial.write(0x1E); Serial.write(0x45); }
Hi Erel and everyone, Can you please give me an example code how to translate the follow code into B4R? Thanks! Code: Copy void setup() { Serial.begin(31250); } void loop() { Serial.write(0x99); Serial.write(0x1E); Serial.write(0x45); }
Erel B4X founder Staff member Licensed User Longtime User May 7, 2016 #2 Code: Copy Sub Process_Globals Public Serial1 As Serial End Sub Private Sub AppStart Serial1.Initialize(31250) AddLooper("Looper1") End Sub Sub Looper1 Serial1.Write(Array As Byte(0x99, 0x1E, 0x45)) End Sub In most cases a timer is better than a looper: Timers, Loopers and CallSubPlus Upvote 0
Code: Copy Sub Process_Globals Public Serial1 As Serial End Sub Private Sub AppStart Serial1.Initialize(31250) AddLooper("Looper1") End Sub Sub Looper1 Serial1.Write(Array As Byte(0x99, 0x1E, 0x45)) End Sub In most cases a timer is better than a looper: Timers, Loopers and CallSubPlus
Hypnos Active Member Licensed User Longtime User May 8, 2016 #3 Hi Erel, I got "Unknown member: write" error in the "Serial1.wirte" line ? Upvote 0
Erel B4X founder Staff member Licensed User Longtime User May 8, 2016 #4 My mistake. I'm too used to working with AsyncStreams. If you are only writing to the stream then use: Code: Copy Serial1.Stream.WriteBytes(ArrayAs Byte(0x99, 0x1E, 0x45), 0, 3) Discussions related to AsyncStreams: https://www.b4x.com/android/forum/pages/results/?query=b4r+asyncstreams Upvote 0
My mistake. I'm too used to working with AsyncStreams. If you are only writing to the stream then use: Code: Copy Serial1.Stream.WriteBytes(ArrayAs Byte(0x99, 0x1E, 0x45), 0, 3) Discussions related to AsyncStreams: https://www.b4x.com/android/forum/pages/results/?query=b4r+asyncstreams
Hypnos Active Member Licensed User Longtime User May 8, 2016 #5 It's worked! Yes, I asking for this example because I found many of the example in this forum using "AsyncStreams" and I'm not quite understand what's AsyncStreams and why not using serial1.stream directly. I'll look into the related discussion and try to figure out what's the different.. Thanks for your help Erel! Upvote 0
It's worked! Yes, I asking for this example because I found many of the example in this forum using "AsyncStreams" and I'm not quite understand what's AsyncStreams and why not using serial1.stream directly. I'll look into the related discussion and try to figure out what's the different.. Thanks for your help Erel!
Erel B4X founder Staff member Licensed User Longtime User May 8, 2016 #6 If you are only writing then there is no difference. AsyncStreams takes care of checking whether there is new data and raises the NewData event when the data is available. AsyncStreams also raises the Disconnected event if the connection breaks. However it will never happen with serial ports. Upvote 0
If you are only writing then there is no difference. AsyncStreams takes care of checking whether there is new data and raises the NewData event when the data is available. AsyncStreams also raises the Disconnected event if the connection breaks. However it will never happen with serial ports.