View previous topic :: View next topic |
Author |
Message |
matjazs
Joined: 08 Nov 2016 Posts: 104
|
Posted: Sat Dec 02, 2023 1:44 pm Post subject: Version Problem |
|
|
This example is made to read an RFID card.
Compiled in version 2.0.8.5 it works, but not in 2.0.8.6.
Where is the problem?
P.S.
I noticed that the BASCOM IDE screen in version 2.0.8.5. is clear and in version 2.0.8.6 it is unclear/foggy. I am using a laptop with full HD resolution 1920x1080, Scale 125%.
Code: | $regfile = "m8def.dat"
$crystal = 7372800
$baud = 9600
$hwstack = 50
$swstack = 50
$framesize = 60
Config Serialin = Buffered , Bytematch = 2 , Size = 250
'------------------------------------------------------------------------------
Config Portb.2 = Output
Rele1 Alias Portb.2
Config Portd.3 = Output
Dere Alias Portd.3
Reset Dere
Dim Data0 As Byte
Dim Data1 As Byte
Dim Data2 As Byte
Dim Data3 As Byte
Dim Data4 As Byte
Dim Data5 As Byte
Dim Data6 As Byte
Dim Data7 As Byte
Dim Ser0 As String * 2
Dim Ser1 As String * 2
Dim Ser2 As String * 2
Dim Ser3 As String * 2
Dim Ser4 As String * 2
Dim Ser5 As String * 2
Dim Ser6 As String * 2
Dim Ser7 As String * 2
Dim Card_nr As String * 17
Dim Card_nrx As String * 17
Enable Interrupts
'------------------------------------------------------------------------------
Main:
Do
Loop
End
'------------------------------------------------------------------------------
'Serial0bytereceived:
Serial0charmatch:
'complet RFID card Nr. in HEX: 02 0A 02 71 00 3E 99 26 F8 03
Inputbin Data0 , Data1 , Data2 , Data3 , Data4 , Data5 , Data6 , Data7
Clear Serialin
Ser0 = Hex(data0)
Ser1 = Hex(data1)
Ser2 = Hex(data2)
Ser3 = Hex(data3)
Ser4 = Hex(data4)
Ser5 = Hex(data5)
Ser6 = Hex(data6)
Ser7 = Hex(data7)
Card_nr = "<" + Ser1
Card_nr = Card_nr + Ser2
Card_nr = Card_nr + Ser3
Card_nr = Card_nr + Ser4
Card_nr = Card_nr + Ser5
Card_nr = Card_nr + Ser6
Card_nr = Card_nr + Ser7
Card_nrx = Card_nr
Card_nrx = Left(card_nrx , 13)
Set Dere
Print Card_nrx 'Output text: <71003E9926F
Waitms 10
Reset Dere
Delchars Card_nrx , "<"
Card_nr = ""
Ser0 = ""
Ser1 = ""
Ser2 = ""
Ser3 = ""
Ser4 = ""
Ser5 = ""
Ser6 = ""
Ser7 = ""
Return
'------------------------------------------------------------------------------ |
(BASCOM-AVR version : 2.0.8.6 ) |
|
Back to top |
|
 |
albertsm
Joined: 09 Apr 2004 Posts: 6173 Location: Holland

|
Posted: Sat Dec 02, 2023 10:05 pm Post subject: |
|
|
please do not create multiple topics in one topic.
you best read this : https://bascomforum.de/index.php?thread/2810-update-2-0-8-6/
usually the settings from the Environment, Font should fix it. bascom scales depending on your settings.
and you can use the windows setting as the user posted. honestly i have no idea why it does not work the same for everyone since i tested on high res with sharp images in all modes.
could be a win11 thing.
your code is not how i would write it.
you trigger on hex 02 but what if there is no other data?
and all the time you are reading the interrupts are blocked.
but ok that is besides the question.
you do not say what does not work.
please give some more details. _________________ Mark |
|
Back to top |
|
 |
matjazs
Joined: 08 Nov 2016 Posts: 104
|
Posted: Sun Dec 03, 2023 8:10 am Post subject: |
|
|
I'm sorry. Please move this post to the appropriate topic.
Thank you very much. I'm using Win10 and set to Win7 compatibility mode. It works great now.
Code explanation:
Code: | Print Card_nrx 'Output text: <71003E9926F |
No data from serial port. That means that
procedure is not performed.
&H02 is start byte
&H03 is end byte
All information from card look like:
Quote: | HEX: 02 0A 02 71 00 3E 99 26 F8 03 |
In all cases on start and end is 02 0A 02 ... 03
I take only:
Quote: | HEX: 71 00 3E 99 26 F8 |
... then I convert HEX to String, add sign "<" and send on serial port. In version 2.0.8.5 works, but in version 2.0.8.6 not.
I enabled interrupts at startup, before the main procedure. How else would I find out? |
|
Back to top |
|
 |
albertsm
Joined: 09 Apr 2004 Posts: 6173 Location: Holland

|
Posted: Sun Dec 03, 2023 12:00 pm Post subject: |
|
|
i understand your code. the reason it works in 2085 is that 2085 contains a flaw which was corrected.
but the side effect is that wrong usage of the serial int will not work.
Let me explain.
When you use buffered serial input the buffer is filled on the background when the data received interrupt occurs. and you have the option to do something based on the character you receive. (bytematch)
This is intended to set some flag or store the location of data, not to write a complete app in the handler. This because the interrupt must be short as possible so the main code can execute and other interrupts can be handled as well. all the time you spend in the interrupt no other interrupt can occur. That because the processor automatic in hardware clears the global interrupt flag. It is enabled when the interrupt ends with RETURN/END SUB
When you read/write to the buffer some variables need to be protected so global interrupts are disabled, the data is updated and in 2085 the interrupts were enabled again.
The(my) idea was that since buffered serial need global interrupts anyway to function, that would not be a problem.
But user MWS pointed out that it is not safe/good. And he is very right. Because when a user has disabled the global interrupts for whatever reason, it is not good that reading data from the buffer will enable it without the user knows this. it could trigger other interrupts.
So in 2086 the state of the global int is stored and restored which is better.
While this is great for most apps, in some cases this can give a problem. Like in your case.
when the ISR is executed, and believe me it is when it receives byte value 2, the global ints are disabled like normal.
THen you read the first byte from the buffer which will work too.
But all your other readings fail because no new data is entering since the ISR blocks the interrupt.
And the code hangs in the ISR waiting for data that never arrives.
First of all one should never assume that data will follow only because you received some byte. It is better to wait till you received the trailer byte so you know that in normal cases all data is there.
I will post a sample later. _________________ Mark |
|
Back to top |
|
 |
albertsm
Joined: 09 Apr 2004 Posts: 6173 Location: Holland

|
Posted: Sun Dec 03, 2023 1:21 pm Post subject: |
|
|
here is an example.
Code: |
$regfile = "m88pdef.dat"
$crystal = 8000000
$baud = 9600
$hwstack = 50
$swstack = 50
$framesize = 60
Declare Sub Serial0bytereceived()
Config Serialin = Buffered , Bytematch = All , Size = 250
'------------------------------------------------------------------------------
'Config Portb.2 = Output
'Rele1 Alias Portb.2
'Config Portd.3 = Output
'Dere Alias Portd.3
'Reset Dere
Dim Card_nr As String * 17
Dim Card_nrx As String * 17
Enable Interrupts
'------------------------------------------------------------------------------
Print "test isr"
Dim B As Byte
Dim Bstate As Byte
Main:
Do
If Card_nrx <> "" Then
Print Card_nrx
Card_nrx = ""
End If
Loop
End
'------------------------------------------------------------------------------
'complet RFID card Nr. in HEX: 02 0A 02 71 00 3E 99 26 F8 03
Sub Serial0bytereceived()
Select Case Bstate
Case 0 'no data received yet
If R25 = 2 Then
Bstate = 2 'we got a header
B = Waitkey() 'eat the header
Card_nr = ""
End If
Case 2 'trailer received
If R25 = 3 Then 'trailer or data byte
If Len(card_nr) = 16 Then 'all ok
Bstate = 3 'set state
B = Waitkey() 'eat the trailer
Card_nrx = Left(card_nr , 13) 'this var will be used in the main app
Bstate = 0 'for the next
Else
Gosub Getthedata 'process data '
End If
Else
Gosub Getthedata 'process the data
End If
End Select
Exit Sub
Getthedata:
B = Waitkey() ' get data
If Len(card_nr) < 16 Then
Card_nr = Card_nr + Hex(b) 'add to string
Else
Bstate = 0 'reset
End If
Return
End Sub
|
there are many more ways, i would do it different but this is simple to get. R25 contains the value from the buffer. but take care that R25 can be destroyed later.
the bstate is best set to 0 by the main app.
but for this sample it was done inside the ISR.
as you can see there is a check to see we do not catch byte data as header.
for the reported problem i will extend the help.
when there is lost of 'abuse' i can also change it back and make the better code an option. i do not know. most users do not actually read all things.
When there is a bug/flaw we prefer to kill it. but of course for users it is important that their code still works. _________________ Mark |
|
Back to top |
|
 |
matjazs
Joined: 08 Nov 2016 Posts: 104
|
Posted: Sun Dec 03, 2023 5:47 pm Post subject: |
|
|
Thank you very, very much. I tried your example and it works very well.
I read your explanation, but I'm not entirely sure I understood everything.  |
|
Back to top |
|
 |
|