Android Question Google Code Scanner read code 32 Italian pharmaceutical code

Xfood

Expert
Licensed User

Hello everyone, I was trying this new class made available by Erel, I wanted to ask two things,

1) it is possible to have him read the Italian pharmaceutical code 32, I attach an example,
2) it is possible to launch reading inside a panel and not full screen


1714080059690.png
 

drgottjr

Expert
Licensed User
Longtime User
no and no. this is a very specific barcode reading library published by google for people who
simply want a point and shoot barcode reading app. the camera action is specifically written to
zoom into a detected barcode and to exclude everthing else. it's not like a normal camera
app. and it can't be changed.

as to the italian pharmaceutical code, this is just a barcode 39 variant. in other words, it is decoded
like a barcode 39, but the result needs to be parsed differently. this is something that can be added
to your app after the scanner returns its result.

look at the attached. if a code39 is returned with 6 characters, it's likely to be an italian pharma
code32. parse it and you get the result that is visible underneath your example. you can add
parsing to many different types of barcodes.

google's documentation clearly states that this library is meant for simple, quick barcode reading.
it implies that if you want some other kind of scanning, you need to use the full barcode scanning
model. but this is fake; even the full barcode model does not do special parsing. you need to
add that yourself.
 

Attachments

  • pharma.png
    pharma.png
    217.5 KB · Views: 83
Last edited:
Upvote 0

sirjo66

Well-Known Member
Licensed User
Longtime User
It's very simple !!!!

This Italian pharmaceutical barcode is a CODE-39 with base32 chars, so.....

Scan the barcode, it returns V3TX5N
Well, now use the table at the page https://www.codiceabarre.it/bccode32.html and transform each char in decimal number, in our case:
27 03 25 29 05 20

Now transform each number in binary string padding 5 bits, so:
11011 00011 11001 11101 00101 10100
Now join all together:
110110001111001111010010110100
And transform in decimal number: 909964468

That's all folks !!!
 
Upvote 0

Xfood

Expert
Licensed User
in fact I had created a function with the old management

I checked if the code type was 2 (code 39) and if the length was 6
, but I actually wanted to know if everything was integrated with the new version of googlescan

I attach the function here, maybe it can be useful to someone
B4X:
=================
' da code 39 a code 32 farmaceutici
'================================================================================
Sub Code39To32(cStringa As String) As String
Dim Matrice As List
Dim nValore As Long
Dim cValore As String
Dim k As Int
Dim i As Int
Dim CodiceErrato As Boolean : CodiceErrato=False

Matrice.Initialize2(Array As String ("0","1","2","3","4","5","6","7","8","9","B","C","D","F","G","H","J","K","L","M","N","P","Q","R","S","T","U","V","W","X","Y","Z"))
If cStringa.Length=6 Then
i=1
Do While i<=cStringa.Length And Not(CodiceErrato)
k =Matrice.IndexOf(cStringa.SubString2(i-1,i))
' verifico se esiste il carattere passato altrimenti considero codice errore
'ed esco dalla procedura, in caso di caratteri strani tipo @-., ecc.
If k <0 Then
CodiceErrato=True
Else
nValore=nValore+(k*Power(32,6-i))
End If
i=i+1
Loop
Else
CodiceErrato=True
End If

If CodiceErrato=True Then
cValore="A000000000"
Else
cValore=nValore
cValore="000000000" & nValore
cValore="A" & cValore.SubString(cValore.Length-9)
End If
Return cValore
End Sub
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
You may find it useful. These are some of the functions I use to scan base32 barcode images.
B4X:
Public Sub TestBase32
    Log(DecimalToBase32("909964468"))
    Log(Base32ToDecimal(DecimalToBase32("909964468")))
End Sub

Public Sub DecimalToBase32(CodeDecimal As Int) As String
    Dim Base32Chars As String = "0123456789BCDFGHJKLMNPQRSTUVWXYZ"
    Dim Base32Value As StringBuilder
    Base32Value.Initialize
    Do While CodeDecimal > 0
        Dim Remainder As Int = CodeDecimal Mod 32
        CodeDecimal = CodeDecimal / 32
        Base32Value.Insert(0,Base32Chars.CharAt(Remainder))
    Loop
    Return Base32Value.ToString
End Sub

Public Sub Base32ToDecimal(Base32 As String) As Long
    Dim Base32Chars As String = "0123456789BCDFGHJKLMNPQRSTUVWXYZ"
    Dim DecimalValue As Long
    Dim Exponent As Long
    For i = Base32.Length - 1 To 0 Step -1
        DecimalValue = DecimalValue + (Base32Chars.IndexOf(Base32.CharAt(i)) * Power(32, Exponent))
        Exponent = Exponent + 1
    Next
    Return DecimalValue
End Sub
1714380694949.png
 
Upvote 0
Top