Advertisement
Guest User

Untitled

a guest
Feb 26th, 2015
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.67 KB | None | 0 0
  1. import jssc.SerialPort;
  2. import jssc.SerialPortEvent;
  3. import jssc.SerialPortEventListener;
  4. import jssc.SerialPortException;
  5. import java.math.BigInteger;
  6.  
  7. import java.io.ByteArrayOutputStream;
  8. import com.openbravo.pos.printer.shtrihfr.fiscalprinter.*;
  9.  
  10. public class Test {
  11.     public static final byte ENQ = 0x05;
  12.     public static final byte STX = 0x02;
  13.     public static final byte ACK = 0x06;
  14.     public static final byte NAK = 0x15;
  15.     public static final long timeoutInMillis = 100;
  16.  
  17.     static SerialPort serialPort;
  18.  
  19.     public static void main(String[] args) {
  20.         serialPort = new SerialPort("COM10");
  21.         try {
  22.             serialPort.openPort();//Open port
  23.             serialPort.setParams(SerialPort.BAUDRATE_4800, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE, false, true);
  24.             serialPort.addEventListener(new SerialPortReader());
  25.  
  26.             CommandOutputStream out = new CommandOutputStream("Cp1251"); // 0515 0205130100000017 06
  27.  
  28.  
  29.             try {
  30.                 serialPort.writeByte(ENQ);
  31.             }
  32.             catch (Exception e) {
  33.                 System.out.println(e);
  34.             }
  35.         }
  36.         catch (SerialPortException ex) {
  37.             System.out.println(ex);
  38.         }
  39.     }
  40.  
  41.     /*
  42.      */
  43.     static class SerialPortReader implements SerialPortEventListener {
  44.  
  45.         public void serialEvent(SerialPortEvent event) {
  46.             try {
  47.                 byte buffer[] = serialPort.readBytes(event.getEventValue());
  48.  
  49.                 System.out.println(buffer);
  50.             }
  51.             catch (Exception e) {
  52.                 System.out.println(e);
  53.             }
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement