导入从摩托罗拉移动设备扫描的条码

Import barcode scanned from motorola mobile device

我正在尝试使用 Motorola MC3090 Symbol 设备编写一个小应用程序来读取条码。该应用程序必须 运行 在 PC 上,而不是在设备上,并且必须使用 JAVA.

编码

使用 DataWedge 3.3 在设备上扫描条形码。

当我在设备上使用写字板时,条形码也会被扫描。

现在的问题是如何将这些扫描的裸码传输到PC。

我已经测试过此代码以了解 PC 是否找到了设备的端口:

代码

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;
        }
    }

}

输出

port COM1 not found.

这是一个问题。

我试试另一种方法,直接的

代码

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();
    }
}

但这种方式的问题是我不知道文件路径,因为设备没有像存储设备一样连接到 PC。

那么如何找回扫描到PC上的条码呢?

据我所知,MC3000 系列是 运行 Windows CE 4.2。

除非您将串行适配器(如果可用)连接到设备,否则没有串行连接。

当设备插入 Windows PC(USB 或串行)时,设备将启动 ActiveSync,并且必须在 PC 上安装 ActiveSync 或 WMDC 才能在设备和 PC 之间建立连接. 可以通过 C/C++ RAPI(另请参阅 Copy a file from PDA to PC via USB in java)或使用网络使用此连接。 ActiveSync 创建一个 PPP 连接并且设备获得一个 IP。或者,对于较新的设备 运行 Windows Mobile 6,您将获得一个连接到设备 (RNDIS) 的虚拟网络适配器。

如果连接了ActiveSync,您可以指定要在PC 和设备之间同步的目录等。或者您使用 PPP 网络传输文件或数据。

如果您将设备连接到您的无线局域网,一切都会变得更容易,如果您有一个 运行。