简体   繁体   中英

Import barcode scanned from motorola mobile device

I am trying to write a small application to read BarCode using Motorola MC3090 Symbol device. The application must run on a PC, not on the device and must be coded with JAVA.

The barcode is scanned on the device, using DataWedge 3.3.

When i use WordPad on the device, barcodes are also scanned.

Now, the problem is how to transfert these scaned barecode to the PC.

I already test this code to know if the PC found the port of the device :

CODE

import java.io.*;
import java.util.*;
import javax.comm.*;

public class SimpleRead implements Runnable, SerialPortEventListener {

    static CommPortIdentifier portId;
    static Enumeration portList;
    InputStream inputStream;
    SerialPort serialPort;
    Thread readThread;

    public static void main(String[] args) {
        boolean portFound = false;
        String defaultPort = "COM1";

        if (args.length > 0) {
            defaultPort = args[0];
        }

        portList = CommPortIdentifier.getPortIdentifiers();

        while (portList.hasMoreElements()) {
            System.out.println("port existed");
            portId = (CommPortIdentifier) portList.nextElement();
            if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
                if (portId.getName().equals(defaultPort)) {
                    System.out.println("Found port: " + defaultPort);
                    portFound = true;
                    SimpleRead reader = new SimpleRead();
                }
            }
        }
        if (!portFound) {
            System.out.println("port " + defaultPort + " not found.");
        }

    }

    public SimpleRead() {
        try {
            serialPort = (SerialPort) portId.open("SimpleReadApp", 2000);
        } catch (PortInUseException e) {
        }

        try {
            inputStream = serialPort.getInputStream();
        } catch (IOException e) {
        }

        try {
            serialPort.addEventListener(this);
        } catch (TooManyListenersException e) {
        }

        serialPort.notifyOnDataAvailable(true);

        try {
            serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8,
                    SerialPort.STOPBITS_1,
                    SerialPort.PARITY_NONE);
        } catch (UnsupportedCommOperationException e) {
        }

        readThread = new Thread(this);

        readThread.start();
    }

    public void run() {
        try {
            Thread.sleep(20000);
        } catch (InterruptedException e) {
        }
    }

    public void serialEvent(SerialPortEvent event) {
        switch (event.getEventType()) {

            case SerialPortEvent.BI:
            case SerialPortEvent.OE:
            case SerialPortEvent.FE:
            case SerialPortEvent.PE:
            case SerialPortEvent.CD:
            case SerialPortEvent.CTS:
            case SerialPortEvent.DSR:
            case SerialPortEvent.RI:

            case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
                break;

            case SerialPortEvent.DATA_AVAILABLE:
                byte[] readBuffer = new byte[20];

                try {
                    while (inputStream.available() > 0) {
                        int numBytes = inputStream.read(readBuffer);
                        System.out.print("The Read Bytes from SerialPort are");
                        System.out.write(readBuffer);
                        System.out.println();
                    }
                    System.out.print(new String(readBuffer));
                } catch (IOException e) {
                }

                break;
        }
    }

}

OUTPUT

port COM1 not found.

This is one problem.

I try one another ways, a direct one

CODE

public static void main(String[] args) {
    String filePath = "??????????";
    readFile(filePath);
}

public static void readFile(String filePath){
    try {
        Scanner scanner = new Scanner(new File(filePath));
        while (scanner.hasNextLine()) {
            System.out.println(scanner.nextLine());
        }
        scanner.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

But the problem with that way is that I don't know the filepath because the devices is not connected on PC like a storage device.

So what is the way to retrieve the barcode scaned to the PC?

AFAIK the MC3000 series is running Windows CE 4.2.

There is no serial connection except you attach a serial adapater (if available) to the device.

When the device is plugged to a Windows PC (USB or Serial), the device will start ActiveSync and on the PC ActiveSync or WMDC has to be installed to get a connection between the device and the PC. This connection can be used via C/C++ RAPI (see also Copy a file from PDA to PC via USB in java ) or using the network. ActiveSync creates a PPP connection and the device gets an IP. Or, with newer devices running Windows Mobile 6, you get a virtual network adapter that connects to the device (RNDIS).

If ActiveSync is connected, you can specify directories etc. to be synced between the PC and the device. Or you use the PPP network to transfer files or data.

Everything will be easier if you connect the device to your wireless LAN, if you have one running.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM