December 21, 2014

Programme VFD Display using java source code. Using RXTX drivers.

Programme VFD  display using java source code

This post is about how to program VFD display using java.This code is specified for COM port.Here you need to download hardware acceleration supports from external supports.Follow given steps and refer the correct documentation related to your vfd device and replace correct byte code for given functionalities.

STEP 1: 
This VFD Customer Display has Serial cabel.So Download serial port drivers from this link 
http://sangon.altervista.org/bin/mfz-rxtx-2.2-20081207-win-x86.zip

STEP 2: 

 Unzip archive file and read instructions inside install.txt file. Follow instructions and copy files into mentioned directories.

STEP 3:

 If you use IDE like netbeans or eclips, Import RXTXcomm.jar file into lib or library folder. 

STEP 4:

 Now your computer is ready to run this class.Now install you customer display manufacture's driver package.Restart your computer.

STEP 5: 

Now you had to configure your display's basic settings for COM1.
    Baud Rate:          9600
   Data Bits:            8
   Parity:                None
   Stop Bits:           1
   Flow Control:   None
For that you can use driver application or switch system of display.
STEP 6:  
 Undestanding command mode.
basic command modes:                            1.   EPSON ESC/POS
                                                                    2.   EMAX (AEDEX)
                                                                    3.   UTC
                                                                    4.   ADM787/788
                                                                   5.   CD5220
                                                                   6.   DSP-800 (optional)
Here we use EPSON ESC/POS command system.First download user manual of your display.Inside manual you can find commands relevent to your display.
Ex: show timer on display Hex code :  1F  55
we need to convert this hex code to byte array like this 
byte time [ ]={0x1F,0x55};
STEP 7:
Download Display.java file and ESC/POS.java file from github and execute your programe.
STEP 8:
Enjoy java programming.


I like to expand this tutorial to tell you how to program a USB display.Please see the below code.
credit : CristianoGhersi
import gnu.io.*;
import java.io.*;
import java.util.Enumeration;
import java.io.IOException;
/**
* This class provides the utilities to read the data exchanged via USB port.
*/
public class USBComm implements SerialPortEventListener {
/**
* Stream for the storage of incoming data
*/
private InputStream inputStream;
/**
* Stream for the dispatching of data
*/
private OutputStream outputStream;
/**
* Timeout of the USB port
*/
private final int PORT_TIMEOUT = 2000;
/**
* Representation of the serial port used for the communication
*/
private SerialPort serialPort;
/**
* Buffer that stores the received bytes from the media
*/
protected LinkedBlockingQueue<Byte> receivedBytes;
/**
* Builds a new manager for the communication via USB port.
* @exception IOException if an error occurred during the opening of the USB port
*/
public USBComm() throws IOException {
receivedBytes = new LinkedBlockingQueue<Byte>(100000);
String port = "COM1"; //place the right COM port here, OS dependent
//Check that the USB port exists and is recognized:
Enumeration<?> portList = CommPortIdentifier.getPortIdentifiers();
boolean portFound = false;
CommPortIdentifier portId = null;
while (portList.hasMoreElements()) {
portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
System.out.println.info(portId.getName());
if (portId.getName().equals(port)) {
System.out.println("Found port: " + port);
portFound = true;
break;
}
}
}
if (!portFound)
throw new IOException("port " + port + " not found.");
try {
System.out.println("USB port opening...");
serialPort = (SerialPort) portId.open("USBCommunicator", PORT_TIMEOUT);
System.out.println("USB port opened");
inputStream = serialPort.getInputStream();
outputStream = serialPort.getOutputStream();
serialPort.addEventListener(this);
serialPort.notifyOnDataAvailable(true);
// WARNING! - DO NOT SET THE FOLLOWING PROPERTY WITH RXTX LIBRARY
//***************** serialPort.notifyOnOutputEmpty(true);***************************
//wait for a while to leave the time to javax.comm to
//correctly configure the port:
Thread.sleep(1000);
int baudRate = 115200; //set according your display
serialPort.setSerialPortParams(baudRate,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
System.out.println("setted SerialPortParams");
} catch (Exception e) {
System.err.println(e.getMessage());
throw new IOException(e.getMessage());
}
}
public void closeUSB(){
//close the streams for serial port:
try {
inputStream.close();
outputStream.close();
} catch (IOException e) {
System.err.println("Cannot close streams:" + e.getMessage(), e);
}
}
/**
* Listener for USB events
*
* @param event new event occurred on the USB port
*/
public void serialEvent(SerialPortEvent event){
switch (event.getEventType()) {
case SerialPortEvent.BI:
case SerialPortEvent.OE:
case SerialPortEvent.FE:
case SerialPortEvent.PE:
case SerialPortEvent.CD:
case SerialPortEvent.CTS:
case SerialPortEvent.DSR:
case SerialPortEvent.RI:
case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
//nothing to do...
break;
case SerialPortEvent.DATA_AVAILABLE:
byte received = -1;
do {
try {
received = (byte)inputStream.read();
} catch (IOException e) {
System.err.println("Error reading USB:" + e.getMessage());
}
synchronized (receivedBytes) {
try {
receivedBytes.add(received);
} catch (IllegalStateException ew) {
System.err.println(ew.getMessage());
receivedBytes.poll();
receivedBytes.add(received);
}
}
} while(received != -1);
break;
}
}
protected void write(byte[] buffer){
try {
outputStream.write(buffer);
outputStream.flush();
} catch (IOException e) {
System.err.println("Cannot write:" + e.getMessage());
}
}
}
view raw USBComm.java hosted with ❤ by GitHub

Related Posts:

7 comments:

  1. Thanks for the POST . but how can we change this code for USB port (when the customer display unit connected with USB port)..please help !!

    ReplyDelete
  2. Thanks yaluwa. This post was very usefull.

    ReplyDelete
  3. Wonderful post, till system thankful to all your team for sharing such best information about EPOS systems.

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete

Leave your comment and feedback here for me