Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Bug BASCOM AVR 2.0.8.2 version?
Goto page Previous  1, 2
 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Tue Mar 10, 2020 6:12 pm    Post subject: Reply with quote

After I've first suspected a dynamic issue, I can confirm now an actual problem.
It's only the first 'select' branch, which is executed in case of a match, the other branches fail.
Code:
Rxdata1 = "[06GM TEST]"

            Select Case Mid(Rxdata1 , 4 , 2)
               Case "GM" : Bip
                           Waitms 500   ' <---- gets executed
                           Print "OK GM";
               Case "GS" : Bip
                           Waitms 500
                           Print "OK GS";
               Case "SM" : Bip
                           Waitms 500
                           Print "OK SM";
            End Select

Code:
Rxdata1 = "[06SM TEST]"

            Select Case Mid(Rxdata1 , 4 , 2)
               Case "GM" : Bip
                           Waitms 500  
                           Print "OK GM";
               Case "GS" : Bip
                           Waitms 500
                           Print "OK GS";
               Case "SM" : Bip
                           Waitms 500   ' <---- does not get executed
                           Print "OK SM";
            End Select

Code:
Rxdata1 = "[06SM TEST]"

            Select Case Mid(Rxdata1 , 4 , 2)
               Case "SM" : Bip   ' <--- first and last keyword exchanged
                           Waitms 500   ' <---- gets executed
                           Print "OK GM";
               Case "GS" : Bip
                           Waitms 500
                           Print "OK GS";
               Case "GM" : Bip   ' <--- first and last  keyword exchanged
                           Waitms 500
                           Print "OK SM";
            End Select

Without digging too much in machine code, for which I have little time in the moment, I suspect that the result or the pointer of the result itself from the implicit 'select case mid' gets lost after the first branch, thus the second and third branch compare on base of invalid data.
Which is avoided by:
Code:
            Rxcmd = Mid(Rxdata1 , 4 , 2)
            Select Case Rxcmd   'Mid(Rxdata1 , 4 , 2)
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5922
Location: Holland

blank.gif
PostPosted: Tue Mar 10, 2020 9:15 pm    Post subject: Reply with quote

hi MWS

thanks for checking. i checked but only the first case which worked. i have limited time too but i should have tested that too.
indeed the pointer is lost because of the function code call.
the choice is to either flag an error since a variable is better, or to change/fix it. since the fix is simple, i changed it.

@atmega64

Quote:
but I repeat, sending the same data, with the bascom version 2.0.8.1 it works ...

yes you repeat but you fail to give proper information in the first place. when the problem is only visible under certain conditions you should provide this information.


Quote:
why does the following code make you wonder?

my remark was more in general based on all your earlier posts.
No offense but i do support for 25 year and also i answer on this forum for 25 years. It is very hard to see each post isolated from previous posts. Some users you have to ask a lot before the problem is clear. Others do not make it clear at all what they want. Others give solid info. Some never read the help. Others seems to know it from memory. I probably need a holiday.

But in the end i like to say :
thank you, a bug was found and fixed. i shall try to have a more open mind the next time Very Happy

about your code : well there is much to improve. all starts with the proper design. you just add data, you do not check for overflow. when you need to react on data you should start collecting data when you find the first bracket.
then keep adding till you find the last bracket. this will make the data shorter too.

state=0 'no data

select case state
case 0 :
if someChar="[" then state=1
case 1: 'add it
if someChar="]" then
state=2
else
if len(buffer) < 100 then' when it fit
buffer=buffer+someChar 'add
else
state=3 'too long
end if
end if
end select

in your main code check the state. when it is 2 you got a command which is stripped from the brackets already
you can also tell if you got too long data. and you could even set a state for each command. then you can test on a byte which is way better than testing on a string using a string function.

_________________
Mark
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Tue Mar 10, 2020 11:14 pm    Post subject: Reply with quote

albertsm wrote:
hi MWS

thanks for checking.

Hi Mark,
you're welcome.
Quote:
i checked but only the first case which worked

Guessed that.

Only my curiosity made me pursue the issue, despite the phlegmatic responsiveness of the TO, which gave no fun.
Wouldn't it be for that reason of curiosity, I would have stopped replying pretty soon.
Back to top
View user's profile
atmega64

Bascom Member



Joined: 23 Feb 2005
Posts: 298
Location: ITALY

italy.gif
PostPosted: Wed Mar 11, 2020 8:41 am    Post subject: Reply with quote

Quote:
yes you repeat but you fail to give proper information in the first place. when the problem is only visible under certain conditions you should provide this information.


Albertsm I have been using BASCOM for years and I have always praised your work and this forum, and as in all the software I have seen to solve various bugs thanks and above all also to the more or less complete reports of the members of this forum.

Unfortunately, due to lack of time, I never manage to investigate some situations that I would like to investigate, but I am happy, in my small way, to contribute to the improvement of this excellent programming language which is BASCOM created by you!

Quote:
thank you, a bug was found and fixed. i shall try to have a more open mind the next time


Thanks to you for what you contributed to the creation of BASCOM!


As for code optimization, what do you think about it:


Code:
Rxcom1_isr:
   Comchar1 = Inkey()
   Select Case State
      Case 0 : If Comchar1 = 91 Then           '[ start command reading
                  Staterx = 1  
                  Rxdata1 = ""
      Case 1 : If Comchar1 = 93 Then                        '] end command reading
                  Staterx = 2
               Else
                  If Len(rxdata1) < 100 Then                'too long
                     Rxdata1 = Rxdata1 + Chr(comchar1)
                  Else
                     Staterx = 3
                  End If
               End If
   End Select
Return



Quote:
I probably need a holiday.


if for this, I am thinking of moving to a stilt house in Polynesia and living there ... Wink Very Happy
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum