Ola, amigos.
Estou a 3 dias procurando uma forma de executar comando PJL em uma impressora USB. Porem sem sucesso. Este comando eu ja executo via rede abrindo um socket, porem como o socket não funciona com USB, não consegui executar. O detalhe é que ao executar o comando ele me retorna um valor, por exemplo qtdade de paginas impressas, ja tentei fazer com o jUSB, porem nao consigo usar o bufferedReader pra ler o valor que esta chegando. Abaixo colarei o codigo que uso pra fazer em rede e tbm o que estou usando pra tentar em USB:
rede okSocket s = new Socket(InetAddress.getByName("10.1.1.111").getHostName(),9100);
File f = new File("caminhoDoArquivo");
DataOutputStream os = new DataOutputStream(s.getOutputStream());
os.writeBytes("comando @PJL");
BufferedReader in = in = new BufferedReader(new InputStreamReader(s.getInputStream()));
BufferedWriter bw = new BufferedWriter (new OutputStreamWriter (new FileOutputStream(f)));
for (String linha = in.readLine(); linha != null ; linha = in.readLine())
{
bw.write (linha); bw.newLine();
pw.write(linha);
}
public class MainTesteJusb {
private static String vendID = "";
private String prodID = "";
public static void main(String[] args) {
try {
// Bootstrap by getting the USB Host from the HostFactory.
Host host = HostFactory.getHost();
// Obtain a list of the USB buses available on the Host.
Bus[] bus = host.getBusses();
//System.out.println("BUSSES : " + host.getDevice(path));
int total_bus = bus.length;
System.out.println( "Total bus: " + total_bus );
// Traverse through all the USB buses.
for (int i=0; i <total_bus; i++) {
System.out.println( "BUS: " + i );
// Access the root hub on the USB bus and obtain the
// number of USB ports available on the root hub.
Device root = bus[i].getRootHub();
int total_port = root.getNumPorts();
System.out.println( "Total port: " + total_port );
System.out.println( "identifier: " + root.getPortIdentifier() );
System.out.println( "address: " + root.getAddress() );
System.out.println( "speed: " + root.getSpeed() );
System.out.println("___________________________"+"\n");
// Traverse through all the USB ports available on the
// root hub. It should be mentioned that the numbering
// starts from 1, not 0.
for (int j=1; j><=total_port; j++) {
// Obtain the Device connected to the port.
Device device = root.getChild(j);
System.out.println( "child: " + j );
// try{
if (device != null) {
System.out.println( "device: " + device.getPortIdentifier() );
DeviceDescriptor d = device.getDeviceDescriptor();
System.out.println( "getManufacturerStringId: " + d.getManufacturerStringId() );
System.out.println( "getVendorId: " + d.getVendorId() );
System.out.println( "getDeviceId: " + d.getDeviceId() );
System.out.println( "getProduct: " + d.getProduct(0) );
System.out.println("bcdUSB : " + d.getUSBVersion());
System.out.println("Device Class : " + d.getDeviceClass() + " ( " + d.getDeviceClassName() + " )");
System.out.println("Device Subclass : " + d.getDeviceSubClass());
System.out.println("Device Protocol : " + d.getDeviceProtocol());
System.out.println("Max Packet Size : " + d.getMaxPacketSize0());
MainTesteJusb.vendID = "0x" + Integer.toHexString(d.getVendorId());
System.out.println("idVendor : " + d.getVendorId() + " 0x" + Integer.toHexString(d.getVendorId()) + " " + d.getManufacturer(1));
System.out.println("idProduct : " + d.getProductId()+ " 0x" + Integer.toHexString(d.getProductId()) + " " + d.getProduct(0));
System.out.println("bcdDevice release number : " + d.getDeviceId());
System.out.println("iManufacturer : " + d.getManufacturerStringId());
System.out.println("iProduct : " + d.getProductStringId());
System.out.println("iSerialNumber : " + d.getSerialStringId() + " " + d.getSerial(0));
System.out.println("NumConfiguration : " + d.getNumConfigurations());
System.out.println( "\n"+"_______________________________");
// Obtain the current Configuration of the device and the number of
// Interfaces available under the current Configuration.
Configuration config = device.getConfiguration();
int total_interface = config.getNumInterfaces();
//System.out.println( "total_interface: " + total_interface );
// Traverse through the Interfaces
for (int k=0; k<total_interface; k++) {
// Access the currently Interface and obtain the number of
// endpoints available on the Interface.
Interface itf = config.getInterface(k, 0);
int total_ep = itf.getNumEndpoints();
// Traverse through all the endpoints.
for (int l=0; l><total_ep; l++){
// Access the endpoint, and obtain its I/O type.
Endpoint ep = itf.getEndpoint(l);
String io_type = ep.getType();
boolean input = ep.isInput();
System.out.println( "io_type: " + io_type );
System.out.println( "total End Points: " + total_ep );
System.out.println( "INput ?: " + input );
System.out.println( "Type : " + ep.getType() );
// If the endpoint is an input endpoint, obtain its
// InputStream and read in data.
System.out.println( "Validação " + input+ " " + ep.getType() + " " + vendID);
if ( input && vendID.equals("0x43d") && ep.getType().contains("bulk")) {
// //System.out.println( vendID );
// File file = new File("C:/Print Evo/USBPJL.prime");
// BufferedReader ins = new BufferedReader(new InputStreamReader(ep.getInputStream()));
// BufferedWriter bw2 = new BufferedWriter (new OutputStreamWriter (new FileOutputStream(file)));
// for (String linha = ins.readLine(); linha != null ; linha = ins.readLine())
// {
// bw2.write (linha); bw2.newLine();
// System.out.println("1 "+linha);
// }
// bw2.close();
// // Read in data here
// ins.close();
try {
File f = new File("C:/Print Evo/USBPJL2.prime");
DataOutputStream os = new DataOutputStream(ep.getOutputStream());
//os.writeBytes("[code]
public class MainTesteJusb {
private static String vendID = "";
private String prodID = "";
public static void main(String[] args) {
try {
// Bootstrap by getting the USB Host from the HostFactory.
Host host = HostFactory.getHost();
// Obtain a list of the USB buses available on the Host.
Bus[] bus = host.getBusses();
//System.out.println("BUSSES : " + host.getDevice(path));
int total_bus = bus.length;
System.out.println( "Total bus: " + total_bus );
// Traverse through all the USB buses.
for (int i=0; i <total_bus; i++) {
System.out.println( "BUS: " + i );
// Access the root hub on the USB bus and obtain the
// number of USB ports available on the root hub.
Device root = bus[i].getRootHub();
int total_port = root.getNumPorts();
System.out.println( "Total port: " + total_port );
System.out.println( "identifier: " + root.getPortIdentifier() );
System.out.println( "address: " + root.getAddress() );
System.out.println( "speed: " + root.getSpeed() );
System.out.println("___________________________"+"\n");
// Traverse through all the USB ports available on the
// root hub. It should be mentioned that the numbering
// starts from 1, not 0.
for (int j=1; j><=total_port; j++) {
// Obtain the Device connected to the port.
Device device = root.getChild(j);
System.out.println( "child: " + j );
// try{
if (device != null) {
System.out.println( "device: " + device.getPortIdentifier() );
DeviceDescriptor d = device.getDeviceDescriptor();
System.out.println( "getManufacturerStringId: " + d.getManufacturerStringId() );
System.out.println( "getVendorId: " + d.getVendorId() );
System.out.println( "getDeviceId: " + d.getDeviceId() );
System.out.println( "getProduct: " + d.getProduct(0) );
System.out.println("bcdUSB : " + d.getUSBVersion());
System.out.println("Device Class : " + d.getDeviceClass() + " ( " + d.getDeviceClassName() + " )");
System.out.println("Device Subclass : " + d.getDeviceSubClass());
System.out.println("Device Protocol : " + d.getDeviceProtocol());
System.out.println("Max Packet Size : " + d.getMaxPacketSize0());
MainTesteJusb.vendID = "0x" + Integer.toHexString(d.getVendorId());
System.out.println("idVendor : " + d.getVendorId() + " 0x" + Integer.toHexString(d.getVendorId()) + " " + d.getManufacturer(1));
System.out.println("idProduct : " + d.getProductId()+ " 0x" + Integer.toHexString(d.getProductId()) + " " + d.getProduct(0));
System.out.println("bcdDevice release number : " + d.getDeviceId());
System.out.println("iManufacturer : " + d.getManufacturerStringId());
System.out.println("iProduct : " + d.getProductStringId());
System.out.println("iSerialNumber : " + d.getSerialStringId() + " " + d.getSerial(0));
System.out.println("NumConfiguration : " + d.getNumConfigurations());
System.out.println( "\n"+"_______________________________");
// Obtain the current Configuration of the device and the number of
// Interfaces available under the current Configuration.
Configuration config = device.getConfiguration();
int total_interface = config.getNumInterfaces();
//System.out.println( "total_interface: " + total_interface );
// Traverse through the Interfaces
for (int k=0; k<total_interface; k++) {
// Access the currently Interface and obtain the number of
// endpoints available on the Interface.
Interface itf = config.getInterface(k, 0);
int total_ep = itf.getNumEndpoints();
// Traverse through all the endpoints.
for (int l=0; l><total_ep; l++){
// Access the endpoint, and obtain its I/O type.
Endpoint ep = itf.getEndpoint(l);
String io_type = ep.getType();
boolean input = ep.isInput();
System.out.println( "io_type: " + io_type );
System.out.println( "total End Points: " + total_ep );
System.out.println( "INput ?: " + input );
System.out.println( "Type : " + ep.getType() );
// If the endpoint is an input endpoint, obtain its
// InputStream and read in data.
System.out.println( "Validação " + input+ " " + ep.getType() + " " + vendID);
if ( input && vendID.equals("0x43d") && ep.getType().contains("bulk")) {
// //System.out.println( vendID );
// File file = new File("C:/Print Evo/USBPJL.prime");
// BufferedReader ins = new BufferedReader(new InputStreamReader(ep.getInputStream()));
// BufferedWriter bw2 = new BufferedWriter (new OutputStreamWriter (new FileOutputStream(file)));
// for (String linha = ins.readLine(); linha != null ; linha = ins.readLine())
// {
// bw2.write (linha); bw2.newLine();
// System.out.println("1 "+linha);
// }
// bw2.close();
// // Read in data here
// ins.close();
try {
File f = new File("C:/Print Evo/USBPJL2.prime");
DataOutputStream os = new DataOutputStream(ep.getOutputStream());
//os.writeBytes("\033%-12345X@PJL JOB\r\n@PJL INFO PAGECOUNT\r\n@PJL EOJ\r\n\033%-12345X\r\n");
os.writeBytes("\033%-12345X@PJL JOB\r\n@PJL ECHO PAGECOUNT\r\n@PJL EOJ\r\n\033%-12345X\r\n");
BufferedReader in = new BufferedReader(new InputStreamReader(ep.getInputStream()));
BufferedWriter bw = new BufferedWriter (new OutputStreamWriter (new FileOutputStream(f)));
for (String linha = in.readLine(); linha != null ; linha = in.readLine())
{
bw.write (linha); bw.newLine();
System.out.println("1 "+linha);
}
bw.close();
System.out.println("3 ");
in.close();
// System.console();
System.out.println("4 ");
os.flush(); os.close();
//ep.close();
} catch (Exception e) {
System.out.println(e.getMessage()+" ERRO AQUI !"+e.getLocalizedMessage());
e.printStackTrace();
}
}
//else {
// If the Endpoint is and output Endpoint, obtain its
// OutputStream and write out data.
// OutputStream out;
// System.out.println("Erro !!!!");
// out = ep.getOutputStream();
// // Write out data here.
// out.close();
//}
}
}
} else {
System.out.println( "Device nulo" );
}
// }catch ( Exception e ){
// e.printStackTrace();
// }
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
public class MainTesteJusb {
private static String vendID = "";
private String prodID = "";
public static void main(String[] args) {
try {
// Bootstrap by getting the USB Host from the HostFactory.
Host host = HostFactory.getHost();
// Obtain a list of the USB buses available on the Host.
Bus[] bus = host.getBusses();
//System.out.println("BUSSES : " + host.getDevice(path));
int total_bus = bus.length;
System.out.println( "Total bus: " + total_bus );
// Traverse through all the USB buses.
for (int i=0; i <total_bus; i++) {
System.out.println( "BUS: " + i );
// Access the root hub on the USB bus and obtain the
// number of USB ports available on the root hub.
Device root = bus[i].getRootHub();
int total_port = root.getNumPorts();
System.out.println( "Total port: " + total_port );
System.out.println( "identifier: " + root.getPortIdentifier() );
System.out.println( "address: " + root.getAddress() );
System.out.println( "speed: " + root.getSpeed() );
System.out.println("___________________________"+"\n");
// Traverse through all the USB ports available on the
// root hub. It should be mentioned that the numbering
// starts from 1, not 0.
for (int j=1; j><=total_port; j++) {
// Obtain the Device connected to the port.
Device device = root.getChild(j);
System.out.println( "child: " + j );
// try{
if (device != null) {
System.out.println( "device: " + device.getPortIdentifier() );
DeviceDescriptor d = device.getDeviceDescriptor();
System.out.println( "getManufacturerStringId: " + d.getManufacturerStringId() );
System.out.println( "getVendorId: " + d.getVendorId() );
System.out.println( "getDeviceId: " + d.getDeviceId() );
System.out.println( "getProduct: " + d.getProduct(0) );
System.out.println("bcdUSB : " + d.getUSBVersion());
System.out.println("Device Class : " + d.getDeviceClass() + " ( " + d.getDeviceClassName() + " )");
System.out.println("Device Subclass : " + d.getDeviceSubClass());
System.out.println("Device Protocol : " + d.getDeviceProtocol());
System.out.println("Max Packet Size : " + d.getMaxPacketSize0());
MainTesteJusb.vendID = "0x" + Integer.toHexString(d.getVendorId());
System.out.println("idVendor : " + d.getVendorId() + " 0x" + Integer.toHexString(d.getVendorId()) + " " + d.getManufacturer(1));
System.out.println("idProduct : " + d.getProductId()+ " 0x" + Integer.toHexString(d.getProductId()) + " " + d.getProduct(0));
System.out.println("bcdDevice release number : " + d.getDeviceId());
System.out.println("iManufacturer : " + d.getManufacturerStringId());
System.out.println("iProduct : " + d.getProductStringId());
System.out.println("iSerialNumber : " + d.getSerialStringId() + " " + d.getSerial(0));
System.out.println("NumConfiguration : " + d.getNumConfigurations());
System.out.println( "\n"+"_______________________________");
// Obtain the current Configuration of the device and the number of
// Interfaces available under the current Configuration.
Configuration config = device.getConfiguration();
int total_interface = config.getNumInterfaces();
//System.out.println( "total_interface: " + total_interface );
// Traverse through the Interfaces
for (int k=0; k<total_interface; k++) {
// Access the currently Interface and obtain the number of
// endpoints available on the Interface.
Interface itf = config.getInterface(k, 0);
int total_ep = itf.getNumEndpoints();
// Traverse through all the endpoints.
for (int l=0; l><total_ep; l++){
// Access the endpoint, and obtain its I/O type.
Endpoint ep = itf.getEndpoint(l);
String io_type = ep.getType();
boolean input = ep.isInput();
System.out.println( "io_type: " + io_type );
System.out.println( "total End Points: " + total_ep );
System.out.println( "INput ?: " + input );
System.out.println( "Type : " + ep.getType() );
// If the endpoint is an input endpoint, obtain its
// InputStream and read in data.
System.out.println( "Validação " + input+ " " + ep.getType() + " " + vendID);
if ( input && vendID.equals("0x43d") && ep.getType().contains("bulk")) {
// //System.out.println( vendID );
// File file = new File("C:/Print Evo/USBPJL.prime");
// BufferedReader ins = new BufferedReader(new InputStreamReader(ep.getInputStream()));
// BufferedWriter bw2 = new BufferedWriter (new OutputStreamWriter (new FileOutputStream(file)));
// for (String linha = ins.readLine(); linha != null ; linha = ins.readLine())
// {
// bw2.write (linha); bw2.newLine();
// System.out.println("1 "+linha);
// }
// bw2.close();
// // Read in data here
// ins.close();
try {
File f = new File("C:/Print Evo/USBPJL2.prime");
DataOutputStream os = new DataOutputStream(ep.getOutputStream());
//os.writeBytes("\033%-12345X@PJL JOB\r\n@PJL INFO PAGECOUNT\r\n@PJL EOJ\r\n\033%-12345X\r\n");
os.writeBytes("\033%-12345X@PJL JOB\r\n@PJL ECHO PAGECOUNT\r\n@PJL EOJ\r\n\033%-12345X\r\n");
BufferedReader in = new BufferedReader(new InputStreamReader(ep.getInputStream()));
BufferedWriter bw = new BufferedWriter (new OutputStreamWriter (new FileOutputStream(f)));
for (String linha = in.readLine(); linha != null ; linha = in.readLine())
{
bw.write (linha); bw.newLine();
System.out.println("1 "+linha);
}
bw.close();
System.out.println("3 ");
in.close();
// System.console();
System.out.println("4 ");
os.flush(); os.close();
//ep.close();
} catch (Exception e) {
System.out.println(e.getMessage()+" ERRO AQUI !"+e.getLocalizedMessage());
e.printStackTrace();
}
}
//else {
// If the Endpoint is and output Endpoint, obtain its
// OutputStream and write out data.
// OutputStream out;
// System.out.println("Erro !!!!");
// out = ep.getOutputStream();
// // Write out data here.
// out.close();
//}
}
}
} else {
System.out.println( "Device nulo" );
}
// }catch ( Exception e ){
// e.printStackTrace();
// }
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
public class MainTesteJusb {
private static String vendID = "";
private String prodID = "";
public static void main(String[] args) {
try {
// Bootstrap by getting the USB Host from the HostFactory.
Host host = HostFactory.getHost();
// Obtain a list of the USB buses available on the Host.
Bus[] bus = host.getBusses();
//System.out.println("BUSSES : " + host.getDevice(path));
int total_bus = bus.length;
System.out.println( "Total bus: " + total_bus );
// Traverse through all the USB buses.
for (int i=0; i <total_bus; i++) {
System.out.println( "BUS: " + i );
// Access the root hub on the USB bus and obtain the
// number of USB ports available on the root hub.
Device root = bus[i].getRootHub();
int total_port = root.getNumPorts();
System.out.println( "Total port: " + total_port );
System.out.println( "identifier: " + root.getPortIdentifier() );
System.out.println( "address: " + root.getAddress() );
System.out.println( "speed: " + root.getSpeed() );
System.out.println("___________________________"+"\n");
// Traverse through all the USB ports available on the
// root hub. It should be mentioned that the numbering
// starts from 1, not 0.
for (int j=1; j><=total_port; j++) {
// Obtain the Device connected to the port.
Device device = root.getChild(j);
System.out.println( "child: " + j );
// try{
if (device != null) {
System.out.println( "device: " + device.getPortIdentifier() );
DeviceDescriptor d = device.getDeviceDescriptor();
System.out.println( "getManufacturerStringId: " + d.getManufacturerStringId() );
System.out.println( "getVendorId: " + d.getVendorId() );
System.out.println( "getDeviceId: " + d.getDeviceId() );
System.out.println( "getProduct: " + d.getProduct(0) );
System.out.println("bcdUSB : " + d.getUSBVersion());
System.out.println("Device Class : " + d.getDeviceClass() + " ( " + d.getDeviceClassName() + " )");
System.out.println("Device Subclass : " + d.getDeviceSubClass());
System.out.println("Device Protocol : " + d.getDeviceProtocol());
System.out.println("Max Packet Size : " + d.getMaxPacketSize0());
MainTesteJusb.vendID = "0x" + Integer.toHexString(d.getVendorId());
System.out.println("idVendor : " + d.getVendorId() + " 0x" + Integer.toHexString(d.getVendorId()) + " " + d.getManufacturer(1));
System.out.println("idProduct : " + d.getProductId()+ " 0x" + Integer.toHexString(d.getProductId()) + " " + d.getProduct(0));
System.out.println("bcdDevice release number : " + d.getDeviceId());
System.out.println("iManufacturer : " + d.getManufacturerStringId());
System.out.println("iProduct : " + d.getProductStringId());
System.out.println("iSerialNumber : " + d.getSerialStringId() + " " + d.getSerial(0));
System.out.println("NumConfiguration : " + d.getNumConfigurations());
System.out.println( "\n"+"_______________________________");
// Obtain the current Configuration of the device and the number of
// Interfaces available under the current Configuration.
Configuration config = device.getConfiguration();
int total_interface = config.getNumInterfaces();
//System.out.println( "total_interface: " + total_interface );
// Traverse through the Interfaces
for (int k=0; k<total_interface; k++) {
// Access the currently Interface and obtain the number of
// endpoints available on the Interface.
Interface itf = config.getInterface(k, 0);
int total_ep = itf.getNumEndpoints();
// Traverse through all the endpoints.
for (int l=0; l><total_ep; l++){
// Access the endpoint, and obtain its I/O type.
Endpoint ep = itf.getEndpoint(l);
String io_type = ep.getType();
boolean input = ep.isInput();
System.out.println( "io_type: " + io_type );
System.out.println( "total End Points: " + total_ep );
System.out.println( "INput ?: " + input );
System.out.println( "Type : " + ep.getType() );
// If the endpoint is an input endpoint, obtain its
// InputStream and read in data.
System.out.println( "Validação " + input+ " " + ep.getType() + " " + vendID);
if ( input && vendID.equals("0x43d") && ep.getType().contains("bulk")) {
// //System.out.println( vendID );
// File file = new File("C:/Print Evo/USBPJL.prime");
// BufferedReader ins = new BufferedReader(new InputStreamReader(ep.getInputStream()));
// BufferedWriter bw2 = new BufferedWriter (new OutputStreamWriter (new FileOutputStream(file)));
// for (String linha = ins.readLine(); linha != null ; linha = ins.readLine())
// {
// bw2.write (linha); bw2.newLine();
// System.out.println("1 "+linha);
// }
// bw2.close();
// // Read in data here
// ins.close();
try {
File f = new File("C:/Print Evo/USBPJL2.prime");
DataOutputStream os = new DataOutputStream(ep.getOutputStream());
//os.writeBytes("\033%-12345X@PJL JOB\r\n@PJL INFO PAGECOUNT\r\n@PJL EOJ\r\n\033%-12345X\r\n");
os.writeBytes("\033%-12345X@PJL JOB\r\n@PJL ECHO PAGECOUNT\r\n@PJL EOJ\r\n\033%-12345X\r\n");
BufferedReader in = new BufferedReader(new InputStreamReader(ep.getInputStream()));
BufferedWriter bw = new BufferedWriter (new OutputStreamWriter (new FileOutputStream(f)));
for (String linha = in.readLine(); linha != null ; linha = in.readLine())
{
bw.write (linha); bw.newLine();
System.out.println("1 "+linha);
}
bw.close();
System.out.println("3 ");
in.close();
// System.console();
System.out.println("4 ");
os.flush(); os.close();
//ep.close();
} catch (Exception e) {
System.out.println(e.getMessage()+" ERRO AQUI !"+e.getLocalizedMessage());
e.printStackTrace();
}
}
//else {
// If the Endpoint is and output Endpoint, obtain its
// OutputStream and write out data.
// OutputStream out;
// System.out.println("Erro !!!!");
// out = ep.getOutputStream();
// // Write out data here.
// out.close();
//}
}
}
} else {
System.out.println( "Device nulo" );
}
// }catch ( Exception e ){
// e.printStackTrace();
// }
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
public class MainTesteJusb {
private static String vendID = "";
private String prodID = "";
public static void main(String[] args) {
try {
// Bootstrap by getting the USB Host from the HostFactory.
Host host = HostFactory.getHost();
// Obtain a list of the USB buses available on the Host.
Bus[] bus = host.getBusses();
//System.out.println("BUSSES : " + host.getDevice(path));
int total_bus = bus.length;
System.out.println( "Total bus: " + total_bus );
// Traverse through all the USB buses.
for (int i=0; i <total_bus; i++) {
System.out.println( "BUS: " + i );
// Access the root hub on the USB bus and obtain the
// number of USB ports available on the root hub.
Device root = bus[i].getRootHub();
int total_port = root.getNumPorts();
System.out.println( "Total port: " + total_port );
System.out.println( "identifier: " + root.getPortIdentifier() );
System.out.println( "address: " + root.getAddress() );
System.out.println( "speed: " + root.getSpeed() );
System.out.println("___________________________"+"\n");
// Traverse through all the USB ports available on the
// root hub. It should be mentioned that the numbering
// starts from 1, not 0.
for (int j=1; j><=total_port; j++) {
// Obtain the Device connected to the port.
Device device = root.getChild(j);
System.out.println( "child: " + j );
// try{
if (device != null) {
System.out.println( "device: " + device.getPortIdentifier() );
DeviceDescriptor d = device.getDeviceDescriptor();
System.out.println( "getManufacturerStringId: " + d.getManufacturerStringId() );
System.out.println( "getVendorId: " + d.getVendorId() );
System.out.println( "getDeviceId: " + d.getDeviceId() );
System.out.println( "getProduct: " + d.getProduct(0) );
System.out.println("bcdUSB : " + d.getUSBVersion());
System.out.println("Device Class : " + d.getDeviceClass() + " ( " + d.getDeviceClassName() + " )");
System.out.println("Device Subclass : " + d.getDeviceSubClass());
System.out.println("Device Protocol : " + d.getDeviceProtocol());
System.out.println("Max Packet Size : " + d.getMaxPacketSize0());
MainTesteJusb.vendID = "0x" + Integer.toHexString(d.getVendorId());
System.out.println("idVendor : " + d.getVendorId() + " 0x" + Integer.toHexString(d.getVendorId()) + " " + d.getManufacturer(1));
System.out.println("idProduct : " + d.getProductId()+ " 0x" + Integer.toHexString(d.getProductId()) + " " + d.getProduct(0));
System.out.println("bcdDevice release number : " + d.getDeviceId());
System.out.println("iManufacturer : " + d.getManufacturerStringId());
System.out.println("iProduct : " + d.getProductStringId());
System.out.println("iSerialNumber : " + d.getSerialStringId() + " " + d.getSerial(0));
System.out.println("NumConfiguration : " + d.getNumConfigurations());
System.out.println( "\n"+"_______________________________");
// Obtain the current Configuration of the device and the number of
// Interfaces available under the current Configuration.
Configuration config = device.getConfiguration();
int total_interface = config.getNumInterfaces();
//System.out.println( "total_interface: " + total_interface );
// Traverse through the Interfaces
for (int k=0; k<total_interface; k++) {
// Access the currently Interface and obtain the number of
// endpoints available on the Interface.
Interface itf = config.getInterface(k, 0);
int total_ep = itf.getNumEndpoints();
// Traverse through all the endpoints.
for (int l=0; l><total_ep; l++){
// Access the endpoint, and obtain its I/O type.
Endpoint ep = itf.getEndpoint(l);
String io_type = ep.getType();
boolean input = ep.isInput();
System.out.println( "io_type: " + io_type );
System.out.println( "total End Points: " + total_ep );
System.out.println( "INput ?: " + input );
System.out.println( "Type : " + ep.getType() );
// If the endpoint is an input endpoint, obtain its
// InputStream and read in data.
System.out.println( "Validação " + input+ " " + ep.getType() + " " + vendID);
if ( input && vendID.equals("0x43d") && ep.getType().contains("bulk")) {
// //System.out.println( vendID );
// File file = new File("C:/Print Evo/USBPJL.prime");
// BufferedReader ins = new BufferedReader(new InputStreamReader(ep.getInputStream()));
// BufferedWriter bw2 = new BufferedWriter (new OutputStreamWriter (new FileOutputStream(file)));
// for (String linha = ins.readLine(); linha != null ; linha = ins.readLine())
// {
// bw2.write (linha); bw2.newLine();
// System.out.println("1 "+linha);
// }
// bw2.close();
// // Read in data here
// ins.close();
try {
File f = new File("C:/Print Evo/USBPJL2.prime");
DataOutputStream os = new DataOutputStream(ep.getOutputStream());
//os.writeBytes("\033%-12345X@PJL JOB\r\n@PJL INFO PAGECOUNT\r\n@PJL EOJ\r\n\033%-12345X\r\n");
os.writeBytes("\033%-12345X@PJL JOB\r\n@PJL ECHO PAGECOUNT\r\n@PJL EOJ\r\n\033%-12345X\r\n");
BufferedReader in = new BufferedReader(new InputStreamReader(ep.getInputStream()));
BufferedWriter bw = new BufferedWriter (new OutputStreamWriter (new FileOutputStream(f)));
for (String linha = in.readLine(); linha != null ; linha = in.readLine())
{
bw.write (linha); bw.newLine();
System.out.println("1 "+linha);
}
bw.close();
System.out.println("3 ");
in.close();
// System.console();
System.out.println("4 ");
os.flush(); os.close();
//ep.close();
} catch (Exception e) {
System.out.println(e.getMessage()+" ERRO AQUI !"+e.getLocalizedMessage());
e.printStackTrace();
}
}
//else {
// If the Endpoint is and output Endpoint, obtain its
// OutputStream and write out data.
// OutputStream out;
// System.out.println("Erro !!!!");
// out = ep.getOutputStream();
// // Write out data here.
// out.close();
//}
}
}
} else {
System.out.println( "Device nulo" );
}
// }catch ( Exception e ){
// e.printStackTrace();
// }
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
// System.console();
System.out.println("4 ");
os.flush(); os.close();
//ep.close();
} catch (Exception e) {
System.out.println(e.getMessage()+" ERRO AQUI !"+e.getLocalizedMessage());
e.printStackTrace();
}
}
//else {
// If the Endpoint is and output Endpoint, obtain its
// OutputStream and write out data.
// OutputStream out;
// System.out.println("Erro !!!!");
// out = ep.getOutputStream();
// // Write out data here.
// out.close();
//}
}
}
} else {
System.out.println( "Device nulo" );
}
// }catch ( Exception e ){
// e.printStackTrace();
// }
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
[/code]
Abraços.
>