J'essaie d'écrire une petite application pour lire BarCode à l'aide du périphérique Motorola MC3090 Symbol. L'application doit fonctionner sur un PC, pas sur l'appareil et doit être codée avec JAVA.Importer un code à barres scanné à partir d'un appareil mobile Motorola
Le code à barres est scanné sur l'appareil à l'aide de DataWedge 3.3. Lorsque j'utilise WordPad sur l'appareil, les codes à barres sont également analysés.
Maintenant, le problème est de savoir comment transférer ces codes-barres scannés vers le PC.
Je teste déjà ce code pour savoir si le PC trouve le port de l'appareil:
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;
}
}
}
SORTIE
port COM1 not found.
Ceci est un problème.
J'essaie une autre façon, un lien direct une
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();
}
}
Mais le problème avec cette façon est que je ne connais pas le filepath parce que les appareils ne sont pas connectés sur PC comme un périphérique de stockage.
Alors, quel est le moyen de récupérer le code-barres scanné sur le PC?