logo
down
shadow

How to access USB barcode scanner data directly from USB port using C/C++ without driver


How to access USB barcode scanner data directly from USB port using C/C++ without driver

By : Pratik Mulye
Date : November 29 2020, 01:01 AM
I hope this helps . Most barcode scanners can work as simple usb-to-serial converters and thus you get a ttyusbx device in /dev. The way this usually works is you download some software or manual from the manufacturer's website and scan a barcode or a series of barcodes that put the device in this mode.
Even simpler, ALL barcode scanners should work as HID devices(keyboard)...again this requires downloading some sort of software or manual and scanning a couple barcodes.
code :


Share : facebook icon twitter icon
Reading a barcode using a USB barcode scanner along with ignoring keyboard data input while scanner product id and vendo

Reading a barcode using a USB barcode scanner along with ignoring keyboard data input while scanner product id and vendo


By : m88
Date : March 29 2020, 07:55 AM
help you fix your problem There is a way to differentiate between keyboard and USB barcode reader
You can depend on these facts:
code :
Public Class Form1

Dim BarcodeStr As String = ""
Dim IsBarcodeTaken As Boolean = False
Dim Str As String = ""
Dim str3 As String = ""


Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown

    If Timer1.Enabled = False Then
        Str = TextBox1.Text
        str3 = TextBox3.Text
    End If

End Sub

Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
    If Timer1.Enabled = False Then
        Timer1.Enabled = True
    End If


    BarcodeStr = BarcodeStr & e.KeyChar
    If Asc(e.KeyChar) = 13 And Len(BarcodeStr) >= 4 Then
        IsBarcodeTaken = True
        TextBox2.Text = BarcodeStr


    End If

End Sub
Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
    If IsBarcodeTaken = True Then
        TextBox1.Text = Str
        TextBox1.Select(Len(TextBox1.Text), 0)
        Str = ""

        TextBox3.Text = str3
        TextBox3.Select(Len(TextBox3.Text), 0)
        str3 = ""
    End If

End Sub


Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    BarcodeStr = ""
    IsBarcodeTaken = False
    Timer1.Enabled = False
End Sub


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    TextBox2.Text = ""

End Sub

End Class
Send data to a barcode scanner over RS232 serial port

Send data to a barcode scanner over RS232 serial port


By : krupakar
Date : March 29 2020, 07:55 AM
I wish this help you I have a bar-code scanner which is connecting through RS232 serial port. I need to write a program to connect this device with the PC and transmit data. I already wrote some basic methods to initialize a communication link and tried to test by sending a BEEP command to the device but it is not beeping as expected. So I think there is something wrong with my source code. Please somebody help me complete the source code. Below is the written source code
code :
#include <iostream>
extern "C"
{
    #include <stdlib.h>
    #include <stdio.h>
    #include <unistd.h>
}
#include "DeviceRS232.h"

using namespace std;

int main()
{

    unsigned char sendBuffer[4096] = "Test test test...";
    unsigned char sendBeep[] = {0x05, 0xE6, 0x04, 0x00, 0x11, 0x46, 0x00};
    unsigned char ledOn[] = {0x05, 0xE7, 0x04, 0x00, 0x0D, 0x00};
    unsigned char val[7];

    //-------------------------------------------------------------------------
    unsigned char commonBuffer[257];

    int iChecksum;
    int i;
    commonBuffer[ 1 ] = (unsigned char)0xC6;
    commonBuffer[ 2 ] = (unsigned char)0x04;
    commonBuffer[ 3 ] = (unsigned char)0x08; // Permanant Chnage
    commonBuffer[ 4 ] = (unsigned char)0x11; // Beep after setting. FF for No Beep
    commonBuffer[ 5 ] = (unsigned char)0xEE; // Decorder parameter to set (238)
    commonBuffer[ 6 ] = (unsigned char)0x01; // Value to set

    commonBuffer[ 0 ] = (unsigned char)0x07; // Length

    iChecksum = 0;
    for (i = 0; i < 7; i++)
    {
        iChecksum += commonBuffer[i];
    }

    commonBuffer[i++] = (char)(((-iChecksum) >> 8) & 0xFF); // Add Checksum into the command
    commonBuffer[i++] = (char)((-iChecksum) & 0xFF);
    //-------------------------------------------------------------------------


    cout << "********************** RS232 - SSI **********************" << endl << endl;
    DeviceRS232 dev_rs232;
    dev_rs232.setDefaultAttributes();
    dev_rs232.openSerialPort();

    //----------------------------------------------------
    //for(int x=0; x<10; x++)
    //{
    //    dev_rs232.sendDataBuffer(sendBeep, sizeof(sendBeep));
    //}
    //----------------------------------------------------

    int sizeSent = dev_rs232.sendDataBuffer(commonBuffer, sizeof(commonBuffer));
    if( sizeSent > 0)
    {
        printf("Data sent: %d...\n", sizeSent);
    }

    sleep(1);

    dev_rs232.closeSerialPort();
    cout << "*********************************************************" << endl;


    return 0;
}
Asynchronous data reading from a barcode scanner over RS232 serial port

Asynchronous data reading from a barcode scanner over RS232 serial port


By : 何佳欢
Date : March 29 2020, 07:55 AM
may help you . I have a bar-code reader which is connected to PC on RS232 serial port. I am writing a C++ code to send command to barcode scanner and get the response back to the PC. Currently program can send data to the device correctly but it is failed to read the response from barcode scanner. In this case once we send a command to barcode reader it will response back with a positive or negative acknowledgement.
code :
/**
 * Receive responses from the decoder
 */
int DeviceRS232::receiveDecodedData(unsigned char *dataBuffer, size_t bufferSize)
{
    unsigned char recvBuffer[251];
    unsigned char *ptrChar;
    int nBytes, portStatus;
    int inputBufSize = 0;

    ChangeCTS(fdRS232, 0);
    ChangeRTS(fdRS232, 0);

    while(inputBufSize <= 0)
    {
        ioctl(fdRS232, FIONREAD, &inputBufSize);
        usleep(1);
    }


    if(inputBufSize > 0)
    {
        int decodePacketLen = 0;
        //unsigned char
        memset(recvBuffer, 0x00, sizeof(recvBuffer));
        nBytes = 0;

        //usleep(100000);
        while(nBytes < ((int)recvBuffer[0] + 2))
        {
            int index = 0;
            int recvDataLen = 0;
            if(nBytes != 0)
                index = nBytes - 1;

            recvDataLen = read(fdRS232, &recvBuffer[index], 251);
            if(recvDataLen < 0)
            {
                std::cout << "[INFO@DeviceRS232::receiveDecodedData]File read error: " << strerror(errno) << std::endl;
                //sleep(1);
            }

            nBytes += recvDataLen;
            if(nBytes == ((int)recvBuffer[0] + 2))
                break;

        }

        if(recvBuffer[1] == DECODE_DATA)
            sendCommandToDecoder(OPCODE_ACK);

        std::cout << "[INFO @ DeviceRS232::receiveDecodedData]Data Lenght (without CheckSum) : " << (int)recvBuffer[0] << std::endl;

        for(int i=0; i<nBytes; i++)
        {
            std::cout << "recvBuffer[" << i << "]: ";
            printf("%x\n", recvBuffer[i]);
        }
        std::cout << "-----------------------------------" << std::endl;

        ChangeRTS(fdRS232, 1);
        ChangeCTS(fdRS232, 1);
        //sleep(1);
    }

    //strcpy((char *)dataBuffer, (char *)recvBuffer);
    memcpy((char *)dataBuffer, recvBuffer, sizeof(recvBuffer)/sizeof(recvBuffer[0]));
    inputBufSize = 0;

    return nBytes;

}


/**
 * Send commands to the decoder.
 */
int DeviceRS232::sendCommandToDecoder(unsigned int opCode)
{
    unsigned char *commandBuffer;
    int commandLength;

    switch(opCode)
    {
    case OPCODE_ACK:
        {
            unsigned char ackString[] = {0x00, 0xD0, 0x04, 0x00};
            commandLength = sizeof(ackString);
            commandBuffer = ackString;
        }
        break;
    case OPCODE_PARAM_SEND:
        {
            unsigned char paramSendString[] = {0x00, 0xC6, 0x04, 0x08, 0x00, 0xEE, 0x01};
            commandLength = sizeof(paramSendString);
            commandBuffer = paramSendString;
        }
        break;
    default:
        break;
    }

    Message msgCommand(commandBuffer, commandLength);

    return sendDataBuffer(msgCommand.getCommandData(), msgCommand.getLen());
}
WD-Mobile barcode scanner via serial port

WD-Mobile barcode scanner via serial port


By : Madhavan Dharmalinga
Date : March 29 2020, 07:55 AM
it should still fix some issue Depending what u want. If u have a android Windows Mobile device that has a bultin scanner u should use the comport to communicate. If u want to use the camera i suggest u use one of the existing apps for scanning barcodes. (U can launch them using a intent). The downside is u need to install a second application.
More on launching a other app in WD http://www.mysnip.de/forum-archiv/thema-27131-126196/WM16+Android+-+Open+App+from+an+App+SOLVED.html
How to access scanning result from barcode scanner connected to Android device via USB port?

How to access scanning result from barcode scanner connected to Android device via USB port?


By : anonymous
Date : March 29 2020, 07:55 AM
Any of those help Most USB scanners connect via the HID profile, so Android should recognize it as a keyboard. The decoded barcode will be "typed" into the currently selected field.
If you'd like to capture the result without entering it into an editable field, see Handle barcode scanner value via Android device
Related Posts Related Posts :
  • C++ Dynamically Allocated Array; Size set by quantity of user input; Writing to a file;
  • enums to be defined as uint8_t variables in structure
  • C++ Overloaded Constructor issues
  • Fast CSV parser in C++
  • MFC GUI application rewrite - threading, messaging, Document/View, etc. Advice needed
  • How to get frame feed of a video in OpenCV?
  • saving data structure c++ to disk
  • Vector of pointers: some clarification needed
  • scaling a bitmap without losing quality
  • How to evaluate a function directly?
  • QNetworkAccessManager: How to change post data at createRequest function
  • Returning std::move of a local variable
  • Is there a fast linear SVM library with a good C++ interface?
  • What is the purpose of name mangling in C++?
  • C++ Why the void function is not working eventhough I called it?
  • How the pointer and the pointer's adress can share the same memory adress?
  • error C2220: warning treated as error - no 'object' file generated
  • exception of strcpy function in c++ console program
  • Under which circumstances will std::vector.clear() call a destructor?
  • Template partial specialisation and dependent names
  • best way to share data between c codes
  • C++ ignores if statement conditions
  • How to set the argv[ ] to be case-insensitive in a Win32 Console Application?
  • How to fix error "clang: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)"?
  • C++ How do I print a .txt file verbatim?
  • Creating two dimensional array of class
  • How do I correctly use COMMTIMEOUTS with OVERLAPPED IO mode reading from a Serial port
  • An assert macro which expands to static_assert when possible?
  • How to write a copyconstructor for a class which has HANDLE as a member in win32 c++ application?
  • C++ saving info such as tree in a file
  • Transforming an expression template tree
  • How to overload an operator with multiple parameters like a + b + c?
  • C++ 11 with Raspberry Pi performances
  • Make a C++ class look like a numpy array using swig
  • Postfix incrementer overloading for nested enumerated types
  • Is there a tidy way of associating metadata with functions in C++
  • QObject::installEventFilter(): Cannot filter events for objects in a different thread
  • LNK2005 error with Zxing C++
  • C++ Doubly Linked List with Pointers: Object of class isn't constructed properly
  • Using a random string generator in c++ constructor
  • What should I use instead of void as one of the alternative types in an variant?
  • C++ return value from multithreads using reference
  • How to connect multiple TCP IP clients to same server port using c++
  • Defaul compiler generates the reference operator (In C++)?
  • Unable to change directory time stamp after using FILE_FLAG_BACKUP_SEMANTICS
  • vector handling displaying output
  • WSAGetLastError returns WSAENOTSOCK - Cause?
  • C++: How to overload pow for user type?
  • C++ using arrays as multidimensional despite initalising it as 1D with pointer
  • How negate std::is_integral for use in tag dispatch?
  • Retrieve serial number from USB memory (Windows environment c++)
  • g++ error: invalid preprocessing directive #INCLUDE
  • C++ What is the std::for_each() function parameter type?
  • C++: Read individual lines from text file, sort words alphabetically
  • Saving 'this' address into a variable
  • c++ command line arguments in ubuntu terminal
  • Convert "Cartesian coordinates" to "polar coordinates with respect to user specified origin"
  • In what order are local scoped objects destructed?
  • How to use SDL_MapRGB with SDL 2.0
  • how compiler and interpreter work in case of array declaration
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org