Hi to all.
Premise 1: probably this post is of no interest for users that don't use Serial Bluetooth communication and it is devoted to users that know what I am talking about (I cannot write much more on the subject; my purpose is to alert other people and, possibly, get an explanation of what happens; by the way I anticipate that I "empirically" resolved the issue, but I don't know why..).
Premise 2: my project is not complicated but it is bound to particular hardware, so it is useless to post it
Premise 3: what I expose here are simply "facts" that I met. I cannot exclude a mistake on my approach to the problem.
The application sends commands to a device and waits an answer from it. Then does some elaboration and sends results over Internet to a remote server. Due to this structure, it is "doubly" asynchronous.
I use OkHttp2 library for the Internet communication, while I use AsyncStreamsText.bas module and Serial lib for serial communication over Bluetooth. Versions are the latest. I took AsyncStreamsText.bas module from posts on the site, and did no change at all. Moreover, the entire App is developed starting from Serial communication example, so there is a Main module and the AsyncStreamsText module.
I have put a Log("SubName") in each Sub of the Main, so I know when and how the Sub is called.
Inside the AsyncStreamsText.bas module, there is a CallSubDelayed2 raising an event in the main module, i.e. calling a Sub Serial_NewText in the Main.
Fact 1: In the Log, I see twice the Log("SubName") message. I cannot understand whether the main module Sub is actually called twice, or the Log(Message) only is displayed twice. I am speaking of all Subs in the main, not only of the Serial_NewText function called by AsyncStreamsText module. (Why I focus attention on this latter, will be clarified in the following).
Fact 2: I have two global variables, one for storing the result of the Instrument answer and one for copying the previous one. I get a value from the text arrived on Serial_NewText(Text as string), like, for example: double Var1=Value extracted from Text. In another sub of the program, obviously not called in the meanwhile, I copy Var1 value in another variable: Var2=Var1. Both Var1 and Var2 are Global double variables. The fact is that, when Var1 is modified according to the new text arrived, also Var2 is modified. I understand that I am telling a nonsense, but must be clear (obviously) that no Var2=Var1 is called between Var1 assignment and Var2 inspection (no question about, and the proof is the fact 3 following).
Fact 3: all above problems disappear substituting the CallSubDelayed2 call in AsyncStreamsText.bas module with simple CallSub2. Sincerely I am suspicious about this empirical solution that I found.
Final notice: I have already had problems using CallSubDelayed calls and decided not to use them in general. I my opinion their use is not as simple as explained in the basics. Of course what I described here could be a basic mistake on my side, but I would like to know why, in this case, things work well with the empirical modification... if I did a mistake, the program should not work in any case ..
Premise 1: probably this post is of no interest for users that don't use Serial Bluetooth communication and it is devoted to users that know what I am talking about (I cannot write much more on the subject; my purpose is to alert other people and, possibly, get an explanation of what happens; by the way I anticipate that I "empirically" resolved the issue, but I don't know why..).
Premise 2: my project is not complicated but it is bound to particular hardware, so it is useless to post it
Premise 3: what I expose here are simply "facts" that I met. I cannot exclude a mistake on my approach to the problem.
The application sends commands to a device and waits an answer from it. Then does some elaboration and sends results over Internet to a remote server. Due to this structure, it is "doubly" asynchronous.
I use OkHttp2 library for the Internet communication, while I use AsyncStreamsText.bas module and Serial lib for serial communication over Bluetooth. Versions are the latest. I took AsyncStreamsText.bas module from posts on the site, and did no change at all. Moreover, the entire App is developed starting from Serial communication example, so there is a Main module and the AsyncStreamsText module.
I have put a Log("SubName") in each Sub of the Main, so I know when and how the Sub is called.
Inside the AsyncStreamsText.bas module, there is a CallSubDelayed2 raising an event in the main module, i.e. calling a Sub Serial_NewText in the Main.
Fact 1: In the Log, I see twice the Log("SubName") message. I cannot understand whether the main module Sub is actually called twice, or the Log(Message) only is displayed twice. I am speaking of all Subs in the main, not only of the Serial_NewText function called by AsyncStreamsText module. (Why I focus attention on this latter, will be clarified in the following).
Fact 2: I have two global variables, one for storing the result of the Instrument answer and one for copying the previous one. I get a value from the text arrived on Serial_NewText(Text as string), like, for example: double Var1=Value extracted from Text. In another sub of the program, obviously not called in the meanwhile, I copy Var1 value in another variable: Var2=Var1. Both Var1 and Var2 are Global double variables. The fact is that, when Var1 is modified according to the new text arrived, also Var2 is modified. I understand that I am telling a nonsense, but must be clear (obviously) that no Var2=Var1 is called between Var1 assignment and Var2 inspection (no question about, and the proof is the fact 3 following).
Fact 3: all above problems disappear substituting the CallSubDelayed2 call in AsyncStreamsText.bas module with simple CallSub2. Sincerely I am suspicious about this empirical solution that I found.
Final notice: I have already had problems using CallSubDelayed calls and decided not to use them in general. I my opinion their use is not as simple as explained in the basics. Of course what I described here could be a basic mistake on my side, but I would like to know why, in this case, things work well with the empirical modification... if I did a mistake, the program should not work in any case ..