问题描述
||
嘿,
我需要在热发票打印机中打印发票
我写了这个程序来做到这一点(见下文)
但是,由于本地化的原因,我需要将值范围为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\");
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)