1#!/usr/bin/env python
2#-----------------------------------------------------------------------------
3# de2120_ex2_serial_settings.py
4#------------------------------------------------------------------------
5#
6# Written by Priyanka Makin @ SparkFun Electronics, April 2021
7#
8# This example demonstrates how to configure the settings of the DE2120 Breakout
9#
10# NOTE: you must put the module into COM mode by scanning the PORVIC barcode
11# in the datasheet. This will put the module in the correct mode to receive
12# and transmit serial.
13#
14# This package has been developed on a Raspberry Pi 4. Connect the DE2120 Barcode
15# Scanner Breakout directly to your Pi using a USB-C cable
16#
17# Do you like this library? Help support SparkFun. Buy a board!
18#
19#==================================================================================
20# Copyright (c) 2021 SparkFun Electronics
21#
22# Permission is hereby granted, free of charge, to any person obtaining a copy
23# of this software and associated documentation files (the "Software"), to deal
24# in the Software without restriction, including without limitation the rights
25# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
26# copies of the Software, and to permit persons to whom the Software is
27# furnished to do so, subject to the following conditions:
28#
29# The above copyright notice and this permission notice shall be included in all
30# copies or substantial portions of the Software.
31#
32# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38# SOFTWARE.
39#==================================================================================
40# Example 2
41
42from __future__ import print_function
43import de2120_barcode_scanner
44import time
45import sys
46import serial
47
48def flash_light(bar_scanner):
49 print("\n")
50 print("\n------------------------------------------------")
51 print("\n1) Enable flash light")
52 print("\n2) Disable flash light")
53 print("\n------------------------------------------------")
54
55 val = input("\nSelect an option number: ")
56
57 if val == '1':
58 print("\nWhite scan light on")
59 bar_scanner.light_on()
60 elif val == '2':
61 print("\nWhite scan light off")
62 bar_scanner.light_off()
63 else:
64 print("\nCommand not recognized")
65
66def reticle(bar_scanner):
67 print("\n")
68 print("\n------------------------------------------------")
69 print("\n1) Enable reticle")
70 print("\n2) Disable reticle")
71 print("\n------------------------------------------------")
72
73 val = input("\nSelect an option number: ")
74
75 if val == '1':
76 print("\nRed scan reticle on")
77 bar_scanner.reticle_on()
78 elif val == '2':
79 print("\nRed scan reticle off")
80 bar_scanner.reticle_off()
81 else:
82 print("\nCommand not recognized")
83
84def decode_beep(bar_scanner):
85 print("\n")
86 print("\n------------------------------------------------")
87 print("\n1) Enable decode beep")
88 print("\n2) Disable decode beep")
89 print("\n------------------------------------------------")
90
91 val = input("\nSelect an option number: ")
92
93 if val == '1':
94 print("\nDecode beep turned on")
95 bar_scanner.enable_decode_beep()
96 elif val == '2':
97 print("\nDecode beep turned off")
98 bar_scanner.disable_decode_beep()
99 else:
100 print("\nCommand not recognized")
101
102def boot_beep(bar_scanner):
103 print("\n")
104 print("\n------------------------------------------------")
105 print("\n1) Enable beep on module power on")
106 print("\n2) Disable beep on module power off")
107 print("\n------------------------------------------------")
108
109 val = input("\nSelect an option number: ")
110
111 if val == '1':
112 print("\nBeep on power on enabled")
113 bar_scanner.enable_boot_beep()
114 elif val == '2':
115 print("\nBeep on power on disabled")
116 bar_scanner.disable_boot_beep()
117 else:
118 print("\nCommand not recognized")
119
120def change_buzz_freq(bar_scanner):
121 print("\n")
122 print("\n------------------------------------------------")
123 print("\n1) Passive low frequency")
124 print("\n2) Passive medium frequency")
125 print("\n3) Passive high frequency")
126
127 val = input("\nSelect an option number: ")
128
129 if val == '1':
130 bar_scanner.change_buzzer_tone(int(val))
131 elif val == '2':
132 bar_scanner.change_buzzer_tone(int(val))
133 elif val == '3':
134 bar_scanner.change_buzzer_tone(int(val))
135 else:
136 print("\nCommand not recognized")
137
138def image_flip(bar_scanner):
139 print("\n")
140 print("\n------------------------------------------------")
141 print("\n1) Turn on image flipping")
142 print("\n2) Turn off image flipping (default)")
143 print("\n------------------------------------------------")
144
145 val = input("\nSelect an option number: ")
146
147 if val == '1':
148 bar_scanner.enable_image_flipping()
149 elif val == '2':
150 bar_scanner.disable_image_flipping()
151 else:
152 print("\nCommand not recognized")
153def reading_area(bar_scanner):
154 print("\n")
155 print("\n------------------------------------------------")
156 print("\n1) Full width (default)")
157 print("\n2) Center 80%")
158 print("\n3) Center 60%")
159 print("\n4) Center 40%")
160 print("\n5) Center 20%")
161 print("\n------------------------------------------------")
162
163 val = input("\nSelect an option number: ")
164
165 if val == '1':
166 print("\nScanning 100% of frame")
167 bar_scanner.change_reading_area(100)
168 elif val == '2':
169 print("\nScanning center 80% of frame")
170 bar_scanner.change_reading_area(80)
171 elif val == '3':
172 print("\nScanning center 60% of frame")
173 bar_scanner.change_reading_area(60)
174 elif val == '4':
175 print("\nScanning center 40% of frame")
176 bar_scanner.change_reading_area(40)
177 elif val == '5':
178 print("\nScanning center 20% of frame")
179 bar_scanner.change_reading_area(20)
180 else:
181 print("\nCommand not recognized")
182
183def reading_mode(bar_scanner):
184 print("\n")
185 print("\n------------------------------------------------")
186 print("\n1) Manual read mode (default)")
187 print("\n2) Continuous read mode")
188 print("\n3) Motion sensor mode")
189 print("\n------------------------------------------------")
190
191 val = input("\nSelect an option number: ")
192
193 if val == '1':
194 print("\nManual trigger mode enabled")
195 bar_scanner.enable_manual_trigger()
196 elif val == '2':
197 print("\nContinuous read mode enabled")
198 bar_scanner.enable_continuous_read(1)
199 elif val == '3':
200 print("\nMotion trigger mode enabled")
201 bar_scanner.enable_motion_sense()
202 else:
203 print("\nCommand not recognized")
204
205def symbologies(bar_scanner):
206 print("\n")
207 print("\n------------------------------------------------")
208 print("\n1) Enable all 1D symbologies")
209 print("\n2) Disable all 1D symbologies")
210 print("\n3) Enable all 2D symbologies")
211 print("\n4) Disable all 2D symbologies")
212 print("\n------------------------------------------------")
213
214 val = input("\nSelect an option number: ")
215
216 if val == '1':
217 print("\n1D symbologies enabled")
218 bar_scanner.enable_all_1D()
219 elif val == '2':
220 print("\n1D symbologies disabled")
221 bar_scanner.disable_all_1D()
222 elif val == '3':
223 print("\n2D symbologies enabled")
224 bar_scanner.enable_all_2D()
225 elif val == '4':
226 print("\n2D symbologies disabled")
227 bar_scanner.disable_all_2D()
228 else:
229 print("\nCommand not recognized")
230
231def run_example():
232
233 print("\nSparkFun DE2120 Barcode Scanner Breakout Example 2")
234 my_scanner = de2120_barcode_scanner.DE2120BarcodeScanner()
235
236 if my_scanner.begin() == False:
237 print("\nThe Barcode Scanner module isn't connected correctly to the system. Please check wiring", \
238 file=sys.stderr)
239 return
240 print("\nScanner ready!")
241
242 while True:
243
244 print("\n")
245 print("\nSparkFun DE2120 Barcode Scanner Python Package")
246 print("\n------------------------------------------------")
247 print("\n1) Start Scan")
248 print("\n2) Stop Scan")
249 print("\n3) Enable/Disable Flashlight")
250 print("\n4) Enable/Disable Aiming Reticle")
251 print("\n5) Enable/Disable Decode Beep")
252 print("\n6) Enable/Disable Start Up Beep")
253 print("\n7) Change Buzzer Frequency")
254 print("\n8) Enablde/Disable Image Flipping")
255 print("\n9) Set Reading Area")
256 print("\n10) Set Reading Mode")
257 print("\n11) Enable/Disable Symbologies")
258 print("\n------------------------------------------------")
259
260 val = input("\nSelect an option number: ")
261
262 if val == '1':
263 my_scanner.start_scan()
264 elif val == '2':
265 my_scanner.stop_scan()
266 elif val == '3':
267 flash_light(my_scanner)
268 elif val == '4':
269 reticle(my_scanner)
270 elif val == '5':
271 decode_beep(my_scanner)
272 elif val == '6':
273 boot_beep(my_scanner)
274 elif val == '7':
275 change_buzz_freq(my_scanner)
276 elif val == '8':
277 image_flip(my_scanner)
278 elif val == '9':
279 reading_area(my_scanner)
280 elif val == '10':
281 reading_mode(my_scanner)
282 elif val == '11':
283 symbologies(my_scanner)
284 else:
285 print("\nCommand not recognized")
286
287if __name__ == '__main__':
288 try:
289 run_example()
290 except (KeyboardInterrupt, SystemExit) as exErr:
291 print("\nEnding Example 2")
292 sys.exit(0)