Jump to content

Bar code Reader * UPC and ITF


youknowwho4eva
 Share

Recommended Posts

Updated to scan any image on your pc. Does need some error proofing but still amazing.

#include <misc.au3>
#include <array.au3>
#include <GUIConstantsEx.au3>
#include <Math.au3>
#include <color.au3>
$t = 2
Dim $color[100000]
Dim $bar[1000]
dim $counter[1000]
dim $counter2[1000]
dim $num[1000]
$dll = DllOpen("user32.dll")
$start = 0
GUICreate("UPC Scanner",400,400)
GUICtrlCreateLabel("Once you click on start" & @LF & "Click once on the left of the bar code" & @LF & "And once on the right of the bar code.",20,20)
GUICtrlCreateLabel("UPC:",20,80)
$upc = GUICtrlCreateInput("000000000000",20,100,100,20)
$go = GUICtrlCreateButton("Start",20,150,75,20)
$complete = GUICtrlCreateLabel("Proceed",20,180,200,20)
GUICtrlSetState($upc,$gui_disable)
GUICtrlSetBkColor($upc,0xffffff)
If $start = 1 Then $msg = $go

GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Select
    Case $msg = $gui_event_close
        Exit
    Case $msg = $go
        GUICtrlSetData($complete, "Proceed")
        GUICtrlSetData($upc,"")
        
        Sleep(100)
        Do
            Sleep(100)
            Until _IsPressed("01",$dll) = 1
    
        $mouse = MouseGetPos()
        $start = 1
        Sleep(200)
    
    Do
            Sleep(100)
            Until _IsPressed("01",$dll) = 1
    GUICtrlSetData($complete,"Processing Please Wait")
        $mouse2 = MouseGetPos()
        Call("start")
        Func start()
        $start = 0
        For $n = 1 to ($mouse2[0] - $mouse[0]) + 1
        $color = PixelGetColor($mouse[0] + $n,$mouse[1])
        
        $red = _colorgetred($color)
        If $red > 200 Then 
            $bar[$n] = 1
        ElseIf $red < 100 Then
            $bar[$n] = 0
        Else
            $bar[$n] = 2
        EndIf
    
        
        
    Next
    
;~  _ArrayDisplay($bar)
    $bar[0] = $n
    
;~      MsgBox(0,$bar[0],"hmmm")
;~  MsgBox(0,"",$bar[0])
    For $i = 1 to $bar[0]
        If $bar[$i] = 2 Then
            _ArrayDelete($bar,$i)
            $i -= 1
        EndIf
        Next
;~  _ArrayDisplay($bar)

    For $i = 1 to $bar[0]
        if $bar[1] <> 0 Then
            _ArrayDelete($bar,1)
        Else
            ExitLoop
        EndIf
    Next
    _ArrayReverse($bar)
    
    For $i = 0 to 1000000
        if $bar[0] <> "0" Then
            _ArrayDelete($bar,0)
;~          MsgBox(0,"", $i)
        Else
            ExitLoop
        EndIf
    Next
;~  _ArrayDisplay($bar)
    _ArrayReverse($bar)
;~      _ArrayDisplay($bar)
;~      If $bar[1] = 0 And $bar[2] = 0 And $bar[3] = 0 And $bar[4] = 1 And $bar[5] = 1 And $bar[6] = 1 And $bar[7] = 0 And $bar[8] = 0 And $bar[9] = 0 Then
;~      Else
;~          MsgBox(0,"","Read Error")
;~      EndIf
For $r = 2 to 100
    
        If $bar[$r] <> $bar[$r-1]Then
            ExitLoop
        EndIf
    
Next
$r = $r + $t
For $i = 1 to $bar[0]
        if $bar[1] = 0 Then
            _ArrayDelete($bar,1)
        Else
            ExitLoop
        EndIf
    Next
    
For $i = 1 to $bar[0]
        if $bar[1] = 1 Then
            _ArrayDelete($bar,1)
        Else
            ExitLoop
        EndIf
    Next
For $i = 1 to $bar[0]
        if $bar[1] = 0 Then
            _ArrayDelete($bar,1)
        Else
            ExitLoop
        EndIf
    Next
    _ArrayReverse($bar)
    For $i = 0 to 10000
        if $bar[0] <> 1 Then
            _ArrayDelete($bar,0)
        Else
            ExitLoop
        EndIf
    Next
    For $i = 0 to 10000
        
        if $bar[0] = 1 Then
            _ArrayDelete($bar,0)
        Else
            ExitLoop
        EndIf
    Next
    For $i = 0 to 10000
        if $bar[0] <> 1 Then
            _ArrayDelete($bar,0)
        Else
            ExitLoop
        EndIf
    Next
    _ArrayReverse($bar)
;~  _ArrayDisplay($bar)
;~  $r -= 1
;~  MsgBox(0,"",$r)
    $bar2 = _ArrayToString($bar)
;~  MsgBox(0,"",$bar2)
    $count = 2 * $r
    $bar2 = StringTrimLeft($bar2, StringLen($bar[0]) + 1)
;~  $bar2 = StringTrimRight($bar2, $count - 1)
        $count1 = StringLen($bar2)
;~      MsgBox(0,"",$bar2 & @lf & $count1)
        $bar3 = StringTrimLeft($bar2,$count1 / 2)
        $bar4 = StringTrimRight($bar2,$count1 / 2)
        
;~      MsgBox(0,"bar3",$bar3)
;~      MsgBox(0,"bar4",$bar4)
        
    
For $i = 1 to StringLen($bar3)
    $q = StringLeft($bar3,1)
        if $q = "1" Then
            $bar3 = StringTrimLeft($bar3,2)
;~          MsgBox(0,"test","caught " & $i)
    ElseIf $q = "|" Then
        $bar3 = StringTrimLeft($bar3,1)
        Else
            ExitLoop
        EndIf
    Next
;~  MsgBox(0,"3",$bar3)
    For $i = 1 to StringLen($bar3)
        $q = StringLeft($bar3,1)
        if $q = "0" Then
            $bar3 = StringTrimLeft($bar3,2)
        Else
            ExitLoop
        EndIf
    Next
;~  MsgBox(0,"3",$bar3)
    For $i = 1 to StringLen($bar3)
        $q = StringLeft($bar3,1)
        if $q = "1" Then
            $bar3 = StringTrimLeft($bar3,2)
        Else
            ExitLoop
        EndIf
    Next
;~  MsgBox(0,"3",$bar3)
    For $i = 1 to StringLen($bar4)
        
    $q = Stringright($bar4,1)
        if $q = "1" Then
;~          MsgBox(0,"","1")
            $bar4 = StringTrimright($bar4,2)
        ElseIf $q <> "1" and $q <> "0" Then
;~          MsgBox(0,"","|")
    $bar4 = StringTrimright($bar4,1)
        Else
;~          MsgBox(0,"","neither")
            ExitLoop
        EndIf
    Next
;~  MsgBox(0,"4",$bar4)
    For $i = 1 to StringLen($bar4)
        $q = Stringright($bar4,1)
        if $q = "0" Then
            $bar4 = StringTrimright($bar4,2)
        Else
            ExitLoop
        EndIf
    Next
;~  MsgBox(0,"4",$bar4)
    For $i = 1 to StringLen($bar4)
        $q = Stringright($bar4,1)
        if $q = "1" Then
            $bar4 = StringTrimright($bar4,2)
        Else
            ExitLoop
        EndIf
    Next
;~  MsgBox(0,"4",$bar4)
;~      $bar3 = StringTrimLeft($bar3,5 * $r)
;~      $bar4 = StringTrimright($bar4,5 * $r)
        $bar5 = $bar4
        $bar6 = $bar3
;~      MsgBox(0,"bar4",$bar5)
;~      MsgBox(0,"bar3",$bar6)
        For $e = 1 to 100
            If _MathCheckDiv($e,2) = 1 Then
            $count = stringlen(StringLeft($bar5,(stringinstr($bar5,0))-1)) / 2
            $realcount = $count
;~          MsgBox(0,$r,$realcount)
            If _MathCheckDiv($count,$r) = 1 Then
                $count += 1
;~              MsgBox(0,"here1",$count)
                If _MathCheckDiv($count,$r) = 1 Then
                    $count -= 2
;~                  MsgBox(0,"here2",$count)
                    If _MathCheckDiv($count,$r) = 1 Then
                        $count -= 1
                EndIf
            EndIf
            EndIf
            
            $count = $count / $r
        Else
            $count = stringlen(StringLeft($bar5,(stringinstr($bar5,1))-1)) / 2
            $realcount = $count
            
;~          MsgBox(0,"",$realcount)
            If _MathCheckDiv($count,$r) = 1 Then
                $count += 1
                If _MathCheckDiv($count,$r) = 1 Then
                    $count -= 2
                    If _MathCheckDiv($count,$r) = 1 Then
                        $count -= 1
                EndIf
            EndIf
            EndIf
            $count = $count / $r
            
            EndIf

        If $count = 1 Then
            $counter[$e] = 1
        ElseIf $count = 2 Then
            $counter[$e] = 2
        ElseIf $count = 3 Then
            $counter[$e] = 3
        ElseIf $count = 4 Then
            $counter[$e] = 4
        Else
            $counter[$e] = StringLen($bar5) / $r / 2
;~          MsgBox(0,"",$counter[$e])
            ExitLoop
            EndIf
            
            $bar5 = StringTrimLeft($bar5,$realcount * 2)
;~          MsgBox(0,$e,$counter[$e] & @lf & $bar5)
        Next
;~      MsgBox(0,"",$bar6)
        For $e = 1 to 100
            If _MathCheckDiv($e,2) = 1 Then
            $count = stringlen(StringLeft($bar6,(stringinstr($bar6,1))-1)) / 2
            $realcount = $count
            If _MathCheckDiv($count,$r) = 1 Then
                $count += 1
;~              MsgBox(0,"here1",$count)
                If _MathCheckDiv($count,$r) = 1 Then
                    $count -= 2
;~                  MsgBox(0,"here2",$count)
                    If _MathCheckDiv($count,$r) = 1 Then
                        $count -= 1
                EndIf
            EndIf
            EndIf
            
            $count = $count / $r
        Else
            $count = stringlen(StringLeft($bar6,(stringinstr($bar6,0))-1)) / 2
            $realcount = $count
            
;~          MsgBox(0,"",$realcount)
            If _MathCheckDiv($count,$r) = 1 Then
                $count += 1
;~              MsgBox(0,"",$count)
                If _MathCheckDiv($count,$r) = 1 Then
                    $count -= 2
;~                  MsgBox(0,"",$count)
                    If _MathCheckDiv($count,$r) = 1 Then
                        $count -= 1
;~                      MsgBox(0,"",$count)
                EndIf
            EndIf
            EndIf
            $count = $count / $r
            
            EndIf

        If $count = 1 Then
            $counter2[$e] = 1
        ElseIf $count = 2 Then
            $counter2[$e] = 2
        ElseIf $count = 3 Then
            $counter2[$e] = 3
        ElseIf $count = 4 Then
            $counter2[$e] = 4
        ElseIf $count = 5 Then
            $counter2[$e] = 4
        Else
;~          MsgBox(0,"",$count)
            $counter2[$e] = StringLen($bar6) / $r / 2
;~          MsgBox(0,"",$counter[$e])
            ExitLoop
            EndIf
            
            $bar6 = StringTrimLeft($bar6,$realcount * 2)
;~          MsgBox(0,$e,$counter[$e] & @lf & $bar6)
        Next
        $msgbx = _ArrayToString($counter)
        For $w = 1 to 100
            If StringLen($counter[$w]) <> 1 then ExitLoop
            Next
;~          MsgBox(0,"",$w)
            $v = 0
            For $g = 1 to $w + 1 step +4
                $v += 1
                If $counter[$g] = 3 and $counter [$g +1] = 2 and $counter[$g +2] = 1 Then $num[$v] = 0
                If $counter[$g] = 3 and $counter[$g +2] = 1 and $counter[$g + 3] < 2 Then $num[$v] = 0
                If $counter [$g +1] = 2 and $counter[$g +2] = 1 and $counter[$g + 3] < 2 Then $num[$v] = 0
                If $counter[$g] = 3 and $counter [$g +1] = 2 and $counter[$g + 3] < 2 Then $num[$v] = 0
                If $counter[$g] = 2 and $counter [$g +1] = 2 and $counter[$g +2] = 2 Then $num[$v] = 1
                If $counter[$g] = 2 and $counter [$g +1] = 2 and $counter[$g + 3] < 2 Then $num[$v] = 1
                If $counter[$g] = 2 and $counter[$g +2] = 2 and $counter[$g + 3] < 2 Then $num[$v] = 1
                If $counter [$g +1] = 2 and $counter[$g +2] = 2 and $counter[$g + 3] < 2 Then $num[$v] = 1
                If $counter[$g] = 2 and $counter [$g +1] = 1 and $counter[$g +2] = 2 Then $num[$v] = 2
                If $counter[$g] = 2 and $counter [$g +1] = 1 and $counter[$g + 3] < 3 and $counter[$g + 3] > 1 Then $num[$v] = 2
                If $counter[$g] = 2 and $counter[$g +2] = 2 and $counter[$g + 3] < 3 and $counter[$g + 3] > 1 Then $num[$v] = 2
                If $counter [$g +1] = 1 and $counter[$g +2] = 2 and $counter[$g + 3] < 3 and $counter[$g + 3] > 1 Then $num[$v] = 2
                If $counter[$g] = 1 and $counter [$g +1] = 4 and $counter[$g +2] = 1 Then $num[$v] = 3
                If $counter[$g] = 1 and $counter [$g +1] = 4 and $counter[$g + 3] < 2 Then $num[$v] = 3
                If $counter[$g] = 1 and $counter[$g +2] = 1 and $counter[$g + 3] < 2 Then $num[$v] = 3
                If $counter [$g +1] = 4 and $counter[$g +2] = 1 and $counter[$g + 3] < 2 Then $num[$v] = 3
                If $counter[$g] = 1 and $counter [$g +1] = 1 and $counter[$g +2] = 3 Then $num[$v] = 4
                If $counter[$g] = 1 and $counter [$g +1] = 1 and $counter[$g + 3] < 3 and $counter[$g + 3] > 1 Then $num[$v] = 4
                If $counter[$g] = 1 and $counter[$g +2] = 3 and $counter[$g + 3] < 3 and $counter[$g + 3] > 1 Then $num[$v] = 4
                If $counter [$g +1] = 1 and $counter[$g +2] = 3 and $counter[$g + 3] < 3 and $counter[$g + 3] > 1 Then $num[$v] = 4
                If $counter[$g] = 1 and $counter [$g +1] = 2 and $counter[$g +2] = 3 Then $num[$v] = 5
                If $counter[$g] = 1 and $counter [$g +1] = 2 and $counter[$g + 3] < 2 Then $num[$v] = 5
                If $counter[$g] = 1 and $counter[$g +2] = 3 and $counter[$g + 3] < 2 Then $num[$v] = 5
                If $counter [$g +1] = 2 and $counter[$g +2] = 3 and $counter[$g + 3] < 2 Then $num[$v] = 5
                If $counter[$g] = 1 and $counter [$g +1] = 1 and $counter[$g +2] = 1 Then $num[$v] = 6
                If $counter[$g] = 1 and $counter [$g +1] = 1 and $counter[$g + 3] < 5 and $counter[$g + 3] > 3 Then $num[$v] = 6
                If $counter[$g] = 1 and $counter[$g +2] = 1 and $counter[$g + 3] < 5 and $counter[$g + 3] > 3 Then $num[$v] = 6
                If $counter [$g +1] = 1 and $counter[$g +2] = 1 and $counter[$g + 3] < 5 and $counter[$g + 3] > 3 Then $num[$v] = 6
                If $counter[$g] = 1 and $counter [$g +1] = 3 and $counter[$g +2] = 1 and $counter [$g + 3] < 3 Then $num[$v] = 7
                If $counter[$g] = 1 and $counter [$g +1] = 3 and $counter[$g + 3] < 3 and $counter[$g + 3] > 1 Then $num[$v] = 7
                If $counter[$g] = 1 and $counter[$g + 1] <> 2 and $counter[$g +2] = 1 and $counter[$g + 3] < 3 and $counter[$g + 3] > 1 Then $num[$v] = 7
                If $counter [$g +1] = 3 and $counter[$g +2] = 1 and $counter[$g + 3] < 3 and $counter[$g + 3] > 1 Then $num[$v] = 7
                If $counter[$g] = 1 and $counter [$g +1] = 2 and $counter[$g +2] = 1 and $counter[$g + 3] > 2 Then $num[$v] = 8
                If $counter[$g] = 1 and $counter [$g +1] = 2 and $counter[$g + 3] < 4 and $counter[$g + 3] > 2 Then $num[$v] = 8
                If $counter[$g] = 1 and $counter [$g + 1] <> 3 and $counter[$g +2] = 1 and $counter[$g + 3] < 4 and $counter[$g + 3] > 2 Then $num[$v] = 8
                If $counter [$g +1] = 2 and $counter[$g +2] = 1 and $counter[$g + 3] < 4 and $counter[$g + 3] > 2 Then $num[$v] = 8
                If $counter[$g] = 3 and $counter [$g +1] = 1 and $counter[$g +2] = 1 Then $num[$v] = 9
                If $counter[$g] = 3 and $counter [$g +1] = 1 and $counter[$g + 3] < 3 and $counter[$g + 3] > 1 Then $num[$v] = 9
                If $counter[$g] = 3 and $counter[$g +2] = 1 and $counter[$g + 3] < 3 and $counter[$g + 3] > 1 Then $num[$v] = 9
                If $counter [$g +1] = 1 and $counter[$g +2] = 1 and $counter[$g + 3] < 3 and $counter[$g + 3] > 1 Then $num[$v] = 9
                If $counter[$g] <> 1 and $counter [$g] <> 2 and $counter[$g] <> 3 and $counter[$g] <> 4 Then ExitLoop
;~                  MsgBox(0,$num[$v],$counter[$g] & "  " & $counter [$g +1] & "  " & $counter[$g +2] & "  " & $counter[$g + 3])
                Next
                $v -= 1
                For $g = 1 to $w + 1 step +4
                $v += 1
                If $counter2[$g] = 3 and $counter2 [$g +1] = 2 and $counter2[$g +2] = 1 Then $num[$v] = 0
                If $counter2[$g] = 3 and $counter2 [$g +1] = 2 and $counter2[$g + 3] < 2 Then $num[$v] = 0
                If $counter2[$g] = 3 and $counter2[$g +2] = 1 and $counter2[$g + 3] < 2 Then $num[$v] = 0
                If $counter2 [$g +1] = 2 and $counter2[$g +2] = 1 and $counter2[$g + 3] < 2 Then $num[$v] = 0
                If $counter2[$g] = 2 and $counter2 [$g +1] = 2 and $counter2[$g +2] = 2 Then $num[$v] = 1
                If $counter2[$g] = 2 and $counter2 [$g +1] = 2 and $counter2[$g + 3] < 2 Then $num[$v] = 1
                If $counter2[$g] = 2 and $counter2[$g +2] = 2 and $counter2[$g + 3] < 2 Then $num[$v] = 1
                If $counter2 [$g +1] = 2 and $counter2[$g +2] = 2 and $counter2[$g + 3] < 2 Then $num[$v] = 1
                If $counter2[$g] = 2 and $counter2 [$g +1] = 1 and $counter2[$g +2] = 2 Then $num[$v] = 2
                If $counter2[$g] = 2 and $counter2 [$g +1] = 1 and $counter2[$g + 3] < 3 and $counter2[$g + 3] > 1 Then $num[$v] = 2
                If $counter2[$g] = 2 and $counter2[$g +2] = 2 and $counter2[$g + 3] < 3 and $counter2[$g + 3] > 1 Then $num[$v] = 2
                If $counter2 [$g +1] = 1 and $counter2[$g +2] = 2 and $counter2[$g + 3] < 3 and $counter2[$g + 3] > 1 Then $num[$v] = 2
                If $counter2[$g] = 1 and $counter2 [$g +1] = 4 and $counter2[$g +2] = 1 Then $num[$v] = 3
                If $counter2[$g] = 1 and $counter2 [$g +1] = 4 and $counter2[$g + 3] < 2 Then $num[$v] = 3
                If $counter2[$g] = 1 and $counter2[$g +2] = 1 and $counter2[$g + 3] < 2 Then $num[$v] = 3
                If $counter2 [$g +1] = 4 and $counter2[$g +2] = 1 and $counter2[$g + 3] < 2 Then $num[$v] = 3
                If $counter2[$g] = 1 and $counter2 [$g +1] = 1 and $counter2[$g +2] = 3 Then $num[$v] = 4
                If $counter2[$g] = 1 and $counter2 [$g +1] = 1 and $counter2[$g + 3] < 3 and $counter2[$g + 3] > 1 Then $num[$v] = 4
                If $counter2[$g] = 1 and $counter2[$g +2] = 3 and $counter2[$g + 3] < 3 and $counter2[$g + 3] > 1 Then $num[$v] = 4
                If $counter2 [$g +1] = 1 and $counter2[$g +2] = 3 and $counter2[$g + 3] < 3 and $counter2[$g + 3] > 1 Then $num[$v] = 4
                If $counter2[$g] = 1 and $counter2 [$g +1] = 2 and $counter2[$g +2] = 3 Then $num[$v] = 5
                If $counter2[$g] = 1 and $counter2 [$g +1] = 2 and $counter2[$g + 3] < 2 Then $num[$v] = 5
                If $counter2[$g] = 1 and $counter2[$g +2] = 3 and $counter2[$g + 3] < 2 Then $num[$v] = 5
                If $counter2 [$g +1] = 2 and $counter2[$g +2] = 3 and $counter2[$g + 3] < 2 Then $num[$v] = 5
                If $counter2[$g] = 1 and $counter2 [$g +1] = 1 and $counter2[$g +2] = 1 Then $num[$v] = 6
                If $counter2[$g] = 1 and $counter2 [$g +1] = 1 and $counter2[$g + 3] < 5 and $counter2[$g + 3] > 3 Then $num[$v] = 6
                If $counter2[$g] = 1 and $counter2[$g +2] = 1 and $counter2[$g + 3] < 5 and $counter2[$g + 3] > 3 Then $num[$v] = 6
                If $counter2 [$g +1] = 1 and $counter2[$g +2] = 1 and $counter2[$g + 3] < 5 and $counter2[$g + 3] > 3 Then $num[$v] = 6
                If $counter2[$g] = 1 and $counter2 [$g +1] = 3 and $counter2[$g +2] = 1 and $counter2[$g + 3] < 3 Then $num[$v] = 7
                If $counter2[$g] = 1 and $counter2 [$g +1] = 3 and $counter2[$g + 3] < 3 and $counter2[$g + 3] > 1 Then $num[$v] = 7
                If $counter2[$g] = 1 and $counter2[$g + 1] <> 2 and $counter2[$g +2] = 1 and $counter2[$g + 3] < 3 and $counter2[$g + 3] > 1 Then $num[$v] = 7
                If $counter2 [$g +1] = 3 and $counter2[$g +2] = 1 and $counter2[$g + 3] < 3 and $counter2[$g + 3] > 1 Then $num[$v] = 7
                If $counter2[$g] = 1 and $counter2 [$g +1] = 2 and $counter2[$g +2] = 1 and $counter2 [$g + 3] > 2 Then $num[$v] = 8
                If $counter2[$g] = 1 and $counter2 [$g +1] = 2 and $counter2[$g + 3] < 4 and $counter2[$g + 3] > 2 Then $num[$v] = 8
                If $counter2[$g] = 1 and $counter2[$g + 1] <> 3 and $counter2[$g +2] = 1 and $counter2[$g + 3] < 4 and $counter2[$g + 3] > 2 Then $num[$v] = 8
                If $counter2 [$g +1] = 2 and $counter2[$g +2] = 1 and $counter2[$g + 3] < 4 and $counter2[$g + 3] > 2 Then $num[$v] = 8
                If $counter2[$g] = 3 and $counter2 [$g +1] = 1 and $counter2[$g +2] = 1 Then $num[$v] = 9
                If $counter2[$g] = 3 and $counter2 [$g +1] = 1 and $counter2[$g + 3] < 3 and $counter2[$g + 3] > 1 Then $num[$v] = 9
                If $counter2[$g] = 3 and $counter2[$g +2] = 1 and $counter2[$g + 3] < 3 and $counter2[$g + 3] > 1 Then $num[$v] = 9
                If $counter2 [$g +1] = 1 and $counter2[$g +2] = 1 and $counter2[$g + 3] < 3 and $counter2[$g + 3] > 1 Then $num[$v] = 9
                If $counter2[$g] <> 1 and $counter2 [$g] <> 2 and $counter2[$g] <> 3 and $counter2[$g] <> 4 Then ExitLoop
