Beruflich Dokumente
Kultur Dokumente
/**
*/
package in2.pos;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.Properties;
import java.util.ResourceBundle;
import java.util.StringTokenizer;
import javax.swing.JOptionPane;
import oracle.forms.handler.IHandler;
import oracle.forms.properties.ID;
import oracle.forms.ui.CustomEvent;
import oracle.forms.ui.VBean;
import gnu.io.*;
/**
*/
SerialPort serialPort;
OutputStream os;
InputStream is;
CommPortIdentifier portId;
Enumeration portList;
IHandler mHandler;
char EOT = 4;
char ACK = 6;
char FS = 28;
// port
// (COM1,COM2,COM3,...)
// the
// transaction
// (12)
// ticket duplicate
long l_timeout;
byte b_retry = 0;
byte[] readBuffer = new byte[2000]; //2000 bytes buffer to read rs232 stream
// (COM1,COM2,...)
String transactionProcessed;
String transactionFlag;
String transactionDate;
String transactionTime;
String transactionBatchNumber;
String terminalTid;
String terminalCard;
String errDesc;
public PosTerminalPjc() {
super();
System.out.println("============================");
System.out.println("============================");
try {
res.load(this.getClass().getResourceAsStream(
+ ex.toString());
String phase = null; // initial null value for state machine phase
if (getComPort().trim().equalsIgnoreCase("")) {
this.showError(res.getProperty("s_dlg_err_title"),
res.getProperty("s_com_invalid"));
return;
System.out.println(this.getTransactionType());
if (!getTransactionType().equalsIgnoreCase("REFUND")
& !getTransactionType().equalsIgnoreCase("SALE")) {
this.showError(res.getProperty("s_dlg_err_title"),
res.getProperty("s_tran_invalid_type"));
return;
portList = portId.getPortIdentifiers();
while (portList.hasMoreElements()) {
if (portId.getName().equalsIgnoreCase(this.getComPort())) {
+ portId.isCurrentlyOwned());
SerialPort.STOPBITS_1, SerialPort.PARITY_EVEN);
// serialPort.addEventListener(this);
serialPort.notifyOnDataAvailable(true);
serialPort.notifyOnOutputEmpty(true);
os = serialPort.getOutputStream();
is = serialPort.getInputStream();
break;
if (portId == null) {
+ this.getComPort() + "\n");
while (true) {
if (phase == null) {
System.out.println("start phase");
if (getTransactionType().equalsIgnoreCase("SALE")) {
+ FS + "+0" + FS + "978" + FS + FS + FS + FS + FS
+ FS + FS + ETX);
else if (getTransactionType().equalsIgnoreCase("REFUND")) {
+ FS + FS + "+0" + FS + "978" + FS + FS + FS + FS
+ FS + FS + FS + ETX);
} else {
os.write(req);
os.flush();
try {
Thread.sleep(500);
} catch (Exception ee) {
phase = "TO_POS_ACK";
}//phase null
if (phase.equalsIgnoreCase("TO_POS_ACK") &
b_retry += 1;
if (b_retry >= 4) {
System.out.println("Timeout occured");
try {
serialPort.close();
is.close();
os.close();
}
//Timeout occured show error
//s_timeout
this.showError(res.getProperty("s_dlg_err_title"),
res.getProperty("s_timeout"));
break;
if (phase.equalsIgnoreCase("TO_POS_ACK") &
try {
int numBytes = 0;
dataValue = "";
if (dataValue.getBytes().length > 0) {
dataValue.getBytes()[0]);
dataValue.getBytes().length);
//check for ack byte
if (dataValue.getBytes()[0] == 6) {
System.out.println(
phase = "WAIT_FOR_TRANSACTION";
l_timeout = System.currentTimeMillis() +
l_wait_for_transaction;
if (phase.equalsIgnoreCase("WAIT_FOR_TRANSACTION") &
System.out.println(
try {
serialPort.close();
is.close();
os.close();
}
this.showError(res.getProperty("s_dlg_err_title"),
res.getProperty("s_response_error"));
break;
//WAIT FOR SOME DATA TO COME FROM POS TERMINAL OVER RS232
if (phase.equalsIgnoreCase("WAIT_FOR_TRANSACTION")) {
try {
int numBytes = 0;
dataValue = "";
if (dataValue.getBytes().length > 0) {
dataValue.getBytes()[0] + "|" +
dataValue.getBytes()[1]);
dataValue.getBytes().length);
if (dataValue.indexOf("PREKINIL UPORABNIK") != -1) {
System.out.println(
try {
serialPort.close();
is.close();
os.close();
this.showError(res.getProperty("s_dlg_err_title"),
res.getProperty("s_user_cancel"));
break;
System.out.println("Napacen vnos");
try {
serialPort.close();
is.close();
os.close();
} catch (Exception ee) {
this.showError(res.getProperty("s_dlg_err_title"),
res.getProperty("s_user_invalid_entry"));
break;
continue;
if (dataValue.indexOf("SPREJETO") != -1) {
try {
serialPort.close();
is.close();
os.close();
System.out.println(dataValue);
System.out.println("Proimo event v formse");
this.transactionProcessed = dataValue.substring(1,
3); //podatek mora biti 10
this.transactionBatchNumber = dataValue.substring(21,
25);
System.out.println(st.nextToken());
System.out.println(st.nextToken());
System.out.println(st.nextToken());
System.out.println(st.nextToken());
System.out.println(st.nextToken());
System.out.println(st.nextToken());
this.terminalTid = st.nextToken();
System.out.println(st.nextToken());
System.out.println(st.nextToken());
System.out.println(st.nextToken());
this.terminalCard = st.nextToken();
if (transactionProcessed.equalsIgnoreCase("10")) {
else
EVT_ERR);
if (transactionProcessed.equalsIgnoreCase("00")) {
System.out.println(
this.errDesc = res.getProperty("s_tf_00");
} else if (transactionProcessed.equalsIgnoreCase(
"01")) {
System.out.println(
this.errDesc = res.getProperty("s_tf_01");
} else if (transactionProcessed.equalsIgnoreCase(
"02")) {
System.out.println(
this.errDesc = res.getProperty("s_tf_02");
} else if (transactionProcessed.equalsIgnoreCase(
"03")) {
this.errDesc = res.getProperty("s_tf_03");
} else if (transactionProcessed.equalsIgnoreCase(
"04")) {
System.out.println("Transaction refused");
this.errDesc = res.getProperty("s_tf_04");
} else if (transactionProcessed.equalsIgnoreCase(
"05")) {
System.out.println(
this.errDesc = res.getProperty("s_tf_05");
} else if (transactionProcessed.equalsIgnoreCase(
"06")) {
System.out.println(
this.errDesc = res.getProperty("s_tf_06");
dispatchCustomEvent(ce);
return;
dispatchCustomEvent(ce);
return;
}
}
//wait 200 ms
try {
Thread.sleep(200);
ex.printStackTrace();
System.out.print('*');
/**
* @param data
* @return byte[]
*/
System.out.print(tmp.getBytes()[i] + ":");
return tmp.getBytes();
/**
* @param packet
* @return String
*/
if (s == null) {
return s;
if (add <= 0) {
return s;
Arrays.fill(ch, c);
if (paddingLeft) {
str.insert(0, ch);
} else {
str.append(ch);
return str.toString();
}
/**
* @param title
* @param exceptionString
*/
return comPort;
this.comPort = comPort;
return transactionType;
this.transactionType = transactionType;
}
return amount;
this.amount = amount;
return transactionNumber;
this.transactionNumber = transactionNumber;
pjc.setComPort("COM1");
pjc.setTransactionType("SALE");
pjc.setAmount("1000");
try
pjc.doTransaction();
}
catch(Exception ex)
System.err.println(ex.toString());
[/code]