我正在尝试使用Motorola MC3090 Symbol设备编写一个小应用程序来读取BarCode。应用程序必须在PC上运行,而不是在设备上运行,并且必须使用JAVA进行编码。
使用DataWedge 3.3在设备上扫描条形码。
当我在设备上使用写字板时,也会扫描条形码。
现在,问题是如何将这些scaned裸码转移到PC上。
我已经测试了这段代码,知道PC是否找到了设备的端口:
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;
}
}
}
输出
port COM1 not found.
这是一个问题。
我尝试另一种方式,直接的方式
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();
}
}
但问题是我不知道文件路径,因为设备没有像存储设备那样连接在PC上。
那么检索扫描到PC的条形码的方法是什么?
答案 0 :(得分:0)
AFAIK 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网络传输文件或数据。
如果您将设备连接到无线局域网,一切都会更容易。