;~                  MsgBox(0,$num[$v],$counter2[$g] & "  " & $counter2 [$g +1] & "  " & $counter2[$g +2] & "  " & $counter2[$g + 3])
                Next
                $v -= 1
                For $u = 1 to $v
                    if $u = 1 then
                        GUICtrlSetData($upc,$num[$u])
                    Else
                        GUICtrlSetData($upc,guictrlread($upc) & $num[$u])
                    EndIf
                Next        
Dim $color[100000]
Dim $bar[1000]
dim $counter[1000]
dim $counter2[1000]
dim $num[1000]
$start = 0

If StringLen(guictrlread($upc)) < 12 And guictrlread($complete) <> "Scan Error" Then 
;~ MsgBox(0,"","here?")
    Call ("repeat")
EndIf
EndFunc
Func repeat()
;~ MsgBox(0,$t,StringLen(guictrlread($upc)))

    If $t = -3 Then
        
        GUICtrlSetData($complete,"Read Error")
    
Else
    $t -= 1
    Call ("start")

EndIf
    
EndFunc
If GUICtrlRead($complete) <> "Scan Error" And StringLen(GUICtrlRead($upc)) = 12 Then GUICtrlSetData($complete,"Completed")

EndSelect

        
WEnd
    Func scanerror()
        GUICtrlSetData($complete, "Scan Error")
        EndFunc
Edited by youknowwho4eva

Giggity

Link to comment
Share on other sites

Yea the error checking could be better, if you have bare code creator open you want to click in the white area to the left of the bar code, then click on the right side in the white as well. I did find last night it doesn't work 100% yet either. On the product I was testing with it does. If you use 07395404208 (check digit is 2 if you don't have the current version that calculates it for you) it reads it correctly. I'm going to check today if its all 10 digits that work or if any other digits work. But it is a big step in the right direction.

Edit: Okay, I made it so you can run it twice and it doesn't crash. But I still have the error of that it works with some codes but not others, and I believe its because of this line here

$count1 = StringLen(Stringleft($bar2,(stringinstr($bar2,"|1|1|1|0|0|0|1|1|1|0|0|0|1|1|1|"))+84))

I made it +84 so it would work with the above code, but I believe that is why its cutting the code wrong. I just don't know how to fix it... If anyone knows, let me know and I'll fix it up, untill then I'm going to pick it apart some more till I figure it out. Then I have to make it so it can read bar codes not made by my bar code maker. :mellow:

Edited by youknowwho4eva

Giggity

Link to comment
Share on other sites

Update: it reads bar code images now. I do need to make it so if a number is read 3212 then the only possibility is for it to be 3211 (0). So go to google images and search upc bar code. open the picture and scan it.

@ the saint, I have an idea for your scanner. Get a web cam, have it so it looks at the code, you hit a go button and it auto scans it. I think the modifications to do this could be pretty easy. I've done all the hard math stuff (God my head hurts now)

Edit: In my further testing I'm getting about 2 out of 3 success ratio

Another Edit: I just tried google images and not a one works... so I'm uploading images that work well at least the first 2 do.

Edited by youknowwho4eva

Giggity

Link to comment
Share on other sites

Ok, I tried and tried and I got it to about 99% IMO. Just make sure you pick a nice clean image. The only problem I ran into recently is that 7 = 1312, and 8 = 1213 but I think I fixed that. It now has a status label. It still crashes if you scan nothing. But other then that, it's working beutifully. Next I have to somehow make it so it doesn't crash, and add support for other bar code types.

Giggity

Link to comment
Share on other sites

Now I have the ITF (Interleaved 2 of 5) reader complete. UPC and ITF are all we use, so I don't plan on making support for others, but feel free to us my scripts to make the protocol of your choice.

UPC reader in original post

ITF reader:

#include <misc.au3>
#include <array.au3>
#include <GUIConstantsEx.au3>
#include <Math.au3>
#include <color.au3>
$t = 2
$r = 2
Dim $color[100000]
Dim $bar[1000]
dim $counter[1000]
dim $counter2[1000]
dim $num[1000]
dim $num2[1000]
$dll = DllOpen("user32.dll")
$start = 0
GUICreate("UPC Scanner",400,400)
GUICtrlCreateLabel("Once you click on start" & @LF & "Click once on the left of the bar code" & @LF & "And once on the right of the bar code.",20,20)
GUICtrlCreateLabel("ITF",20,80)
$upc = GUICtrlCreateInput("00000000000000000",20,100,200,20)
$go = GUICtrlCreateButton("Start",20,150,75,20)
$complete = GUICtrlCreateLabel("Proceed",20,180,200,20)
GUICtrlSetState($upc,$gui_disable)
GUICtrlSetBkColor($upc,0xffffff)
If $start = 1 Then $msg = $go

GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Select
    Case $msg = $gui_event_close
        Exit
    Case $msg = $go
        GUICtrlSetData($complete, "Proceed")
        GUICtrlSetData($upc,"")
        
        Sleep(100)
        Do
            Sleep(100)
            Until _IsPressed("01",$dll) = 1
    
        $mouse = MouseGetPos()
        $start = 1
        Sleep(200)
    
    Do
            Sleep(100)
            Until _IsPressed("01",$dll) = 1
    GUICtrlSetData($complete,"Processing Please Wait")
        $mouse2 = MouseGetPos()
        Call("start")
        Func start()
        $start = 0
        For $n = 1 to ($mouse2[0] - $mouse[0]) + 1
        $color = PixelGetColor($mouse[0] + $n,$mouse[1])
        
        $red = _colorgetred($color)
        If $red > 200 Then 
            $bar[$n] = 1
        ElseIf $red < 100 Then
            $bar[$n] = 0
        Else
            $bar[$n] = 2
        EndIf
    
        
        
    Next
    
;~  _ArrayDisplay($bar)
    $bar[0] = $n
    
;~      MsgBox(0,$bar[0],"hmmm")
;~  MsgBox(0,"",$bar[0])
    For $i = 1 to $bar[0]
        If $bar[$i] = 2 Then
            _ArrayDelete($bar,$i)
            $i -= 1
        EndIf
        Next
;~  _ArrayDisplay($bar)

    For $i = 1 to $bar[0]
        if $bar[1] <> 0 Then
            _ArrayDelete($bar,1)
        Else
            ExitLoop
        EndIf
    Next
    _ArrayReverse($bar)
    
    For $i = 0 to 1000000
        if $bar[0] <> "0" Then
            _ArrayDelete($bar,0)
;~          MsgBox(0,"", $i)
        Else
            ExitLoop
        EndIf
    Next
;~  _ArrayDisplay($bar)
    _ArrayReverse($bar)
;~      _ArrayDisplay($bar)
;~      If $bar[1] = 0 And $bar[2] = 0 And $bar[3] = 0 And $bar[4] = 1 And $bar[5] = 1 And $bar[6] = 1 And $bar[7] = 0 And $bar[8] = 0 And $bar[9] = 0 Then
;~      Else
;~          MsgBox(0,"","Read Error")
;~      EndIf
For $r = 2 to 100
    
        If $bar[$r] <> $bar[$r-1]Then
            ExitLoop
        EndIf
    
Next
;~ MsgBox(0,$t,$r)
$r = $r + $t
For $i = 1 to $bar[0]
        if $bar[1] = 0 Then
            _ArrayDelete($bar,1)
        Else
            ExitLoop
        EndIf
    Next
    
For $i = 1 to $bar[0]
        if $bar[1] = 1 Then
            _ArrayDelete($bar,1)
        Else
            ExitLoop
        EndIf
    Next
For $i = 1 to $bar[0]
        if $bar[1] = 0 Then
            _ArrayDelete($bar,1)
        Else
            ExitLoop
        EndIf
    Next
    For $i = 1 to $bar[0]
        if $bar[1] = 1 Then
            _ArrayDelete($bar,1)
        Else
            ExitLoop
        EndIf
    Next
    _ArrayReverse($bar)
    For $i = 0 to 10000
        if $bar[0] <> 1 Then
            _ArrayDelete($bar,0)
        Else
            ExitLoop
        EndIf
    Next
    For $i = 0 to 10000
        
        if $bar[0] = 1 Then
            _ArrayDelete($bar,0)
        Else
            ExitLoop
        EndIf
    Next
    For $i = 0 to 10000
        if $bar[0] <> 1 Then
            _ArrayDelete($bar,0)
        Else
            ExitLoop
        EndIf
    Next
    _ArrayReverse($bar)
;~  _ArrayDisplay($bar)
;~  $r -= 1
;~  MsgBox(0,"",$r)
_ArrayDelete($bar,0)
    $bar2 = _ArrayToString($bar)
;~  MsgBox(0,"",$bar2)
        For $e = 1 to 100
            If _MathCheckDiv($e,2) = 1 Then
            $count = stringlen(StringLeft($bar2,(stringinstr($bar2,1))-1)) / 2
            $realcount = $count
;~          MsgBox(0,$r,$realcount)
            If _MathCheckDiv($count,$r) = 1 Then
                $count += 1
;~              MsgBox(0,"here1",$count)
                If _MathCheckDiv($count,$r) = 1 Then
                    $count -= 2
;~                  MsgBox(0,"here2",$count)
                    If _MathCheckDiv($count,$r) = 1 Then
                        $count -= 1
                EndIf
            EndIf
            EndIf
            
            $count = $count / $r
        Else
            $count = stringlen(StringLeft($bar2,(stringinstr($bar2,0))-1)) / 2
            $realcount = $count
            
;~          MsgBox(0,"",$realcount)
            If _MathCheckDiv($count,$r) = 1 Then
                $count += 1
                If _MathCheckDiv($count,$r) = 1 Then
                    $count -= 2
                    If _MathCheckDiv($count,$r) = 1 Then
                        $count -= 1
                EndIf
            EndIf
            EndIf
            $count = $count / $r
            
            EndIf

        If $count = 1 Then
            $counter[$e] = 1
        ElseIf $count = 2 Then
            $counter[$e] = 1
        ElseIf $count = 3 Then
            $counter[$e] = 4
        ElseIf $count = 4 Then
            $counter[$e] = 4
        Else
            $counter[$e] = StringLen($bar2) / $r / 2
            If $counter[$e] < 2 Then
                $counter[$e] = 1
            Else
                $counter[$e] = 4
            EndIf
            
;~          MsgBox(0,"",$counter[$e])
            ExitLoop
            EndIf
            
            $bar2 = StringTrimLeft($bar2,$realcount * 2)
;~          MsgBox(0,$e,$counter[$e] & @lf & $bar2)
        Next
        For $w = 1 to 100
            If StringLen($counter[$w]) <> 1 then ExitLoop
            Next
            $v = 0
            For $g = 1 to $w + 1 step +10
                $v += 1
                If $counter[$g] = 1 and $counter[$g + 2] = 1 and $counter[$g + 4] = 4 and $counter[$g + 6] = 4 and $counter[$g + 8] = 1 Then $num[$v] = 0
                If $counter[$g] = 4 and $counter[$g + 2] = 1 and $counter[$g + 4] = 1 and $counter[$g + 6] = 1 and $counter[$g + 8] = 4 Then $num[$v] = 1
                If $counter[$g] = 1 and $counter[$g + 2] = 4 and $counter[$g + 4] = 1 and $counter[$g + 6] = 1 and $counter[$g + 8] = 4 Then $num[$v] = 2
                If $counter[$g] = 4 and $counter[$g + 2] = 4 and $counter[$g + 4] = 1 and $counter[$g + 6] = 1 and $counter[$g + 8] = 1 Then $num[$v] = 3
                If $counter[$g] = 1 and $counter[$g + 2] = 1 and $counter[$g + 4] = 4 and $counter[$g + 6] = 1 and $counter[$g + 8] = 4 Then $num[$v] = 4
                If $counter[$g] = 4 and $counter[$g + 2] = 1 and $counter[$g + 4] = 4 and $counter[$g + 6] = 1 and $counter[$g + 8] = 1 Then $num[$v] = 5
                If $counter[$g] = 1 and $counter[$g + 2] = 4 and $counter[$g + 4] = 4 and $counter[$g + 6] = 1 and $counter[$g + 8] = 1 Then $num[$v] = 6
                If $counter[$g] = 1 and $counter[$g + 2] = 1 and $counter[$g + 4] = 1 and $counter[$g + 6] = 4 and $counter[$g + 8] = 4 Then $num[$v] = 7
                If $counter[$g] = 4 and $counter[$g + 2] = 1 and $counter[$g + 4] = 1 and $counter[$g + 6] = 4 and $counter[$g + 8] = 1 Then $num[$v] = 8
                If $counter[$g] = 1 and $counter[$g + 2] = 4 and $counter[$g + 4] = 1 and $counter[$g + 6] = 4 and $counter[$g + 8] = 1 Then $num[$v] = 9
;~                  MsgBox(0,$num[$v],$counter[$g] & "  " & $counter[$g +2] & "  " & $counter[$g +4] & "  " & $counter[$g + 6] & "  " & $counter[$g + 8])
                Next
                $v = 0
                For $g = 1 to $w + 1 step +10
                $v += 1
                If $counter[$g + 1] = 1 and $counter[$g + 3] = 1 and $counter[$g + 5] = 4 and $counter[$g + 7] = 4 and $counter[$g + 9] = 1 Then $num2[$v] = 0
                If $counter[$g + 1] = 4 and $counter[$g + 3] = 1 and $counter[$g + 5] = 1 and $counter[$g + 7] = 1 and $counter[$g + 9] = 4 Then $num2[$v] = 1
                If $counter[$g + 1] = 1 and $counter[$g + 3] = 4 and $counter[$g + 5] = 1 and $counter[$g + 7] = 1 and $counter[$g + 9] = 4 Then $num2[$v] = 2
                If $counter[$g + 1] = 4 and $counter[$g + 3] = 4 and $counter[$g + 5] = 1 and $counter[$g + 7] = 1 and $counter[$g + 9] = 1 Then $num2[$v] = 3
                If $counter[$g + 1] = 1 and $counter[$g + 3] = 1 and $counter[$g + 5] = 4 and $counter[$g + 7] = 1 and $counter[$g + 9] = 4 Then $num2[$v] = 4
                If $counter[$g + 1] = 4 and $counter[$g + 3] = 1 and $counter[$g + 5] = 4 and $counter[$g + 7] = 1 and $counter[$g + 9] = 1 Then $num2[$v] = 5
                If $counter[$g + 1] = 1 and $counter[$g + 3] = 4 and $counter[$g + 5] = 4 and $counter[$g + 7] = 1 and $counter[$g + 9] = 1 Then $num2[$v] = 6
                If $counter[$g + 1] = 1 and $counter[$g + 3] = 1 and $counter[$g + 5] = 1 and $counter[$g + 7] = 4 and $counter[$g + 9] = 4 Then $num2[$v] = 7
                If $counter[$g + 1] = 4 and $counter[$g + 3] = 1 and $counter[$g + 5] = 1 and $counter[$g + 7] = 4 and $counter[$g + 9] = 1 Then $num2[$v] = 8
                If $counter[$g + 1] = 1 and $counter[$g + 3] = 4 and $counter[$g + 5] = 1 and $counter[$g + 7] = 4 and $counter[$g + 9] = 1 Then $num2[$v] = 9
;~                  MsgBox(0,$num2[$v],$counter[$g + 1] & "  " & $counter[$g +3] & "  " & $counter[$g + 5] & "  " & $counter[$g + 7] & "  " & $counter[$g + 9])
                Next
;~              MsgBox(0,"", $num[1] & "  " & $num2[1] & "  " & $num2[2] & "  " & $num2[2] & "  " & $num2[3] & "  " & $num2[3] & "  " & $num2[4] & "  " & $num2[4] & "  " & $num2[5] & "  " & $num2[5])
                $v -= 1
                For $u = 1 to $v
                    if $u = 1 then
                        GUICtrlSetData($upc,$num[$u])
                        GUICtrlSetData($upc,guictrlread($upc) & $num2[$u])
                    Else
                        GUICtrlSetData($upc,guictrlread($upc) & $num[$u])
                        GUICtrlSetData($upc,guictrlread($upc) & $num2[$u])
                        
                    EndIf
                Next        
Dim $color[100000]
Dim $bar[1000]
dim $counter[1000]
dim $counter2[1000]
dim $num[1000]
dim $num2[1000]
$start = 0

If StringLen(guictrlread($upc)) < 12 And guictrlread($complete) <> "Scan Error" Then 
;~ MsgBox(0,"","here?")
    Call ("repeat")
EndIf
EndFunc
Func repeat()
;~ MsgBox(0,$t,StringLen(guictrlread($upc)))

    If $t = -3 Then
        
        GUICtrlSetData($complete,"Read Error")
        GUICtrlSetData($upc,"Error")
    
Else
    $t -= 1
    Call ("start")

EndIf
    
EndFunc
If GUICtrlRead($complete) <> "Scan Error" And StringLen(GUICtrlRead($upc)) > 12 Then GUICtrlSetData($complete,"Completed")

EndSelect

        
WEnd
    Func scanerror()
        GUICtrlSetData($complete, "Scan Error")
        EndFunc

Giggity

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...