嘿,我需要在热敏发票打印机中打印发票我编写了这个程序来做到这一点(见下文)但是,出于本地化原因,我需要将值范围为 0x80 – 0x102 的字符发送到打印机,但我发现这是不可能的,因为我无法发送具有此值的字节(这是 Java 中不存在的无符号字节)
关于如何将此值添加到将发送到打印机的字符串的任何想法???谢谢
import gnu.io.CommPortIdentifier;
import gnu.io.NoSuchPortException;
import gnu.io.PortInUseException;
import gnu.io.SerialPort;
import gnu.io.UnsupportedCommOperationException;
import java.io.IOException;
import java.io.OutputStream;
public class SimpleWrite {
static CommPortIdentifier portId;
static SerialPort serialPort;
static OutputStream outputStream;
public static void print(String messageString){
try {
portId = CommPortIdentifier.getPortIdentifier( "COM1");
serialPort = (SerialPort) portId.open("SimpleWrite", 2000);
outputStream = serialPort.getOutputStream();
serialPort.setSerialPortParams( 9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
outputStream.write(messageString.getBytes());
serialPort.close();
}catch (IOException e) { System.out.println(e.getMessage());
}catch (PortInUseException e) { System.out.println(e.getMessage());
}catch (UnsupportedCommOperationException e) { System.out.println(e.getMessage());
}catch (NoSuchPortException e) { System.out.println(e.getMessage());}
}
public static void main(String[] args) throws IOException{
print("Hello , world \n\r");
}
}