找回密码
 加入
搜索
查看: 3208|回复: 9

[效率算法] 已解决 AU3条码生成器的条码无法识别

  [复制链接]
发表于 2016-6-15 22:45:55 | 显示全部楼层 |阅读模式
本帖最后由 风过无痕 于 2017-12-20 16:16 编辑
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <array.au3>
#include <file.au3>
#include <GUIConstantsEx.au3>
#include <ScreenCapture.au3>

#NoTrayIcon
Global $array[104]
Global $CodeArray
Global $data
Global $L[1]

;*************************************************************************************
; Assign Code 128 Pattern array
;*************************************************************************************
; Items are "[Value]?[Bcode]?[Ccode]?[1/0 Pattern]"

$array[1] = "0? ?00?11011001100"
$array[2] = "1?!?01?11001101100"
$array[3] = '2?"?02?11001100110'
$array[4] = "3?#?03?10010011000"
$array[5] = "4?$?04?10010001100"
$array[6] = "5?%?05?10001001100"
$array[7] = "6?&?06?10011001000"
$array[8] = "7?'?07?10011000100"
$array[9] = "8?(?08?10001100100"
$array[10] = "9?)?09?11001001000"
$array[11] = "10?*?10?11001000100"
$array[12] = "11?+?11?11000100100"
$array[13] = "12?,?12?10110011100"
$array[14] = "13?-?13?10011011100"
$array[15] = "14?.?14?10011001110"
$array[16] = "15?/?15?10111001100"
$array[17] = "16?0?16?10011101100"
$array[18] = "17?1?17?10011100110"
$array[19] = "18?2?18?11001110010"
$array[20] = "19?3?19?11001011100"
$array[21] = "20?4?20?11001001110"
$array[22] = "21?5?21?11011100100"
$array[23] = "22?6?22?11001110100"
$array[24] = "23?7?23?11101101110"
$array[25] = "24?8?24?11101001100"
$array[26] = "25?9?25?11100101100"
$array[27] = "26?:?26?11100100110"
$array[28] = "27?;?27?11101100100"
$array[29] = "28?<?28?11100110100"
$array[30] = "29?=?29?11100110010"
$array[31] = "30?>?30?11011011000"
$array[32] = "31???31?11011000110"
$array[33] = "32?@?32?11000110110"
$array[34] = "33?A?33?10100011000"
$array[35] = "34?B?34?10001011000"
$array[36] = "35?C?35?10001000110"
$array[37] = "36?D?36?10110001000"
$array[38] = "37?E?37?10001101000"
$array[39] = "38?F?38?10001100010"
$array[40] = "39?G?39?11010001000"
$array[41] = "40?H?40?11000101000"
$array[42] = "41?I?41?11000100010"
$array[43] = "42?J?42?10110111000"
$array[44] = "43?K?43?10110001110"
$array[45] = "44?L?44?10001101110"
$array[46] = "45?M?45?10111011000"
$array[47] = "46?N?46?10111000110"
$array[48] = "47?O?47?10001110110"
$array[49] = "48?P?48?11101110110"
$array[50] = "49?Q?49?11010001110"
$array[51] = "50?R?50?11000101110"
$array[52] = "51?S?51?11011101000"
$array[53] = "52?T?52?11011100010"
$array[54] = "53?U?53?11011101110"
$array[55] = "54?V?54?11101011000"
$array[56] = "55?W?55?11101000110"
$array[57] = "56?X?56?11100010110"
$array[58] = "57?Y?57?11101101000"
$array[59] = "58?Z?58?11101100010"
$array[60] = "59?[?59?11100011010"
$array[61] = "60?\?60?11101111010"
$array[62] = "61?]?61?11001000010"
$array[63] = "62?^?62?11110001010"
$array[64] = "63?_?63?10100110000"
$array[65] = "64?`?64?10100001100"
$array[66] = "65?a?65?10010110000"
$array[67] = "66?b?66?10010000110"
$array[68] = "67?c?67?10000101100"
$array[69] = "68?d?68?10000100110"
$array[70] = "69?e?69?10110010000"
$array[71] = "70?f?70?10110000100"
$array[72] = "71?g?71?10011010000"
$array[73] = "72?h?72?10011000010"
$array[74] = "73?i?73?10000110100"
$array[75] = "74?j?74?10000110010"
$array[76] = "75?k?75?11000010010"
$array[77] = "76?l?76?11001010000"
$array[78] = "77?m?77?11110111010"
$array[79] = "78?n?78?11000010100"
$array[80] = "79?o?79?10001111010"
$array[81] = "80?p?80?10100111100"
$array[82] = "81?q?81?10010111100"
$array[83] = "82?r?82?10010011110"
$array[84] = "83?s?83?10111100100"
$array[85] = "84?t?84?10011110100"
$array[86] = "85?u?85?10011110010"
$array[87] = "86?v?86?11110100100"
$array[88] = "87?w?87?11110010100"
$array[89] = "88?x?88?11110010010"
$array[90] = "89?y?89?11011011110"
$array[91] = "90?z?90?11011110110"
$array[92] = "91?{?91?11110110110"
$array[93] = "92?|?92?10101111000"
$array[94] = "93?}?93?10100011110"
$array[95] = "94?~?94?10001011110"
$array[96] = "95?del?95?10111101000"
$array[97] = "96?Fnc3?96?10111100010"
$array[98] = "97?Fnc2?97?11110101000"
$array[99] = "98?Shift?98?11110100010"
$array[100] = "99?Code C?99?10111011110"
$array[101] = "100?Fnc 4?Code B?10111101110"
$array[102] = "101?Code A?Code A?11101011110"
$array[103] = "102?Fnc 1?Fnc 1?11110101110"

$Form1 = GUICreate("条码生成工具", 405, 360, -1, -1,BitOR($WS_MINIMIZEBOX,$WS_GROUP))
$Group1 = GUICtrlCreateGroup("", 8, 5, 385, 285)
$Label1 = GUICtrlCreateLabel("订货通知编号", 40, 43, 76, 17)
$Input1 = GUICtrlCreateInput("", 122, 40, 233, 21, 0x2000 & 0x0008)
$Label2 = GUICtrlCreateLabel("订货审批单号", 40, 77, 76, 17)
$Input2 = GUICtrlCreateInput("", 122, 72, 233, 21)
$Label3 = GUICtrlCreateLabel("门   店   号", 40, 109, 76, 17)
$Input3 = GUICtrlCreateCombo("", 122, 104, 233, 21)
GUICtrlSetData(-1,"9143|9101|","9101")
$Label4 = GUICtrlCreateLabel("门   店   名", 40, 141, 76, 17)
$Input4 = GUICtrlCreateCombo("", 122, 136, 233, 21)
GUICtrlSetData(-1,"2233|121","")
$Label5 = GUICtrlCreateLabel("箱   码   号", 40, 173, 76, 17)
$Input5 = GUICtrlCreateCombo("", 122, 168, 81, 21)
GUICtrlSetData(-1,"1|2|","1")
$Label6 = GUICtrlCreateLabel("  UPI  码", 40, 205, 76, 17)
$Input6 = GUICtrlCreateInput("", 122, 200, 233, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("生成条码", 55, 300, 80, 30)
$Button2 = GUICtrlCreateButton("打印条码", 170, 300, 80, 30)
$Button3 = GUICtrlCreateButton("退出", 285, 300, 80, 30)
GUISetState(@SW_SHOW)

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $Button1
                        MakeBarcode()
                Case $Button2
                        print()
                Case $Button3
                        close()
        EndSwitch
WEnd

Func print()
        Run('Rundll32.exe "' & @SystemDir & '\mshtml.dll",PrintHTML "' & @TempDir & "\Barcode.jpg" & '"', @SystemDir)
EndFunc   ;==>print

Func close()
        Exit
EndFunc   ;==>close

Func MakeBarcode()
    Local $hGUI
        For $i = 1 To (UBound($L) - 1)
                GUICtrlDelete($L[$i])
        Next
        $Barcode = IdentifyCodeSwitches(GUICtrlRead($Input6))
        Dim $L[StringLen($Barcode) + 1]
        $i = 1
        While $i <= StringLen($Barcode)
                $col = StringMid($Barcode, $i, 1)
                If $col = 1 Then
                        $L[$i] = GUICtrlCreateLabel("", 20 + ($i * 2), 230, 2, 50)
                        GUICtrlSetBkColor(-1, 0x000000)
                Else
                        $L[$i] = GUICtrlCreateLabel("", 20 + ($i * 2), 230, 2, 50)
                        GUICtrlSetBkColor(-1, 0xFFFFFF)
                EndIf
                $i += 1
        WEnd
        _ScreenCapture_CaptureWnd (@TempDir & "\Barcode.jpg", $hGui,8,28,398,315)
EndFunc   ;==>MakeBarcode

Func IdentifyCodeSwitches($code)

        $i = 1
        $CodeType = "B"
        $len = StringLen($code)

        While $i <= $len
                Select
                        Case $CodeType = "B"
                                If StringRegExp(StringMid($code, $i, 6), "([0-9][0-9]){3}") = 1 Then
                                        $code = StringMid($code, 1, $i - 1) & "?C?" & StringMid($code, $i)
                                        $CodeType = "C"
                                        $i += 6 + 3
                                Else
                                        $CodeType = "B"
                                        $i += 1
                                EndIf
                        Case $CodeType = "C"
                                If StringRegExp(StringMid($code, $i, 2), "([0-9][0-9])") <> 1 Then
                                        $code = StringMid($code, 1, $i - 1) & "?B?" & StringMid($code, $i)
                                        $CodeType = "B"
                                        $i += 2 + 3
                                Else
                                        $CodeType = "C"
                                        $i += 2
                                EndIf
                EndSelect
                $len = StringLen($code)
        WEnd

        If StringMid($code, 1, 3) <> "?C?" Then $code = "?B?" & $code

        $CodeArray = StringSplit($code, "")

        For $i = 1 To (UBound($CodeArray) - 3)

                Select
                        Case $CodeArray[$i] & $CodeArray[$i + 1] & $CodeArray[$i + 2] = "?B?"
                                $CodeArray[$i] = "[B]"
                                $CodeArray[$i + 1] = ""
                                $CodeArray[$i + 2] = ""

                        Case $CodeArray[$i] & $CodeArray[$i + 1] & $CodeArray[$i + 2] = "?C?"
                                $CodeArray[$i] = "[C]"
                                $CodeArray[$i + 1] = ""
                                $CodeArray[$i + 2] = ""
                EndSelect
        Next

        For $i = (UBound($CodeArray) - 1) To 1 Step -1
                If $CodeArray[$i] = "" Then _ArrayDelete($CodeArray, $i)
        Next

        $i = 1

        While $i <= (UBound($CodeArray) - 1)
                If $CodeArray[$i] = "[C]" Then
                        $i += 1
                        Do
                                If $CodeArray[$i] = "" Then
                                        $i += 1
                                Else
                                        $CodeArray[$i] &= $CodeArray[$i + 1]
                                        $CodeArray[$i + 1] = ""
                                        $i += 1

                                EndIf
                        Until $i = (UBound($CodeArray) - 1) Or $CodeArray[$i] = "[B]" Or $CodeArray[$i + 1] = "[B]"
                EndIf
                $i += 1
        WEnd

        For $i = (UBound($CodeArray) - 1) To 1 Step -1
                If $CodeArray[$i] = "" Then _ArrayDelete($CodeArray, $i)
        Next

        _ArrayDelete($CodeArray, 0) ;important

        If $CodeArray[0] = "[B]" Then
                $CodeArray[0] = "11010010000"
                $SUM = 104
                $CodeType = "[B]"
        Else
                $CodeArray[0] = "11010011100"
                $SUM = 105
                $CodeType = "[C]"
        EndIf

        For $i = 1 To (UBound($CodeArray) - 1)

                If $CodeArray[$i] = "[B]" Then
                        $CodeArray[$i] = "10111101110"
                        $SUM += $i * 100
                        $CodeType = "[B]"
                        ContinueLoop
                EndIf

                If $CodeArray[$i] = "[C]" Then
                        $CodeArray[$i] = "10111011110"
                        $SUM += $i * 99
                        $CodeType = "[C]"
                        ContinueLoop
                EndIf

                For $j = 1 To (UBound($array) - 1)

                        $data = StringSplit($array[$j], "?")

                        Select
                                Case $CodeType = "[B]"

                                        If $CodeArray[$i] == $data[2] Then
                                                $CodeArray[$i] = $data[4]
                                                $SUM += $i * $data[1]

                                        EndIf

                                Case $CodeType = "[C]"

                                        If $CodeArray[$i] == $data[3] Then
                                                $CodeArray[$i] = $data[4]
                                                $SUM += $i * $data[1]

                                        EndIf
                        EndSelect
                Next
        Next

        $ChecksumItem = Mod($SUM, 103)
        $data = StringSplit($array[$ChecksumItem + 1], "?")
        _ArrayAdd($CodeArray, $data[4])
        _ArrayAdd($CodeArray, "1100011101011")
        $CodeArrayString = _ArrayToString($CodeArray, "")
        Return $CodeArrayString
EndFunc   ;==>IdentifyCodeSwitches
SOSO1606111906293231
SOSO1606111759521013

生成的这两个条码无法识别


SOSO1606111804163759
这个就可以

可以看一下 生成的条码长度不一样  短的那个确实是识别不了

不知道是什么原因 如下图所示

大家都能识别,估计是我这边的问题

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2016-6-16 08:28:29 | 显示全部楼层
经测试能识别
发表于 2016-6-16 09:40:22 | 显示全部楼层
回复 1# 风过无痕
SOSO1606111906293231
SOSO16061119062932
我用18位数生成,都能读取。
发表于 2016-6-16 10:14:02 | 显示全部楼层
回复收藏本帖!
 楼主| 发表于 2016-6-16 10:19:14 | 显示全部楼层
回复 3# chzj589
我要的是全部数字生成的条码 但是这两个不知道是什么原因 手机无法识别 扫描器也无法识别 郁闷了
 楼主| 发表于 2016-6-16 10:19:49 | 显示全部楼层
回复 2# haijie1223
又上传了两张图 可以测试下  但是这两个不知道是什么原因 手机无法识别 扫描器也无法识别
发表于 2016-6-16 10:51:54 | 显示全部楼层
回复 5# 风过无痕
我用手机测试扫描包装盒子上有20位数字的条码无法读取,
可能手机扫描读取软件的问题
发表于 2016-6-16 11:44:15 | 显示全部楼层
回复 6# 风过无痕


    都可以读取
发表于 2016-6-24 17:16:50 | 显示全部楼层
手机的问题吧.
发表于 2016-6-25 23:24:02 | 显示全部楼层
可以的
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-12-26 01:11 , Processed in 0.108938 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表