Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import jssc.SerialPort;
- import jssc.SerialPortEvent;
- import jssc.SerialPortEventListener;
- import jssc.SerialPortException;
- import java.math.BigInteger;
- import java.io.ByteArrayOutputStream;
- import com.openbravo.pos.printer.shtrihfr.fiscalprinter.*;
- public class Test {
- public static final byte ENQ = 0x05;
- public static final byte STX = 0x02;
- public static final byte ACK = 0x06;
- public static final byte NAK = 0x15;
- public static final long timeoutInMillis = 100;
- static SerialPort serialPort;
- public static void main(String[] args) {
- serialPort = new SerialPort("COM10");
- try {
- serialPort.openPort();//Open port
- serialPort.setParams(SerialPort.BAUDRATE_4800, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE, false, true);
- serialPort.addEventListener(new SerialPortReader());
- CommandOutputStream out = new CommandOutputStream("Cp1251"); // 0515 0205130100000017 06
- try {
- serialPort.writeByte(ENQ);
- }
- catch (Exception e) {
- System.out.println(e);
- }
- }
- catch (SerialPortException ex) {
- System.out.println(ex);
- }
- }
- /*
- */
- static class SerialPortReader implements SerialPortEventListener {
- public void serialEvent(SerialPortEvent event) {
- try {
- byte buffer[] = serialPort.readBytes(event.getEventValue());
- System.out.println(buffer);
- }
- catch (Exception e) {
- System.out.println(e);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement