memozebadua
asked on
Dot matrix printer problem (/dev/parport)
Dear experts:
I have a problem with a dot matrix printer. Im in a Linux/Java App project thats prints tickets to it.
But i cant print on it. I dont know why. On Windows it works fine, but the javax.comm for windows is obviously different.
Can anyone help me?
Heres a log of what happens...
Starting printing test...
On Printer 3 :/dev/parport0
SerialDriver(port) Method
DefaultPort: /dev/parport0
Open Method
Trying to open port with Javax...
Opened the port Successfully with Javax!!
Obtaining the OutputStream...
OutputStream OK
Linux: /dev/parport0 opened succesfully
Creating StringBuffer...
Appending text
+------------------------- -----+
| Tienda PRO |
+------------------------- -----+
Print Test Successful
Converting to Bytes while replacing nulls
[B@dc024a
Opening FileOutputStream
Writing to printer
Couldnt send data to port due to :
java.io.IOException: Invalid argument
at java.io.FileOutputStream.w riteBytes( Native Method)
at java.io.FileOutputStream.w rite(FileO utputStrea m.java:247 )
at com.storecheck.detailconne ct.utils.T icketPrint er.printLP T(TicketPr inter.java :362)
at com.storecheck.detailconne ct.ui.pane ls.Setting sPanel.btn ProbarActi onPerforme d(Settings Panel.java :1447)
at com.storecheck.detailconne ct.ui.pane ls.Setting sPanel.acc ess$3100(S ettingsPan el.java:45 )
at com.storecheck.detailconne ct.ui.pane ls.Setting sPanel$19. actionPerf ormed(Sett ingsPanel. java:854)
at javax.swing.AbstractButton .fireActio nPerformed (AbstractB utton.java :1849)
at javax.swing.AbstractButton $Handler.a ctionPerfo rmed(Abstr actButton. java:2169)
at javax.swing.DefaultButtonM odel.fireA ctionPerfo rmed(Defau ltButtonMo del.java:4 20)
at javax.swing.DefaultButtonM odel.setPr essed(Defa ultButtonM odel.java: 258)
at javax.swing.plaf.basic.Bas icButtonLi stener.mou seReleased (BasicButt onListener .java:234)
at java.awt.Component.process MouseEvent (Component .java:5488 )
at javax.swing.JComponent.pro cessMouseE vent(JComp onent.java :3093)
at java.awt.Component.process Event(Comp onent.java :5253)
at java.awt.Container.process Event(Cont ainer.java :1966)
at java.awt.Component.dispatc hEventImpl (Component .java:3955 )
at java.awt.Container.dispatc hEventImpl (Container .java:2024 )
at java.awt.Component.dispatc hEvent(Com ponent.jav a:3803)
at java.awt.LightweightDispat cher.retar getMouseEv ent(Contai ner.java:4 212)
at java.awt.LightweightDispat cher.proce ssMouseEve nt(Contain er.java:38 92)
at java.awt.LightweightDispat cher.dispa tchEvent(C ontainer.j ava:3822)
at java.awt.Container.dispatc hEventImpl (Container .java:2010 )
at java.awt.Window.dispatchEv entImpl(Wi ndow.java: 1774)
at java.awt.Component.dispatc hEvent(Com ponent.jav a:3803)
at java.awt.EventQueue.dispat chEvent(Ev entQueue.j ava:463)
at java.awt.EventDispatchThre ad.pumpOne EventForHi erarchy(Ev entDispatc hThread.ja va:242)
at java.awt.EventDispatchThre ad.pumpEve ntsForHier archy(Even tDispatchT hread.java :163)
at java.awt.EventDispatchThre ad.pumpEve nts(EventD ispatchThr ead.java:1 57)
at java.awt.EventDispatchThre ad.pumpEve nts(EventD ispatchThr ead.java:1 49)
at java.awt.EventDispatchThre ad.run(Eve ntDispatch Thread.jav a:110)
Closing outputStream...
outputStream Closed Succesfully. Printing finished succesfully
and my code that prints is this:
public static boolean printLPT(String datos[]) throws java.lang.NullPointerExcep tion {
FileOutputStream outputStream = null;
try {
String OS = System.getProperty("os.nam e").toStri ng();
String defaultPort = SmartClientSettings.getIns tance().ge tSerialPor t();
if (!OS.startsWith("Windows") ){
SerialDriver serial = new SerialDriver(defaultPort);
if(!serial.open()){
logger.info("Couldnt open the parallel port!");
return false;
}
}
logger.info(OS + ": " + defaultPort + " opened succesfully");
logger.info("Creating StringBuffer...");
StringBuffer yourText = new StringBuffer();
logger.info("Appending text");
for(int i=0; i < datos.length; i++){
yourText.append(datos[i]);
}
logger.info(yourText);
logger.info("Converting to Bytes while replacing nulls");
byte[] bytes = yourText.toString().replac e("null"," ").getByte s();
logger.info(bytes);
logger.info("Opening FileOutputStream");
outputStream = new FileOutputStream(defaultPo rt);
logger.info("Writing to printer");
outputStream.write(bytes);
} catch (FileNotFoundException fileNotFoundException) {
logger.error("Could not find the port file : ",fileNotFoundException);
return false;
} catch (IOException ioException) {
logger.error("Couldnt send data to port due to : ",ioException);
return false;
}catch (Exception Exception) {
logger.error("Error while printing to parallel printer port : ",Exception);
return false;
}finally{
try{
logger.info("Closing outputStream...");
outputStream.close();
logger.info("outputStream Closed Succesfully. Printing finished succesfully");
return true;
} catch (FileNotFoundException fileNotFoundException) {
logger.error("Could not find the port file : ",fileNotFoundException);
return false;
} catch (IOException ioException) {
logger.error("Couldnt send data to port due to : ",ioException);
return false;
}
}
}
public synchronized boolean open(){
boolean abierto=true;
logger.info("Open Method");
while (portList.hasMoreElements( )) {
logger.info("Found 1 port");
portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SE RIAL) {
logger.info("and its Serial");
if (portId.getName().equals(d efaultPort )) {
logger.info("This is the preferred port ");
portFound = true;
try {
logger.info("Trying to open port with Javax...");
serialPort = (SerialPort) portId.open("SimpleWrite", 2000);
logger.info("Opened the port Successfully with Javax!!");
} catch (Exception e) {
logger.error("Couldnt open port with javax", e);
JOptionPane.showMessageDia log(null," Couldnt open the printer port!!","E00156",2);
abierto=false;
continue;
}
logger.info("Obtaining OutputStream...");
try {
outputStream = serialPort.getOutputStream ();
logger.info("OutputStream OK");
} catch (IOException e) {
logger.error("Error getting OutputStream port",e);
abierto=false;
}
//try {
int impresora = Integer.parseInt(SmartClie ntSettings .getInstan ce().getSe lectedPrin ter());
logger.info("Setting Serial parameters");
if (impresora == 0){
//serialPort.setSerialPort Params(960 0, SerialPort.DATABITS_8, SerialPort.STOPBITS_1,Seri alPort.PAR ITY_NONE);
}else if(impresora == 1){
//serialPort.setSerialPort Params(192 00, SerialPort.DATABITS_8, SerialPort.STOPBITS_1,Seri alPort.PAR ITY_NONE);
}
logger.info("Done setting SerialPort Params");
//} catch (UnsupportedCommOperationE xception e) {
// logger.error("Error setting port parameters", e);
// abierto=false;
//}
try {
serialPort.notifyOnOutputE mpty(true) ;
} catch (Exception e) {
logger.error("Error on notifyOnOutputEmpty",e);
abierto=false;
}
}
}else{ //LPT1
logger.info("and its Parallel");
if (portId.getName().equals(d efaultPort )) {
logger.info("This is the preferred port");
portFound = true;
try {
logger.info("Trying to open port with Javax...");
parallelPort = (ParallelPort) portId.open("SimpleWrite", 2000);
logger.info("Opened the port Successfully with Javax!!");
}catch (javax.comm.PortInUseExcep tion ex1){
logger.error("Used Port Exception: " + portId.isCurrentlyOwned(), ex1 );
} catch (Exception e) {
logger.error("Couldnt open port with javax", e);
abierto=false;
continue;
}
logger.info("Obtaining the OutputStream...");
try {
outputStream = parallelPort.getOutputStre am();
logger.info("OutputStream OK");
} catch (IOException e) {
logger.error("Error getting OutputStream port", e);
abierto=false;
}
try {
if (parallelPort.isPaperOut() ){
Toolkit.getDefaultToolkit( ).beep();
}
} catch (Exception e) {
logger.error("Error on notifyOnOutputEmpty",e);
abierto=false;
}
}
}
}
if (!portFound) {
abierto=false;
}
return abierto;
}
Can anyone help me?
Nemo
I have a problem with a dot matrix printer. Im in a Linux/Java App project thats prints tickets to it.
But i cant print on it. I dont know why. On Windows it works fine, but the javax.comm for windows is obviously different.
Can anyone help me?
Heres a log of what happens...
Starting printing test...
On Printer 3 :/dev/parport0
SerialDriver(port) Method
DefaultPort: /dev/parport0
Open Method
Trying to open port with Javax...
Opened the port Successfully with Javax!!
Obtaining the OutputStream...
OutputStream OK
Linux: /dev/parport0 opened succesfully
Creating StringBuffer...
Appending text
+-------------------------
| Tienda PRO |
+-------------------------
Print Test Successful
Converting to Bytes while replacing nulls
[B@dc024a
Opening FileOutputStream
Writing to printer
Couldnt send data to port due to :
java.io.IOException: Invalid argument
at java.io.FileOutputStream.w
at java.io.FileOutputStream.w
at com.storecheck.detailconne
at com.storecheck.detailconne
at com.storecheck.detailconne
at com.storecheck.detailconne
at javax.swing.AbstractButton
at javax.swing.AbstractButton
at javax.swing.DefaultButtonM
at javax.swing.DefaultButtonM
at javax.swing.plaf.basic.Bas
at java.awt.Component.process
at javax.swing.JComponent.pro
at java.awt.Component.process
at java.awt.Container.process
at java.awt.Component.dispatc
at java.awt.Container.dispatc
at java.awt.Component.dispatc
at java.awt.LightweightDispat
at java.awt.LightweightDispat
at java.awt.LightweightDispat
at java.awt.Container.dispatc
at java.awt.Window.dispatchEv
at java.awt.Component.dispatc
at java.awt.EventQueue.dispat
at java.awt.EventDispatchThre
at java.awt.EventDispatchThre
at java.awt.EventDispatchThre
at java.awt.EventDispatchThre
at java.awt.EventDispatchThre
Closing outputStream...
outputStream Closed Succesfully. Printing finished succesfully
and my code that prints is this:
public static boolean printLPT(String datos[]) throws java.lang.NullPointerExcep
FileOutputStream outputStream = null;
try {
String OS = System.getProperty("os.nam
String defaultPort = SmartClientSettings.getIns
if (!OS.startsWith("Windows")
SerialDriver serial = new SerialDriver(defaultPort);
if(!serial.open()){
logger.info("Couldnt open the parallel port!");
return false;
}
}
logger.info(OS + ": " + defaultPort + " opened succesfully");
logger.info("Creating StringBuffer...");
StringBuffer yourText = new StringBuffer();
logger.info("Appending text");
for(int i=0; i < datos.length; i++){
yourText.append(datos[i]);
}
logger.info(yourText);
logger.info("Converting to Bytes while replacing nulls");
byte[] bytes = yourText.toString().replac
logger.info(bytes);
logger.info("Opening FileOutputStream");
outputStream = new FileOutputStream(defaultPo
logger.info("Writing to printer");
outputStream.write(bytes);
} catch (FileNotFoundException fileNotFoundException) {
logger.error("Could not find the port file : ",fileNotFoundException);
return false;
} catch (IOException ioException) {
logger.error("Couldnt send data to port due to : ",ioException);
return false;
}catch (Exception Exception) {
logger.error("Error while printing to parallel printer port : ",Exception);
return false;
}finally{
try{
logger.info("Closing outputStream...");
outputStream.close();
logger.info("outputStream Closed Succesfully. Printing finished succesfully");
return true;
} catch (FileNotFoundException fileNotFoundException) {
logger.error("Could not find the port file : ",fileNotFoundException);
return false;
} catch (IOException ioException) {
logger.error("Couldnt send data to port due to : ",ioException);
return false;
}
}
}
public synchronized boolean open(){
boolean abierto=true;
logger.info("Open Method");
while (portList.hasMoreElements(
logger.info("Found 1 port");
portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SE
logger.info("and its Serial");
if (portId.getName().equals(d
logger.info("This is the preferred port ");
portFound = true;
try {
logger.info("Trying to open port with Javax...");
serialPort = (SerialPort) portId.open("SimpleWrite",
logger.info("Opened the port Successfully with Javax!!");
} catch (Exception e) {
logger.error("Couldnt open port with javax", e);
JOptionPane.showMessageDia
abierto=false;
continue;
}
logger.info("Obtaining OutputStream...");
try {
outputStream = serialPort.getOutputStream
logger.info("OutputStream OK");
} catch (IOException e) {
logger.error("Error getting OutputStream port",e);
abierto=false;
}
//try {
int impresora = Integer.parseInt(SmartClie
logger.info("Setting Serial parameters");
if (impresora == 0){
//serialPort.setSerialPort
}else if(impresora == 1){
//serialPort.setSerialPort
}
logger.info("Done setting SerialPort Params");
//} catch (UnsupportedCommOperationE
// logger.error("Error setting port parameters", e);
// abierto=false;
//}
try {
serialPort.notifyOnOutputE
} catch (Exception e) {
logger.error("Error on notifyOnOutputEmpty",e);
abierto=false;
}
}
}else{ //LPT1
logger.info("and its Parallel");
if (portId.getName().equals(d
logger.info("This is the preferred port");
portFound = true;
try {
logger.info("Trying to open port with Javax...");
parallelPort = (ParallelPort) portId.open("SimpleWrite",
logger.info("Opened the port Successfully with Javax!!");
}catch (javax.comm.PortInUseExcep
logger.error("Used Port Exception: " + portId.isCurrentlyOwned(),
} catch (Exception e) {
logger.error("Couldnt open port with javax", e);
abierto=false;
continue;
}
logger.info("Obtaining the OutputStream...");
try {
outputStream = parallelPort.getOutputStre
logger.info("OutputStream OK");
} catch (IOException e) {
logger.error("Error getting OutputStream port", e);
abierto=false;
}
try {
if (parallelPort.isPaperOut()
Toolkit.getDefaultToolkit(
}
} catch (Exception e) {
logger.error("Error on notifyOnOutputEmpty",e);
abierto=false;
}
}
}
}
if (!portFound) {
abierto=false;
}
return abierto;
}
Can anyone help me?
Nemo
ASKER
Hey Mark! :)
Mmm i did that because i was trying to avoid null in a string. The string is indeed this:
+------------------------- -----+
| Tienda PRO |
+------------------------- -----+
Print Test Successful
(with the blank lines)
So basically, the string is this: +------------------------- -----+\n | Tienda PRO \n | +------------------------- -----+\n .... and so on.
But at the end of the string, it always sent a null because my String array is sometimes larger or shorter and i cant define it as a single number like 11, so sometimes it just sends a null when there was no more data but the for was still spinning.
So i just decided to replace nulls to "".
But now i changed a little bit my code, to correct it as you told me:
for(int i=0; i < datos.length; i++){
if (datos[i] != null){ <--- ADDED THIS NULL CHECK
yourText.append(datos[i]);
}
}
logger.info(yourText);
logger.info("Converting to Bytes while replacing nulls");
byte[] bytes = yourText.toString().getByt es(); <--- ERASED THAT NULL CHCK
logger.info(bytes);
But, now i have another problem, as you can see below:
SerialDriver Constructor
PortID OK... Jumping to the other Constructor method...
SerialDriver(port) Method
DefaultPort: /dev/parport0
Open Method
This is the preferred port
Trying to open port with Javax...
Opened the port Successfully with Javax!!
Obtaining the OutputStream...
Error while printing to parallel printer port :
java.lang.IllegalStateExce ption: This port has not been opened yet
at com.sun.comm.LinuxParallel .getOutput Stream(Lin uxParallel .java:320)
at com.storecheck.detailconne ct.utils.S erialDrive r.open(Ser ialDriver. java:167)
at com.storecheck.detailconne ct.utils.T icketPrint er.printLP T(TicketPr inter.java :340)
at com.storecheck.detailconne ct.ui.pane ls.Setting sPanel.btn ProbarActi onPerforme d(Settings Panel.java :1447)
at com.storecheck.detailconne ct.ui.pane ls.Setting sPanel.acc ess$3100(S ettingsPan el.java:45 )
at com.storecheck.detailconne ct.ui.pane ls.Setting sPanel$19. actionPerf ormed(Sett ingsPanel. java:854)
at javax.swing.AbstractButton .fireActio nPerformed (AbstractB utton.java :1849)
at javax.swing.AbstractButton $Handler.a ctionPerfo rmed(Abstr actButton. java:2169)
at javax.swing.DefaultButtonM odel.fireA ctionPerfo rmed(Defau ltButtonMo del.java:4 20)
at javax.swing.DefaultButtonM odel.setPr essed(Defa ultButtonM odel.java: 258)
at javax.swing.plaf.basic.Bas icButtonLi stener.mou seReleased (BasicButt onListener .java:234)
at java.awt.Component.process MouseEvent (Component .java:5488 )
at javax.swing.JComponent.pro cessMouseE vent(JComp onent.java :3093)
at java.awt.Component.process Event(Comp onent.java :5253)
at java.awt.Container.process Event(Cont ainer.java :1966)
at java.awt.Component.dispatc hEventImpl (Component .java:3955 )
at java.awt.Container.dispatc hEventImpl (Container .java:2024 )
at java.awt.Component.dispatc hEvent(Com ponent.jav a:3803)
at java.awt.LightweightDispat cher.retar getMouseEv ent(Contai ner.java:4 212)
at java.awt.LightweightDispat cher.proce ssMouseEve nt(Contain er.java:38 92)
at java.awt.LightweightDispat cher.dispa tchEvent(C ontainer.j ava:3822)
at java.awt.Container.dispatc hEventImpl (Container .java:2010 )
at java.awt.Window.dispatchEv entImpl(Wi ndow.java: 1774)
at java.awt.Component.dispatc hEvent(Com ponent.jav a:3803)
at java.awt.EventQueue.dispat chEvent(Ev entQueue.j ava:463)
at java.awt.EventDispatchThre ad.pumpOne EventForHi erarchy(Ev entDispatc hThread.ja va:242)
at java.awt.EventDispatchThre ad.pumpEve ntsForHier archy(Even tDispatchT hread.java :163)
at java.awt.EventDispatchThre ad.pumpEve nts(EventD ispatchThr ead.java:1 57)
at java.awt.EventDispatchThre ad.pumpEve nts(EventD ispatchThr ead.java:1 49)
at java.awt.EventDispatchThre ad.run(Eve ntDispatch Thread.jav a:110)
Closing outputStream...
Any ideas?
Thanks :)
Nemo
Mmm i did that because i was trying to avoid null in a string. The string is indeed this:
+-------------------------
| Tienda PRO |
+-------------------------
Print Test Successful
(with the blank lines)
So basically, the string is this: +-------------------------
But at the end of the string, it always sent a null because my String array is sometimes larger or shorter and i cant define it as a single number like 11, so sometimes it just sends a null when there was no more data but the for was still spinning.
So i just decided to replace nulls to "".
But now i changed a little bit my code, to correct it as you told me:
for(int i=0; i < datos.length; i++){
if (datos[i] != null){ <--- ADDED THIS NULL CHECK
yourText.append(datos[i]);
}
}
logger.info(yourText);
logger.info("Converting to Bytes while replacing nulls");
byte[] bytes = yourText.toString().getByt
logger.info(bytes);
But, now i have another problem, as you can see below:
SerialDriver Constructor
PortID OK... Jumping to the other Constructor method...
SerialDriver(port) Method
DefaultPort: /dev/parport0
Open Method
This is the preferred port
Trying to open port with Javax...
Opened the port Successfully with Javax!!
Obtaining the OutputStream...
Error while printing to parallel printer port :
java.lang.IllegalStateExce
at com.sun.comm.LinuxParallel
at com.storecheck.detailconne
at com.storecheck.detailconne
at com.storecheck.detailconne
at com.storecheck.detailconne
at com.storecheck.detailconne
at javax.swing.AbstractButton
at javax.swing.AbstractButton
at javax.swing.DefaultButtonM
at javax.swing.DefaultButtonM
at javax.swing.plaf.basic.Bas
at java.awt.Component.process
at javax.swing.JComponent.pro
at java.awt.Component.process
at java.awt.Container.process
at java.awt.Component.dispatc
at java.awt.Container.dispatc
at java.awt.Component.dispatc
at java.awt.LightweightDispat
at java.awt.LightweightDispat
at java.awt.LightweightDispat
at java.awt.Container.dispatc
at java.awt.Window.dispatchEv
at java.awt.Component.dispatc
at java.awt.EventQueue.dispat
at java.awt.EventDispatchThre
at java.awt.EventDispatchThre
at java.awt.EventDispatchThre
at java.awt.EventDispatchThre
at java.awt.EventDispatchThre
Closing outputStream...
Any ideas?
Thanks :)
Nemo
This seems incorrect:
String defaultPort = SmartClientSettings.getIns tance().ge tSerialPor t();
outputStream = new FileOutputStream(defaultPo rt);
outputStream.write(bytes);
I'm not sure if you can create a fileoutputstream from that "defaultPort" thingie. Could you show how you connect to your serial port, open the connection and generate input/outputstreams from that connection?
Mark
String defaultPort = SmartClientSettings.getIns
outputStream = new FileOutputStream(defaultPo
outputStream.write(bytes);
I'm not sure if you can create a fileoutputstream from that "defaultPort" thingie. Could you show how you connect to your serial port, open the connection and generate input/outputstreams from that connection?
Mark
ASKER
:)
This line:
String defaultPort = SmartClientSettings.getIns tance().ge tSerialPor t();
brings this result:
/dev/parport0
only. It looks for the actual selected port for my application only.
The other question you made is "how you connect to your serial port and how you generate input/outputstreams from that connection?".
This code shows:
private Enumeration portList;
private CommPortIdentifier portId;
private ParallelPort parallelPort;
private SerialPort serialPort;
private OutputStream outputStream = null;
private boolean outputBufferEmptyFlag = false;
private boolean portFound = false;
private String defaultPort;
String OS = System.getProperty("os.nam e").toStri ng();
public SerialDriver(String puerto) {
this();
logger.info("SerialDriver( port) Method");
defaultPort = puerto;
logger.info("DefaultPort: " + defaultPort);
}
public SerialDriver(){
logger.info("SerialDriver Constructor");
portList = CommPortIdentifier.getPort Identifier s();
logger.info("PortID OK... Jumping to the other Constructor method...");
}
public String[] portList(){
logger.info("portList Method");
CommPortIdentifier puerto;
int cuenta=0;
logger.info("Finding ports ...");
Enumeration puertos = CommPortIdentifier.getPort Identifier s();
String sPuertos="";
while (puertos.hasMoreElements() ) {
logger.info("Found 1 port");
cuenta++;
puerto = (CommPortIdentifier) puertos.nextElement();
//if(puerto.getPortType() == CommPortIdentifier.PORT_SE RIAL)
sPuertos += puerto.getName() + ":";
}
logger.info("Found " + cuenta + " ports in this computer");
if(sPuertos.endsWith(":") && sPuertos.length()>1)
sPuertos = sPuertos.substring(0, sPuertos.length()-1);
logger.info("AllPorts list: " + sPuertos);
String resultado[] = sPuertos.split(":");
logger.info("portList Method ends.");
return resultado;
}
public synchronized boolean open(){
boolean abierto=true;
logger.info("Open Method");
while (portList.hasMoreElements( )) {
logger.info("Found 1 port");
portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SE RIAL) {
logger.info("and its Serial");
if (portId.getName().equals(d efaultPort )) {
logger.info("This is the preferred port ");
portFound = true;
try {
logger.info("Trying to open port with Javax...");
serialPort = (SerialPort) portId.open("SimpleWrite", 2000);
logger.info("Opened the port Successfully with Javax!!");
} catch (Exception e) {
logger.error("Couldnt open port with javax", e);
JOptionPane.showMessageDia log(null," Couldnt open the printer port!!","E00156",2);
abierto=false;
continue;
}
logger.info("Obtaining OutputStream...");
try {
outputStream = serialPort.getOutputStream ();
logger.info("OutputStream OK");
} catch (IOException e) {
logger.error("Error getting OutputStream port",e);
abierto=false;
}
//try {
int impresora = Integer.parseInt(SmartClie ntSettings .getInstan ce().getSe lectedPrin ter());
logger.info("Setting Serial parameters");
if (impresora == 0){
//serialPort.setSerialPort Params(960 0, SerialPort.DATABITS_8, SerialPort.STOPBITS_1,Seri alPort.PAR ITY_NONE);
}else if(impresora == 1){
//serialPort.setSerialPort Params(192 00, SerialPort.DATABITS_8, SerialPort.STOPBITS_1,Seri alPort.PAR ITY_NONE);
}
logger.info("Done setting SerialPort Params");
//} catch (UnsupportedCommOperationE xception e) {
// logger.error("Error setting port parameters", e);
// abierto=false;
//}
try {
serialPort.notifyOnOutputE mpty(true) ;
} catch (Exception e) {
logger.error("Error on notifyOnOutputEmpty",e);
abierto=false;
}
}
}else{ //LPT1
logger.info("and its Parallel");
if (portId.getName().equals(d efaultPort )) {
logger.info("This is the preferred port");
portFound = true;
try {
logger.info("Trying to open port with Javax...");
parallelPort = (ParallelPort) portId.open("SimpleWrite", 2000);
logger.info("Opened the port Successfully with Javax!!");
}catch (javax.comm.PortInUseExcep tion ex1){
logger.error("Used Port Exception: " + portId.isCurrentlyOwned(), ex1 );
} catch (Exception e) {
logger.error("Couldnt open port with javax", e);
abierto=false;
continue;
}
logger.info("Obtaining the OutputStream...");
try {
outputStream = parallelPort.getOutputStre am();
logger.info("OutputStream OK");
} catch (IOException e) {
logger.error("Error getting OutputStream port", e);
abierto=false;
}
try {
if (parallelPort.isPaperOut() ){
Toolkit.getDefaultToolkit( ).beep();
}
} catch (Exception e) {
logger.error("Error on notifyOnOutputEmpty",e);
abierto=false;
}
}
}
}
if (!portFound) {
abierto=false;
}
return abierto;
}
And with this I send things to the printer:
public static boolean printLPT(String datos[]) throws java.lang.NullPointerExcep tion {
FileOutputStream outputStream = null;
try {
String OS = System.getProperty("os.nam e").toStri ng();
String defaultPort = SmartClientSettings.getIns tance().ge tSerialPor t();
if (!OS.startsWith("Windows") ){
SerialDriver serial = new SerialDriver(defaultPort);
if(!serial.open()){
logger.info("Couldnt open the parallel port!");
return false;
}
}
logger.info(OS + ": " + defaultPort + " opened succesfully");
logger.info("Creating StringBuffer...");
StringBuffer yourText = new StringBuffer();
logger.info("Appending text");
for(int i=0; i < datos.length; i++){
if (datos[i] != null){
yourText.append(datos[i]);
}
}
logger.info(yourText);
logger.info("Converting to Bytes while replacing nulls");
byte[] bytes = yourText.toString().getByt es();
logger.info(bytes);
logger.info("Opening FileOutputStream");
outputStream = new FileOutputStream(defaultPo rt);
logger.info("Writing to printer");
outputStream.write(bytes);
} catch (FileNotFoundException fileNotFoundException) {
logger.error("Could not find the port file : ",fileNotFoundException);
return false;
} catch (IOException ioException) {
logger.error("Couldnt send data to port due to : ",ioException);
return false;
}catch (Exception Exception) {
logger.error("Error while printing to parallel printer port : ",Exception);
return false;
}finally{
try{
logger.info("Closing outputStream...");
outputStream.close();
logger.info("outputStream Closed Succesfully. Printing finished succesfully");
return true;
} catch (FileNotFoundException fileNotFoundException) {
logger.error("Could not find the port file : ",fileNotFoundException);
return false;
} catch (IOException ioException) {
logger.error("Couldnt send data to port due to : ",ioException);
return false;
}
}
}
This line:
String defaultPort = SmartClientSettings.getIns
brings this result:
/dev/parport0
only. It looks for the actual selected port for my application only.
The other question you made is "how you connect to your serial port and how you generate input/outputstreams from that connection?".
This code shows:
private Enumeration portList;
private CommPortIdentifier portId;
private ParallelPort parallelPort;
private SerialPort serialPort;
private OutputStream outputStream = null;
private boolean outputBufferEmptyFlag = false;
private boolean portFound = false;
private String defaultPort;
String OS = System.getProperty("os.nam
public SerialDriver(String puerto) {
this();
logger.info("SerialDriver(
defaultPort = puerto;
logger.info("DefaultPort: " + defaultPort);
}
public SerialDriver(){
logger.info("SerialDriver Constructor");
portList = CommPortIdentifier.getPort
logger.info("PortID OK... Jumping to the other Constructor method...");
}
public String[] portList(){
logger.info("portList Method");
CommPortIdentifier puerto;
int cuenta=0;
logger.info("Finding ports ...");
Enumeration puertos = CommPortIdentifier.getPort
String sPuertos="";
while (puertos.hasMoreElements()
logger.info("Found 1 port");
cuenta++;
puerto = (CommPortIdentifier) puertos.nextElement();
//if(puerto.getPortType() == CommPortIdentifier.PORT_SE
sPuertos += puerto.getName() + ":";
}
logger.info("Found " + cuenta + " ports in this computer");
if(sPuertos.endsWith(":") && sPuertos.length()>1)
sPuertos = sPuertos.substring(0, sPuertos.length()-1);
logger.info("AllPorts list: " + sPuertos);
String resultado[] = sPuertos.split(":");
logger.info("portList Method ends.");
return resultado;
}
public synchronized boolean open(){
boolean abierto=true;
logger.info("Open Method");
while (portList.hasMoreElements(
logger.info("Found 1 port");
portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SE
logger.info("and its Serial");
if (portId.getName().equals(d
logger.info("This is the preferred port ");
portFound = true;
try {
logger.info("Trying to open port with Javax...");
serialPort = (SerialPort) portId.open("SimpleWrite",
logger.info("Opened the port Successfully with Javax!!");
} catch (Exception e) {
logger.error("Couldnt open port with javax", e);
JOptionPane.showMessageDia
abierto=false;
continue;
}
logger.info("Obtaining OutputStream...");
try {
outputStream = serialPort.getOutputStream
logger.info("OutputStream OK");
} catch (IOException e) {
logger.error("Error getting OutputStream port",e);
abierto=false;
}
//try {
int impresora = Integer.parseInt(SmartClie
logger.info("Setting Serial parameters");
if (impresora == 0){
//serialPort.setSerialPort
}else if(impresora == 1){
//serialPort.setSerialPort
}
logger.info("Done setting SerialPort Params");
//} catch (UnsupportedCommOperationE
// logger.error("Error setting port parameters", e);
// abierto=false;
//}
try {
serialPort.notifyOnOutputE
} catch (Exception e) {
logger.error("Error on notifyOnOutputEmpty",e);
abierto=false;
}
}
}else{ //LPT1
logger.info("and its Parallel");
if (portId.getName().equals(d
logger.info("This is the preferred port");
portFound = true;
try {
logger.info("Trying to open port with Javax...");
parallelPort = (ParallelPort) portId.open("SimpleWrite",
logger.info("Opened the port Successfully with Javax!!");
}catch (javax.comm.PortInUseExcep
logger.error("Used Port Exception: " + portId.isCurrentlyOwned(),
} catch (Exception e) {
logger.error("Couldnt open port with javax", e);
abierto=false;
continue;
}
logger.info("Obtaining the OutputStream...");
try {
outputStream = parallelPort.getOutputStre
logger.info("OutputStream OK");
} catch (IOException e) {
logger.error("Error getting OutputStream port", e);
abierto=false;
}
try {
if (parallelPort.isPaperOut()
Toolkit.getDefaultToolkit(
}
} catch (Exception e) {
logger.error("Error on notifyOnOutputEmpty",e);
abierto=false;
}
}
}
}
if (!portFound) {
abierto=false;
}
return abierto;
}
And with this I send things to the printer:
public static boolean printLPT(String datos[]) throws java.lang.NullPointerExcep
FileOutputStream outputStream = null;
try {
String OS = System.getProperty("os.nam
String defaultPort = SmartClientSettings.getIns
if (!OS.startsWith("Windows")
SerialDriver serial = new SerialDriver(defaultPort);
if(!serial.open()){
logger.info("Couldnt open the parallel port!");
return false;
}
}
logger.info(OS + ": " + defaultPort + " opened succesfully");
logger.info("Creating StringBuffer...");
StringBuffer yourText = new StringBuffer();
logger.info("Appending text");
for(int i=0; i < datos.length; i++){
if (datos[i] != null){
yourText.append(datos[i]);
}
}
logger.info(yourText);
logger.info("Converting to Bytes while replacing nulls");
byte[] bytes = yourText.toString().getByt
logger.info(bytes);
logger.info("Opening FileOutputStream");
outputStream = new FileOutputStream(defaultPo
logger.info("Writing to printer");
outputStream.write(bytes);
} catch (FileNotFoundException fileNotFoundException) {
logger.error("Could not find the port file : ",fileNotFoundException);
return false;
} catch (IOException ioException) {
logger.error("Couldnt send data to port due to : ",ioException);
return false;
}catch (Exception Exception) {
logger.error("Error while printing to parallel printer port : ",Exception);
return false;
}finally{
try{
logger.info("Closing outputStream...");
outputStream.close();
logger.info("outputStream Closed Succesfully. Printing finished succesfully");
return true;
} catch (FileNotFoundException fileNotFoundException) {
logger.error("Could not find the port file : ",fileNotFoundException);
return false;
} catch (IOException ioException) {
logger.error("Couldnt send data to port due to : ",ioException);
return false;
}
}
}
Ok, I think you have to do something like:
String defaultPort = SmartClientSettings.getIns tance().ge tSerialPor t();
SerialDriver serial = new SerialDriver(defaultPort);
if(!serial.open())
{
logger.info("Couldnt open the parallel port!");
return false;
}
OutputStream out = serial.getOutputStream();
out.write(...)
Now the serial port is constructed, but never used again. So I think you should first get the port.. create a serial driver and then get the outputstream from this serial driver. The serialdriver class still needs a get-method to get the outputstream, simply:
public OutputStream getOutputStream()
{
return this.outputStream;
}
Mark
String defaultPort = SmartClientSettings.getIns
SerialDriver serial = new SerialDriver(defaultPort);
if(!serial.open())
{
logger.info("Couldnt open the parallel port!");
return false;
}
OutputStream out = serial.getOutputStream();
out.write(...)
Now the serial port is constructed, but never used again. So I think you should first get the port.. create a serial driver and then get the outputstream from this serial driver. The serialdriver class still needs a get-method to get the outputstream, simply:
public OutputStream getOutputStream()
{
return this.outputStream;
}
Mark
ASKER
Mmm it didnt work... same exception:
SerialDriver Constructor
PortID OK... Jumping to the other Constructor method...
SerialDriver(port) Method
DefaultPort: /dev/parport0
Open Method
This is the preferred port
Trying to open port with Javax...
Opened the port Successfully with Javax!!
Obtaining the OutputStream...
Error while printing to parallel printer port :
java.lang.IllegalStateExce ption: This port has not been opened yet
at com.sun.comm.LinuxParallel .getOutput Stream(Lin uxParallel .java:320)
at com.storecheck.detailconne ct.utils.S erialDrive r.open(Ser ialDriver. java:167)
at com.storecheck.detailconne ct.utils.T icketPrint er.printLP T(TicketPr inter.java :340)
at com.storecheck.detailconne ct.ui.pane ls.Setting sPanel.btn ProbarActi onPerforme d(Settings Panel.java :1447)
at com.storecheck.detailconne ct.ui.pane ls.Setting sPanel.acc ess$3100(S ettingsPan el.java:45 )
at com.storecheck.detailconne ct.ui.pane ls.Setting sPanel$19. actionPerf ormed(Sett ingsPanel. java:854)
at javax.swing.AbstractButton .fireActio nPerformed (AbstractB utton.java :1849)
at javax.swing.AbstractButton $Handler.a ctionPerfo rmed(Abstr actButton. java:2169)
at javax.swing.DefaultButtonM odel.fireA ctionPerfo rmed(Defau ltButtonMo del.java:4 20)
at javax.swing.DefaultButtonM odel.setPr essed(Defa ultButtonM odel.java: 258)
at javax.swing.plaf.basic.Bas icButtonLi stener.mou seReleased (BasicButt onListener .java:234)
at java.awt.Component.process MouseEvent (Component .java:5488 )
at javax.swing.JComponent.pro cessMouseE vent(JComp onent.java :3093)
at java.awt.Component.process Event(Comp onent.java :5253)
at java.awt.Container.process Event(Cont ainer.java :1966)
at java.awt.Component.dispatc hEventImpl (Component .java:3955 )
at java.awt.Container.dispatc hEventImpl (Container .java:2024 )
at java.awt.Component.dispatc hEvent(Com ponent.jav a:3803)
at java.awt.LightweightDispat cher.retar getMouseEv ent(Contai ner.java:4 212)
at java.awt.LightweightDispat cher.proce ssMouseEve nt(Contain er.java:38 92)
at java.awt.LightweightDispat cher.dispa tchEvent(C ontainer.j ava:3822)
at java.awt.Container.dispatc hEventImpl (Container .java:2010 )
at java.awt.Window.dispatchEv entImpl(Wi ndow.java: 1774)
at java.awt.Component.dispatc hEvent(Com ponent.jav a:3803)
at java.awt.EventQueue.dispat chEvent(Ev entQueue.j ava:463)
at java.awt.EventDispatchThre ad.pumpOne EventForHi erarchy(Ev entDispatc hThread.ja va:242)
at java.awt.EventDispatchThre ad.pumpEve ntsForHier archy(Even tDispatchT hread.java :163)
at java.awt.EventDispatchThre ad.pumpEve nts(EventD ispatchThr ead.java:1 57)
at java.awt.EventDispatchThre ad.pumpEve nts(EventD ispatchThr ead.java:1 49)
at java.awt.EventDispatchThre ad.run(Eve ntDispatch Thread.jav a:110)
Closing outputStream...
Here's the new code:
public static boolean printLPT(String datos[]) throws java.lang.NullPointerExcep tion {
OutputStream outputStream = null;
try {
String OS = System.getProperty("os.nam e").toStri ng();
String defaultPort = SmartClientSettings.getIns tance().ge tSerialPor t();
SerialDriver serial = null;
if (!OS.startsWith("Windows") ){
serial = new SerialDriver(defaultPort);
if(!serial.open()){
logger.info("Couldnt open the parallel port!");
return false;
}
}
logger.info(OS + ": " + defaultPort + " opened succesfully");
logger.info("Creating StringBuffer...");
StringBuffer yourText = new StringBuffer();
logger.info("Appending text");
for(int i=0; i < datos.length; i++){
if (datos[i] != null){
yourText.append(datos[i]);
}
}
logger.info(yourText);
logger.info("Converting to Bytes while replacing nulls");
byte[] bytes = yourText.toString().getByt es();
logger.info(bytes);
logger.info("Opening FileOutputStream");
outputStream = serial.getOutputStream();
logger.info("Writing to printer");
outputStream.write(bytes);
} catch (FileNotFoundException fileNotFoundException) {
logger.error("Could not find the port file : ",fileNotFoundException);
return false;
} catch (IOException ioException) {
logger.error("Couldnt send data to port due to : ",ioException);
return false;
}catch (Exception Exception) {
logger.error("Error while printing to parallel printer port : ",Exception);
return false;
}finally{
try{
logger.info("Closing outputStream...");
outputStream.close();
logger.info("outputStream Closed Succesfully. Printing finished succesfully");
return true;
} catch (FileNotFoundException fileNotFoundException) {
logger.error("Could not find the port file : ",fileNotFoundException);
return false;
} catch (IOException ioException) {
logger.error("Couldnt send data to port due to : ",ioException);
return false;
}
}
}
and in SerialDriver class:
public synchronized OutputStream getOutputStream()
{
return this.getOutputStream();
}
... Any other ideas? :S
I'm trying a new approach meanwhile :)
Thanks :)
SerialDriver Constructor
PortID OK... Jumping to the other Constructor method...
SerialDriver(port) Method
DefaultPort: /dev/parport0
Open Method
This is the preferred port
Trying to open port with Javax...
Opened the port Successfully with Javax!!
Obtaining the OutputStream...
Error while printing to parallel printer port :
java.lang.IllegalStateExce
at com.sun.comm.LinuxParallel
at com.storecheck.detailconne
at com.storecheck.detailconne
at com.storecheck.detailconne
at com.storecheck.detailconne
at com.storecheck.detailconne
at javax.swing.AbstractButton
at javax.swing.AbstractButton
at javax.swing.DefaultButtonM
at javax.swing.DefaultButtonM
at javax.swing.plaf.basic.Bas
at java.awt.Component.process
at javax.swing.JComponent.pro
at java.awt.Component.process
at java.awt.Container.process
at java.awt.Component.dispatc
at java.awt.Container.dispatc
at java.awt.Component.dispatc
at java.awt.LightweightDispat
at java.awt.LightweightDispat
at java.awt.LightweightDispat
at java.awt.Container.dispatc
at java.awt.Window.dispatchEv
at java.awt.Component.dispatc
at java.awt.EventQueue.dispat
at java.awt.EventDispatchThre
at java.awt.EventDispatchThre
at java.awt.EventDispatchThre
at java.awt.EventDispatchThre
at java.awt.EventDispatchThre
Closing outputStream...
Here's the new code:
public static boolean printLPT(String datos[]) throws java.lang.NullPointerExcep
OutputStream outputStream = null;
try {
String OS = System.getProperty("os.nam
String defaultPort = SmartClientSettings.getIns
SerialDriver serial = null;
if (!OS.startsWith("Windows")
serial = new SerialDriver(defaultPort);
if(!serial.open()){
logger.info("Couldnt open the parallel port!");
return false;
}
}
logger.info(OS + ": " + defaultPort + " opened succesfully");
logger.info("Creating StringBuffer...");
StringBuffer yourText = new StringBuffer();
logger.info("Appending text");
for(int i=0; i < datos.length; i++){
if (datos[i] != null){
yourText.append(datos[i]);
}
}
logger.info(yourText);
logger.info("Converting to Bytes while replacing nulls");
byte[] bytes = yourText.toString().getByt
logger.info(bytes);
logger.info("Opening FileOutputStream");
outputStream = serial.getOutputStream();
logger.info("Writing to printer");
outputStream.write(bytes);
} catch (FileNotFoundException fileNotFoundException) {
logger.error("Could not find the port file : ",fileNotFoundException);
return false;
} catch (IOException ioException) {
logger.error("Couldnt send data to port due to : ",ioException);
return false;
}catch (Exception Exception) {
logger.error("Error while printing to parallel printer port : ",Exception);
return false;
}finally{
try{
logger.info("Closing outputStream...");
outputStream.close();
logger.info("outputStream Closed Succesfully. Printing finished succesfully");
return true;
} catch (FileNotFoundException fileNotFoundException) {
logger.error("Could not find the port file : ",fileNotFoundException);
return false;
} catch (IOException ioException) {
logger.error("Couldnt send data to port due to : ",ioException);
return false;
}
}
}
and in SerialDriver class:
public synchronized OutputStream getOutputStream()
{
return this.getOutputStream();
}
... Any other ideas? :S
I'm trying a new approach meanwhile :)
Thanks :)
I wonder why i do not see "Found 1 port" in your log, since in the serial.open(), there is this line:
while (portList.hasMoreElements( )) {
logger.info("Found 1 port");
portId = (CommPortIdentifier) portList.nextElement();
but if portList does not contain any ports, then where are we writing to?
Could you check that it really does create the outputstream in the serial.open()?
It's difficult to give advice without being able to insert some debug statements, so I'm trying my best by analyzing, sorry for the inconvenience.
Mark
while (portList.hasMoreElements(
logger.info("Found 1 port");
portId = (CommPortIdentifier) portList.nextElement();
but if portList does not contain any ports, then where are we writing to?
Could you check that it really does create the outputstream in the serial.open()?
It's difficult to give advice without being able to insert some debug statements, so I'm trying my best by analyzing, sorry for the inconvenience.
Mark
Tried:
CommPortIdentifier portIdentifier = CommPortIdentifier.getPort Identifier ( "COM1" ) ; // or whatever port name
CommPort port = portIdentifier.open ( "Your application name", 500 ) ; // app name and time out
InputStream is = port.getInputStream () ;
OutputStream os = port.getOutputStream () ;
?
CommPortIdentifier portIdentifier = CommPortIdentifier.getPort
CommPort port = portIdentifier.open ( "Your application name", 500 ) ; // app name and time out
InputStream is = port.getInputStream () ;
OutputStream os = port.getOutputStream () ;
?
ASKER
Dont worry Mark, i know you are really trying and i am too.
Sorry, i delete that lines of the log because it was already too long, but i post the entire one if you want...
portList Method
Finding ports ...
Found 1 port
Found 1 port
Found 1 port
Found 3 ports in this computer
AllPorts list: /dev/ttyS0:/dev/ttyS1:/dev /parport0
SerialDriver Constructor
PortID OK... Jumping to the other Constructor method...
SerialDriver(port) Method
DefaultPort: /dev/parport0
Open Method
Found 1 port
and its Serial
Found 1 port
and its Serial
Found 1 port
and its Parallel
This is the preferred port
Trying to open port with Javax...
Opened the port Successfully with Javax!!
Obtaining the OutputStream...
Error while printing to parallel printer port :
java.lang.IllegalStateExce ption: This port has not been opened yet
at com.sun.comm.LinuxParallel .getOutput Stream(Lin uxParallel .java:320)
at com.storecheck.detailconne ct.utils.S erialDrive r.open(Ser ialDriver. java:167)
at com.storecheck.detailconne ct.utils.T icketPrint er.printLP T(TicketPr inter.java :340)
at com.storecheck.detailconne ct.ui.pane ls.Setting sPanel.btn ProbarActi onPerforme d(Settings Panel.java :1447)
at com.storecheck.detailconne ct.ui.pane ls.Setting sPanel.acc ess$3100(S ettingsPan el.java:45 )
at com.storecheck.detailconne ct.ui.pane ls.Setting sPanel$19. actionPerf ormed(Sett ingsPanel. java:854)
at javax.swing.AbstractButton .fireActio nPerformed (AbstractB utton.java :1849)
at javax.swing.AbstractButton $Handler.a ctionPerfo rmed(Abstr actButton. java:2169)
at javax.swing.DefaultButtonM odel.fireA ctionPerfo rmed(Defau ltButtonMo del.java:4 20)
at javax.swing.DefaultButtonM odel.setPr essed(Defa ultButtonM odel.java: 258)
at javax.swing.plaf.basic.Bas icButtonLi stener.mou seReleased (BasicButt onListener .java:234)
at java.awt.Component.process MouseEvent (Component .java:5488 )
at javax.swing.JComponent.pro cessMouseE vent(JComp onent.java :3093)
at java.awt.Component.process Event(Comp onent.java :5253)
at java.awt.Container.process Event(Cont ainer.java :1966)
at java.awt.Component.dispatc hEventImpl (Component .java:3955 )
at java.awt.Container.dispatc hEventImpl (Container .java:2024 )
at java.awt.Component.dispatc hEvent(Com ponent.jav a:3803)
at java.awt.LightweightDispat cher.retar getMouseEv ent(Contai ner.java:4 212)
at java.awt.LightweightDispat cher.proce ssMouseEve nt(Contain er.java:38 92)
at java.awt.LightweightDispat cher.dispa tchEvent(C ontainer.j ava:3822)
at java.awt.Container.dispatc hEventImpl (Container .java:2010 )
at java.awt.Window.dispatchEv entImpl(Wi ndow.java: 1774)
at java.awt.Component.dispatc hEvent(Com ponent.jav a:3803)
at java.awt.EventQueue.dispat chEvent(Ev entQueue.j ava:463)
at java.awt.EventDispatchThre ad.pumpOne EventForHi erarchy(Ev entDispatc hThread.ja va:242)
at java.awt.EventDispatchThre ad.pumpEve ntsForHier archy(Even tDispatchT hread.java :163)
at java.awt.EventDispatchThre ad.pumpEve nts(EventD ispatchThr ead.java:1 57)
at java.awt.EventDispatchThre ad.pumpEve nts(EventD ispatchThr ead.java:1 49)
at java.awt.EventDispatchThre ad.run(Eve ntDispatch Thread.jav a:110)
Closing outputStream...
In my code, i Do call OutputStream os = port.getOutputStream () , but
i do NOT call InputStream is = port.getInputStream ()...
Do you want me to put that? Im trying it now?
The other lines (CommPortIdentifier portIdentifier = .... and CommPort port = portIdentifier.open ( "Your application ... ) are indeed used...
Thx :)
Sorry, i delete that lines of the log because it was already too long, but i post the entire one if you want...
portList Method
Finding ports ...
Found 1 port
Found 1 port
Found 1 port
Found 3 ports in this computer
AllPorts list: /dev/ttyS0:/dev/ttyS1:/dev
SerialDriver Constructor
PortID OK... Jumping to the other Constructor method...
SerialDriver(port) Method
DefaultPort: /dev/parport0
Open Method
Found 1 port
and its Serial
Found 1 port
and its Serial
Found 1 port
and its Parallel
This is the preferred port
Trying to open port with Javax...
Opened the port Successfully with Javax!!
Obtaining the OutputStream...
Error while printing to parallel printer port :
java.lang.IllegalStateExce
at com.sun.comm.LinuxParallel
at com.storecheck.detailconne
at com.storecheck.detailconne
at com.storecheck.detailconne
at com.storecheck.detailconne
at com.storecheck.detailconne
at javax.swing.AbstractButton
at javax.swing.AbstractButton
at javax.swing.DefaultButtonM
at javax.swing.DefaultButtonM
at javax.swing.plaf.basic.Bas
at java.awt.Component.process
at javax.swing.JComponent.pro
at java.awt.Component.process
at java.awt.Container.process
at java.awt.Component.dispatc
at java.awt.Container.dispatc
at java.awt.Component.dispatc
at java.awt.LightweightDispat
at java.awt.LightweightDispat
at java.awt.LightweightDispat
at java.awt.Container.dispatc
at java.awt.Window.dispatchEv
at java.awt.Component.dispatc
at java.awt.EventQueue.dispat
at java.awt.EventDispatchThre
at java.awt.EventDispatchThre
at java.awt.EventDispatchThre
at java.awt.EventDispatchThre
at java.awt.EventDispatchThre
Closing outputStream...
In my code, i Do call OutputStream os = port.getOutputStream () , but
i do NOT call InputStream is = port.getInputStream ()...
Do you want me to put that? Im trying it now?
The other lines (CommPortIdentifier portIdentifier = .... and CommPort port = portIdentifier.open ( "Your application ... ) are indeed used...
Thx :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Mmm never mind, i did it :D
with another code (mayankeagle helped me in another question)...
But now, i dont know what to do :S
Thanks a lot guys!
Nemo
with another code (mayankeagle helped me in another question)...
But now, i dont know what to do :S
Thanks a lot guys!
Nemo
You mean closing the ports in the finally block?
ASKER
The same code that i had with your corrections (yes, the finally block and more) worked fine with LPT printers, although the code is specifically for COM drivers.
:)
:)
:-)
byte[] bytes = yourText.toString().replac
you replace "null" inside a string with "".. so for example
"abcnulldef" becomes "abcdef".
I think you meant to write:
String myText = yourText.toString();
if(myText == null)
myText = "<nothing>";
byte[] bytes = myText.getBytes();
Mark