Can we Modify Serial 1.20?

Scantech

Well-Known Member
Licensed User
Longtime User
Who created Serial 1.20 library? Is it Erel. Is there any chance we can modify the library. I need a slight modification to it. I was wondering if one function can be added to the list. A simple command that will allow Newdata Event to get raised or not. ReadyReceive = true then Newdata Event will be allowed to get raised on data availability. This may prevent NewData Event from overlapping each other and causing the data to arrange in wrong order. NewData event works great with a fast processors or using prefix mode, but when it comes to a slow processor you may run into problems. Just a suggestion. Thank you
 

Scantech

Well-Known Member
Licensed User
Longtime User
I am not the only one who is experiencing with this data problem. 2 Users reported similar problem as I described it.

basic4android - Serial data over bluetooth - getting chopped up? - Stack Overflow

http://www.b4x.com/forum/basic4android-updates-questions/12661-asyncstreams-vs-inputstream.html#post71817

e.g. Data packets expecting in the NewData Event 486B1041050009
>

NewData Event is returning data in chunks. Here is a good behavior of Newdata Event. Please note using String Builder or Strings have similiar results. This example is in Strings.

Astreams......: 4
Astreams......: 486B10
Astreams......: 486B104105
Astreams......: 486B10410500
Astreams......: 486B1041050009
Astreams......: 486B1041050009
>
AStream_NewData: 486B1041050009
>

Breakdown:
Event #1 = 4
Event #2 = 86B10
Event #3 = 4105
Event #4 = 00
Event #5 = 09
Event #6 = >

This result in good behavior.
------------------------------------------------------------------

Here is a bad behavior of the Newdata event

Astreams......: 4
Astreams......: 486B1041
Astreams......: 486B104109
Astreams......: 486B104109
05
Astreams......: 486B104109
0500
Astreams......: 486B104109
0500
Astreams......: 486B104109
0500
>
AStream_NewData: 486B104109
0500
>

Breakdown:
Event #1 = 4
Event #2 = 86B1041
Event #3 = 09
Event #4 = 05
Event #5 = 00
Event #6 = SAME #5: NO DATA?
Event #7 = >

Data 09 Jumped in before 0500??

Also notice NewData Event Triggered twice for Astreams......: 486B104109
0500 (Event #5 and #6)

It appears the NewData Event was interrupted. I am thinking can we somehow prevent the Newdata Event from getting raised until I issue a command to continue. I am trying to figure out a solution but it is difficult for me without doing any trial and error test. Basically, the source code would have to be in my position. But Java is out my league.
 
Last edited:
Upvote 0

Scantech

Well-Known Member
Licensed User
Longtime User
Can you post your code?
Are you showing a modal dialog or calling DoEvents?


B4X:
Sub AStreams_NewData (Buffer() As Byte)
'   msgBuilder.Append(BytesToString(Buffer, 0, Buffer.Length, "UTF8"))
'   Log("Astreams......: "  & msgBuilder)
'   
'   'LAST CHAR THEN RESET
'   If msgBuilder.ToString.EndsWith(">") Then       
'      msg = msgBuilder.ToString.Replace(Chr(13), Chr(10))
'      Log("AStream_NewData: " & msg)
'      blnReadySend = True               'ELM IDLE STATE INDICATOR
'      Timer_Timeout.Enabled = False      'RESET TIMEOUT
'      msgBuilder.Remove(0, msgBuilder.Length)
'   Else If msgBuilder.ToString.Contains(">") Then
'      Log("AStream_NewData: Bad Data " & msg)
'      blnReadySend = True
'      Timer_Timeout.Enabled = False
'      msgBuilder.Remove(0, msgBuilder.Length)
'      msg = ""
'   End If


'===============================================

    msg = msg & BytesToString(Buffer, 0, Buffer.Length, "UTF8")
   msg = msg.Replace(Chr(13), Chr(10))
   Log("Astreams......: "  & msg)
   
   'LAST CHAR THEN RESET
   If msg.EndsWith(">") Then 
      Log("AStream_NewData: " & msg)
      blnReadySend = True               'ELM IDLE STATE INDICATOR
      Timer_Timeout.Enabled = False      'RESET TIMEOUT
   Else If msg.Contains(">") Then
      Log("AStream_NewData: Bad Data " & msg)
      blnReadySend = True
      Timer_Timeout.Enabled = False
      msg = ""
   End If
end sub

No doevents is used in my codes. Calling a modal Dialog inputlist will do (not always). The coding works ok with the new phone (Fast Processor). Never had any problems, however my slow processor phone gives me this problem.
 
Upvote 0

Scantech

Well-Known Member
Licensed User
Longtime User

I still do not understand what you mean by that. Every message received from this bluetooth device will end up with ">". If the Data comes in right order then this detection works great unless you call a modal dialog. I use Timer_Timeout just in case ">" is not detected at the end of the message. I said it before, I can query data all day long without any problems until I call up the Modal Dialog.
 
Upvote 0

Scantech

Well-Known Member
Licensed User
Longtime User

Ok. I understand now. That makes more sense. I guess I will have to deal with it. Not a big deal. Thanks for you time, Erel.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…