Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

How to use Barcode scanner ?

Hey HF community .. I have this problem , I want to scan the products with Bar code scanner To record them in database
so I can later sell them through there Barcode .

[sum : ]

I want to Know how can I use bar code scanner with my application ?

it's very Important , Please Help me 😭 ..
you dont need any specific snippet or dll for doing this, barcode scanner itself will return the output as string , if scanner is attached to the pc. You can check the scanner by open a notepad and scan any barcode the text will appers in notepad.

You need to set product code or batch as particular barcode of that product in databse, then you can pick the particular product from database by searching the barcode with query
(Jun 6, 2018 05:46 AM)Moe_Sharp Wrote:  Hey HF community .. I have this problem , I want to scan the products with Bar code scanner To record them in database
so I can later sell them through there Barcode .

[sum : ]

I want to Know how can I use bar code scanner with my application ?

it's very Important , Please Help me  😭 ..

hey man you need to use a barcode api, i've found a free one on the internet you can use https://archive.codeplex.com/?p=freebarcode

hope this helps.

🤝
Mostly new devices like magnetic card scanner,barcode scanner they connect via usb and are treated like HID(Human interface device) or roughly as a keyboard ,who perform two operations during reading card value or barcode value.

1)The first operation is reading and returning output as string
2)Sending an key event,It's mostly enter key ()

So now you should have a wider picture of their implementation in your software,and your final solution would be next:

1)Define the control that is to receive the output of magnetic card or barcode scanner as an input
2)Do not let that control lose keyboard focus at any moment
3)Do a HID key filtering for numbers or letters in your case for numbers
4)Do a HID enter key filtering and rise logic for submit in order to save record in the database

a simple solution would be:

[Image: USrN5GA.gif]

xaml
Code
<Window x:Class="MainWindow"
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
       xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
       xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
       xmlns:local="clr-namespace:hidtest"
       mc:Ignorable="d"
       Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded" WindowStartupLocation="CenterScreen" >
   <Grid>
       <StackPanel Margin="20" Width="300">
           <TextBlock Text="Barcode or magnetic card input: "/>
           <TextBox x:Name="BarcodeOrCardInput"  Height="20" KeyDown="BarcodeOrCardInput_KeyDown" LostKeyboardFocus="BarcodeOrCardInput_LostKeyboardFocus" />
           <Button x:Name="btnSubmit" Content="Submit" Margin="5" Click="btnSubmit_Click"/>
       </StackPanel>
   </Grid>
</Window>

code
Code
Class MainWindow
   Inherits Window

   Public Sub New()
       InitializeComponent()
   End Sub



   Private Sub BarcodeOrCardInput_KeyDown(sender As Object, e As KeyEventArgs)
       Dim key = CType(e.Key, System.Windows.Input.Key)
       e.Handled = Not (key >= System.Windows.Input.Key.D0 AndAlso key <= System.Windows.Input.Key.D9 OrElse key >= System.Windows.Input.Key.NumPad0 AndAlso key <= System.Windows.Input.Key.NumPad9 OrElse key = System.Windows.Input.Key.Back OrElse key = System.Windows.Input.Key.OemPeriod OrElse key = System.Windows.Input.Key.Decimal OrElse key = System.Windows.Input.Key.Tab OrElse key = System.Windows.Input.Key.F1 OrElse key = System.Windows.Input.Key.F2 OrElse key = System.Windows.Input.Key.F3 OrElse key = System.Windows.Input.Key.F4)

       If e.Key = Key.Enter Then
           Me.btnSubmit.[RaiseEvent](New RoutedEventArgs(Button.ClickEvent))
           BarcodeOrCardInput.Text = String.Empty
           Keyboard.Focus(BarcodeOrCardInput)
       End If
   End Sub

   Private Sub btnSubmit_Click(sender As Object, e As RoutedEventArgs)
       MessageBox.Show("record is saved in db")
   End Sub

   Private Sub BarcodeOrCardInput_LostKeyboardFocus(sender As Object, e As KeyboardFocusChangedEventArgs)
       Keyboard.Focus(BarcodeOrCardInput)
   End Sub

   Private Sub Window_Loaded(sender As Object, e As RoutedEventArgs)
       Keyboard.Focus(BarcodeOrCardInput)
   End Sub
End Class

if you need a different way of implementation you must use one of barcode api to achieve the goal
buy me a coffee eth:0x88621A52aa5Eb3b6503628369687111810186c58
IT works Just like a keyboard Bro , No special code needed !!
(Jun 7, 2018 04:37 AM)PabloEscarNark Wrote:  hey man you need to use a barcode api, i've found a free one on the internet you can use https :// archive.codeplex.com/?p=freebarcode

hope this helps.

🤝

Thanks for the link bro , I Appreciate it  🤝 , I'll check it right away


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by basisJun 1, 2018 05:59 AM 9 790 Jun 1, 2018 05:59 AM
Last Post: Dalvik
[.NET] by musashixNov 20, 2017 02:27 AM 13 741 Nov 20, 2017 02:27 AM
Last Post: Earn
[.NET] by lost my mindJul 17, 2017 01:31 PM 7 188 Jul 17, 2017 01:31 PM
Last Post: Barret