Skip to content

Instantly share code, notes, and snippets.

@HashRaygoza
Created January 29, 2018 22:30
Show Gist options
  • Save HashRaygoza/624f3d81d85eccb91d4929e9d8c24928 to your computer and use it in GitHub Desktop.
Save HashRaygoza/624f3d81d85eccb91d4929e9d8c24928 to your computer and use it in GitHub Desktop.
package mx.hash.print;
import jssc.SerialPort;
import jssc.SerialPortException;
public class PrinterTest {
public static void main(String[] args) {
SerialPort serialPort = new SerialPort("COM7");
try {
// Esto funciona
serialPort.openPort();//Open serial port
serialPort.setParams(SerialPort.BAUDRATE_9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);//Set params. Also you can set params by this string: serialPort.setParams(9600, 8, 1, 0);
for (int i = 0; i < 10; i++) {
serialPort.writeBytes("¡¡Hola Mundo!!\n".getBytes());//Write data to port
}
serialPort.closePort();//Close serial port
} catch (SerialPortException ex) {
System.out.println(ex);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment