5.0 Source Code

Committing 5.0 Source Code
This commit is contained in:
2023-04-06 18:58:04 +01:00
parent 0f3ede77fa
commit 0282345603
1680 changed files with 241310 additions and 0 deletions
@@ -0,0 +1,106 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.pos.scale;
import com.unicenta.pos.forms.AppLocal;
import com.unicenta.pos.forms.AppProperties;
import com.unicenta.pos.util.StringParser;
import java.awt.Component;
/**
*
* @author JG uniCenta
*/
public class DeviceScale {
private Scale m_scale;
/** Creates a new instance of DeviceScale
* @param parent
* @param props */
public DeviceScale(Component parent, AppProperties props) {
StringParser sd = new StringParser(props.getProperty("machine.scale"));
String sScaleType = sd.nextToken(':');
String sScaleParam1 = sd.nextToken(',');
// String sScaleParam2 = sd.nextToken(',');
switch (sScaleType) {
case "acompc100":
m_scale = new ScaleAcomPC100(sScaleParam1);
break;
case "averyberkel6720":
m_scale = new ScaleAvery(sScaleParam1);
break;
case "casiopd1":
m_scale = new ScaleCasioPD1(sScaleParam1);
break;
case "dialog1":
m_scale = new ScaleComm(sScaleParam1);
break;
case "samsungesp":
m_scale = new ScaleSamsungEsp(sScaleParam1);
break;
case "caspdii":
m_scale = new ScaleCASPDII(sScaleParam1);
break;
case "fake":
// a fake scale for debugging purposes
m_scale = new ScaleFake();
break;
case "screen":
// on screen scale
m_scale = new ScaleDialog(parent);
break;
default:
m_scale = null;
break;
}
}
/**
*
* @return
*/
public boolean existsScale() {
return m_scale != null;
}
/**
*
* @return
* @throws ScaleException
*/
public Double readWeight() throws ScaleException {
if (m_scale == null) {
throw new ScaleException(AppLocal.getIntString("scale.notdefined"));
} else {
Double result = m_scale.readWeight();
if (result == null) {
return null; // Canceled by the user / scale
} else if (result < 0.002) {
// invalid result. nothing on the scale
throw new ScaleException(AppLocal.getIntString("scale.invalidvalue"));
} else {
// valid result
return result;
}
}
}
}
@@ -0,0 +1,34 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.pos.scale;
/**
*
* @author JG uniCenta
*/
public interface Scale {
/**
*
* @return
* @throws ScaleException
*/
public Double readWeight() throws ScaleException;
}
@@ -0,0 +1,181 @@
//    uniCenta oPOS  - Touch Friendly Point Of Sale
//    Copyright (c) 2018 uniCenta & previous Openbravo POS works
// Contribution by Hajinder Singh
//    https://unicenta.com
//
//    This file is part of uniCenta oPOS
//
//    uniCenta oPOS is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//   uniCenta oPOS is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with uniCenta oPOS.  If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.pos.scale;
import gnu.io.*;
import java.io.*;
import java.util.TooManyListenersException;
/**
*
* @author uniCenta + H Singh
*/
public class ScaleAcomPC100 implements Scale, SerialPortEventListener {
private CommPortIdentifier m_PortIdPrinter;
private SerialPort m_CommPortPrinter;
private final String m_sPortScale;
private OutputStream m_out;
private InputStream m_in;
private static final int SCALE_READY = 0;
private static final int SCALE_READING = 1;
private static final int SCALE_READINGDECIMALS = 2;
private double m_dWeightBuffer;
private double m_dWeightDecimals;
private int m_iStatusScale;
private String m_sScaleReading;
/** Creates a new instance of ScaleComm
* @param sPortPrinter */
public ScaleAcomPC100(String sPortPrinter) {
m_sPortScale = sPortPrinter;
m_out = null;
m_in = null;
m_iStatusScale = SCALE_READY;
m_dWeightBuffer = 0.0;
m_dWeightDecimals = 1.0;
}
/**
*
* @return
*/
@Override
public Double readWeight() {
synchronized(this) {
if (m_iStatusScale != SCALE_READY) {
try {
wait(200);
} catch (InterruptedException e) {
}
if (m_iStatusScale != SCALE_READY) {
m_iStatusScale = SCALE_READY;
}
}
m_dWeightBuffer = 0.0;
m_dWeightDecimals = 1.0;
write(new byte[] {0x57,0X0D}); // $
flush();
try {
wait(200);
} catch (InterruptedException e) {
}
if (m_iStatusScale == SCALE_READY) {
double dWeight = m_dWeightBuffer / m_dWeightDecimals;
m_dWeightBuffer = 0.0;
m_dWeightDecimals = 1.0;
return dWeight;
} else {
m_iStatusScale = SCALE_READY;
m_dWeightBuffer = 0.0;
m_dWeightDecimals = 1.0;
return 0.0;
}
}
}
private void flush() {
try {
m_out.flush();
} catch (IOException e) {
}
}
private void write(byte[] data) {
try {
if (m_out == null) {
m_PortIdPrinter = CommPortIdentifier.getPortIdentifier(m_sPortScale);
m_CommPortPrinter = (SerialPort) m_PortIdPrinter.open("PORTID", 2000);
m_out = m_CommPortPrinter.getOutputStream();
m_in = m_CommPortPrinter.getInputStream();
m_CommPortPrinter.addEventListener(this);
m_CommPortPrinter.notifyOnDataAvailable(true);
m_CommPortPrinter.setSerialPortParams(9600,
SerialPort.DATABITS_7,
SerialPort.STOPBITS_1,
SerialPort.PARITY_EVEN);
}
m_out.write(data);
} catch (NoSuchPortException | PortInUseException | UnsupportedCommOperationException
| TooManyListenersException | IOException e) {
}
}
/**
*
* @param e
*/
@Override
public void serialEvent(SerialPortEvent e) {
switch (e.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:
break;
case SerialPortEvent.DATA_AVAILABLE:
try {
int i;
i = m_in.available();
byte[] readBuffer = new byte[i];
if (i > 0) {
m_in.read(readBuffer);
}
m_sScaleReading = m_sScaleReading + new String(readBuffer);
try {
int start = m_sScaleReading.indexOf((char) 10);
int end = m_sScaleReading.indexOf((char) 3);
if (start >= 0 && end >= 0) {
start = m_sScaleReading.indexOf((char) 10);
end = m_sScaleReading.indexOf((char) 75);
m_dWeightBuffer = Double.parseDouble(m_sScaleReading.substring(start+1, end));
m_sScaleReading = "";
}
} catch (IndexOutOfBoundsException ex) {
System.out.println("IndexOutOfBoundsException, message not complete yet. Waiting for more data.");
}
} catch (IOException eIO) {}
break;
}
}
}
@@ -0,0 +1,195 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
/*
* uniCenta Feb 2017
* Original code supplied Ryan Airey Feb 2017
*/
package com.unicenta.pos.scale;
import gnu.io.*;
import java.io.*;
import java.util.TooManyListenersException;
public class ScaleAvery implements Scale, SerialPortEventListener {
private CommPortIdentifier m_PortIdPrinter;
private SerialPort m_CommPortPrinter;
private String m_sPortScale;
private OutputStream m_out;
private InputStream m_in;
private static final int SCALE_READY = 0;
private static final int SCALE_READING = 1;
private static final int SCALE_READINGDECIMALS = 2;
private static int SCALE_NOMORE = 1;
private double m_dWeightBuffer;
private double m_dWeightDecimals;
private int m_iStatusScale;
public ScaleAvery(String sPortPrinter) {
m_sPortScale = sPortPrinter;
m_out = null;
m_in = null;
m_iStatusScale = SCALE_READY;
m_dWeightBuffer = 0.0;
m_dWeightDecimals = 1.0;
}
@Override
public Double readWeight() {
synchronized(this) {
if (m_iStatusScale != SCALE_READY) {
try {
wait(1000);
} catch (InterruptedException e) {
}
if (m_iStatusScale != SCALE_READY) {
m_iStatusScale = SCALE_READY;
}
}
m_dWeightBuffer = 0.0;
m_dWeightDecimals = 1.0;
// Send command to get data from scale
write(new byte[] {0x0057});
flush();
write(new byte[] {0x000D});
try {
wait(1000);
} catch (InterruptedException e) {
}
if (m_iStatusScale == SCALE_READY) {
double dWeight = m_dWeightBuffer / m_dWeightDecimals;
// System.out.println(" ----- ScaleAvery : readWeight --- if ------ "+dWeight);
m_dWeightBuffer = 0.0;
m_dWeightDecimals = 1.0;
return dWeight;
} else {
m_iStatusScale = SCALE_READY;
m_dWeightBuffer = 0.0;
m_dWeightDecimals = 1.0;
return 0.0;
}
}
}
private void flush() {
try {
m_out.flush();
} catch (IOException e) {
}
}
private void write(byte[] data) {
try {
if (m_out == null) {
m_PortIdPrinter = CommPortIdentifier.getPortIdentifier(m_sPortScale);
m_CommPortPrinter = (SerialPort) m_PortIdPrinter.open("PORTID", 2000);
m_out = m_CommPortPrinter.getOutputStream();
m_in = m_CommPortPrinter.getInputStream();
m_CommPortPrinter.addEventListener(this);
m_CommPortPrinter.notifyOnDataAvailable(true);
m_CommPortPrinter.setSerialPortParams(9600,
SerialPort.DATABITS_7,
SerialPort.STOPBITS_1,
SerialPort.PARITY_EVEN);
}
m_out.write(data);
} catch (NoSuchPortException | PortInUseException
| UnsupportedCommOperationException | TooManyListenersException
| IOException e) {
// System.out.println(" Exception While Writing the Data, Might be Serial Dll Missing or COM Port not Supported, Or COM Port already in use");
}
}
@Override
public void serialEvent(SerialPortEvent e) {
switch (e.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:
break;
case SerialPortEvent.DATA_AVAILABLE:
try {
while (m_in.available() > 0) {
int b = m_in.read();
if (b==0x0003 || b==3) {
synchronized (this) {
SCALE_NOMORE = 1;
m_iStatusScale = SCALE_READY;
notifyAll(); }
} else if (b == 0x004C || b==76) {
synchronized (this) {
SCALE_NOMORE = 0; }
} else if (SCALE_NOMORE==0){
m_iStatusScale = SCALE_READY;
} else if (b > 0x002F
&& b < 0x003A
&& SCALE_NOMORE==1
|| b == 0x002E) {
synchronized(this) {
if (m_iStatusScale == SCALE_READY) {
m_dWeightBuffer = 0.0;
m_dWeightDecimals = 1.0;
m_iStatusScale = SCALE_READING;
}
if (b == 0x002E) {
m_iStatusScale = SCALE_READINGDECIMALS;
} else {
m_dWeightBuffer = m_dWeightBuffer * 10.0 + b - 0x0030;
if (m_iStatusScale == SCALE_READINGDECIMALS) {
m_dWeightDecimals *= 10.0;
}
}
}
} else {
m_dWeightBuffer = 0.0;
m_dWeightDecimals = 1.0;
m_iStatusScale = SCALE_READY;
}
}
} catch (IOException eIO) {
// System.out.println(" Error At serialEvent due to unknowen response data from scale ");
}
break;
}
}
}
@@ -0,0 +1,178 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta
// https://unicenta.com/
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.pos.scale;
import gnu.io.*;
import java.io.*;
import java.util.TooManyListenersException;
public class ScaleCASPDII implements Scale, SerialPortEventListener {
private CommPortIdentifier m_PortIdPrinter;
private SerialPort m_CommPortPrinter;
private final String m_sPortScale;
private OutputStream m_out;
private InputStream m_in;
private static final int SCALE_READY = 0;
private static final int SCALE_READING = 1;
private static final int SCALE_READINGDECIMALS = 2;
private double m_dWeightBuffer;
private double m_dWeightDecimals;
private int m_iStatusScale;
/** Creates a new instance of ScaleComm
* @param sPortPrinter */
public ScaleCASPDII(String sPortPrinter) {
m_sPortScale = sPortPrinter;
m_out = null;
m_in = null;
m_iStatusScale = SCALE_READY;
m_dWeightBuffer = 0.0;
m_dWeightDecimals = 1.0;
}
@Override
public Double readWeight() {
synchronized(this) {
if (m_iStatusScale != SCALE_READY) {
try {
wait(1000);
} catch (InterruptedException e) {
}
if (m_iStatusScale != SCALE_READY) {
m_iStatusScale = SCALE_READY;
}
}
m_dWeightBuffer = 0.0;
m_dWeightDecimals = 1.0;
write(new byte[] {0x57});
flush();
try {
wait(1000);
} catch (InterruptedException e) {
}
if (m_iStatusScale == SCALE_READY) {
double dWeight = m_dWeightBuffer / m_dWeightDecimals;
m_dWeightBuffer = 0.0;
m_dWeightDecimals = 1000.0;
return dWeight;
} else {
m_iStatusScale = SCALE_READY;
m_dWeightBuffer = 0.0;
m_dWeightDecimals = 1000.0;
return 0.0;
}
}
}
private void flush() {
try {
m_out.flush();
} catch (IOException e) {
}
}
private void write(byte[] data) {
try {
if (m_out == null) {
m_PortIdPrinter = CommPortIdentifier.getPortIdentifier(m_sPortScale);
m_CommPortPrinter = (SerialPort) m_PortIdPrinter.open("PORTID", 1000);
m_out = m_CommPortPrinter.getOutputStream();
m_in = m_CommPortPrinter.getInputStream();
m_CommPortPrinter.addEventListener(this);
m_CommPortPrinter.notifyOnDataAvailable(true);
m_CommPortPrinter.setSerialPortParams(9600,
SerialPort.DATABITS_7,
SerialPort.STOPBITS_1,
SerialPort.PARITY_EVEN);
}
m_out.write(data);
} catch (NoSuchPortException |
PortInUseException |
UnsupportedCommOperationException |
TooManyListenersException |
IOException e) {
}
}
@Override
public void serialEvent(SerialPortEvent e) {
switch (e.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:
break;
case SerialPortEvent.DATA_AVAILABLE:
try {
while (m_in.available() > 0) {
int b = m_in.read();
if (b == 0x000D) {
synchronized (this) {
m_iStatusScale = SCALE_READY;
notifyAll();
}
} else if ((b > 0x002F && b < 0x003A) || b == 0x002E){
synchronized(this) {
if (m_iStatusScale == SCALE_READY) {
m_dWeightBuffer = 0.0;
m_dWeightDecimals = 1000.0;
m_iStatusScale = SCALE_READING;
}
if (b == 0x002E) {
m_iStatusScale = SCALE_READINGDECIMALS;
} else {
m_dWeightBuffer = m_dWeightBuffer * 10.0 + b - 0x0030;
if (m_iStatusScale == SCALE_READINGDECIMALS) {
m_dWeightDecimals *= 10.0;
}
}
}
} else {
m_dWeightBuffer = 0.0;
m_dWeightDecimals = 1000.0;
m_iStatusScale = SCALE_READY;
}
}
} catch (IOException eIO) {}
break;
}
}
}
@@ -0,0 +1,202 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.pos.scale;
import gnu.io.*;
import java.io.*;
import java.util.TooManyListenersException;
/**
*
* @author JG uniCenta
*/
public class ScaleCasioPD1 implements Scale, SerialPortEventListener {
private CommPortIdentifier m_PortIdPrinter;
private SerialPort m_CommPortPrinter;
private String m_sPortScale;
private OutputStream m_out;
private InputStream m_in;
private static final int SCALE_READY = 0;
private static final int SCALE_READING = 1;
private static final int SCALE_READINGDECIMALS = 2;
private static int SCALE_NOMORE = 1;
private double m_dWeightBuffer;
private double m_dWeightDecimals;
private int m_iStatusScale;
/** Creates a new instance of ScaleComm
* @param sPortPrinter */
public ScaleCasioPD1(String sPortPrinter) {
m_sPortScale = sPortPrinter;
m_out = null;
m_in = null;
m_iStatusScale = SCALE_READY;
m_dWeightBuffer = 0.0;
m_dWeightDecimals = 1.0;
}
/**
*
* @return
*/
@Override
public Double readWeight() {
synchronized(this) {
if (m_iStatusScale != SCALE_READY) {
try {
wait(1000);
} catch (InterruptedException e) {
}
if (m_iStatusScale != SCALE_READY) {
// bascula tonta.
m_iStatusScale = SCALE_READY;
}
}
m_dWeightBuffer = 0.0;
m_dWeightDecimals = 1.0;
write(new byte[] {0x0057});
flush();
write(new byte[] {0x000D});
// Esperamos un ratito
try {
wait(1000);
} catch (InterruptedException e) {
}
if (m_iStatusScale == SCALE_READY) {
double dWeight = m_dWeightBuffer / m_dWeightDecimals;
m_dWeightBuffer = 0.0;
m_dWeightDecimals = 1.0;
return dWeight;
} else {
m_iStatusScale = SCALE_READY;
m_dWeightBuffer = 0.0;
m_dWeightDecimals = 1.0;
return 0.0;
}
}
}
private void flush() {
try {
m_out.flush();
} catch (IOException e) {
}
}
private void write(byte[] data) {
try {
if (m_out == null) {
m_PortIdPrinter = CommPortIdentifier.getPortIdentifier(m_sPortScale);
m_CommPortPrinter = (SerialPort) m_PortIdPrinter.open("PORTID", 2000);
m_out = m_CommPortPrinter.getOutputStream();
m_in = m_CommPortPrinter.getInputStream();
m_CommPortPrinter.addEventListener(this);
m_CommPortPrinter.notifyOnDataAvailable(true);
m_CommPortPrinter.setSerialPortParams(9600,
SerialPort.DATABITS_7,
SerialPort.STOPBITS_1,
SerialPort.PARITY_EVEN);
}
m_out.write(data);
} catch (NoSuchPortException | PortInUseException | UnsupportedCommOperationException | TooManyListenersException | IOException e) {
}
}
/**
*
* @param e
*/
@Override
public void serialEvent(SerialPortEvent e) {
// Determine type of event.
switch (e.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:
break;
case SerialPortEvent.DATA_AVAILABLE:
try {
while (m_in.available() > 0) {
int b = m_in.read();
if (b==0x0003 || b==3) {
synchronized (this) {
SCALE_NOMORE = 1;
m_iStatusScale = SCALE_READY;
notifyAll();
}
}else if (b == 0x004C || b==76) {
synchronized (this) {
SCALE_NOMORE = 0;
}
}else if (SCALE_NOMORE==0){
m_iStatusScale = SCALE_READY;
}else if (b > 0x002F && b < 0x003A && SCALE_NOMORE==1 || b == 0x002E){
synchronized(this) {
if (m_iStatusScale == SCALE_READY) {
m_dWeightBuffer = 0.0;
m_dWeightDecimals = 1.0;
m_iStatusScale = SCALE_READING;
}
if (b == 0x002E) {
m_iStatusScale = SCALE_READINGDECIMALS;
} else {
m_dWeightBuffer = m_dWeightBuffer * 10.0 + b - 0x0030;
if (m_iStatusScale == SCALE_READINGDECIMALS) {
m_dWeightDecimals *= 10.0;
}
}
}
} else {
m_dWeightBuffer = 0.0;
m_dWeightDecimals = 1.0;
m_iStatusScale = SCALE_READY;
}
}
} catch (IOException eIO) {}
break;
}
}
}
@@ -0,0 +1,178 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.pos.scale;
import gnu.io.*;
import java.io.*;
import java.util.TooManyListenersException;
/**
*
* @author JG uniCenta
*/
public class ScaleComm implements Scale, SerialPortEventListener {
private String m_sPortScale;
private CommPortIdentifier m_PortIdPrinter;
private SerialPort m_CommPortPrinter;
private OutputStream m_out;
private InputStream m_in;
private static final int SCALE_READY = 0;
private static final int SCALE_READING = 1;
private double m_dWeightBuffer;
private int m_iStatusScale;
/** Creates a new instance of ScaleComm
* @param sPortPrinter */
public ScaleComm(String sPortPrinter) {
m_sPortScale = sPortPrinter;
m_out = null;
m_in = null;
m_iStatusScale = SCALE_READY;
m_dWeightBuffer = 0.0;
}
/**
*
* @return
*/
@Override
public Double readWeight() {
synchronized(this) {
if (m_iStatusScale != SCALE_READY) {
try {
wait(1000);
} catch (InterruptedException e) {
}
if (m_iStatusScale != SCALE_READY) {
// bascula tonta.
m_iStatusScale = SCALE_READY;
}
}
// Ya estamos en SCALE_READY
m_dWeightBuffer = 0.0;
write(new byte[] {0x05});
flush();
// Esperamos un ratito
try {
wait(1000);
} catch (InterruptedException e) {
}
if (m_iStatusScale == SCALE_READY) {
// a value as been readed.
double dWeight = m_dWeightBuffer / 1000.0;
m_dWeightBuffer = 0.0;
return new Double(dWeight);
} else {
m_iStatusScale = SCALE_READY;
m_dWeightBuffer = 0.0;
return new Double(0.0);
}
}
}
private void flush() {
try {
m_out.flush();
} catch (IOException e) {
}
}
private void write(byte[] data) {
try {
if (m_out == null) {
m_PortIdPrinter = CommPortIdentifier.getPortIdentifier(m_sPortScale); // Tomamos el puerto
m_CommPortPrinter = (SerialPort) m_PortIdPrinter.open("PORTID", 2000); // Abrimos el puerto
m_out = m_CommPortPrinter.getOutputStream(); // Tomamos el chorro de escritura
m_in = m_CommPortPrinter.getInputStream();
m_CommPortPrinter.addEventListener(this);
m_CommPortPrinter.notifyOnDataAvailable(true);
m_CommPortPrinter.setSerialPortParams(4800,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_ODD); // Configuramos el puerto
}
m_out.write(data);
} catch (NoSuchPortException | PortInUseException | UnsupportedCommOperationException | TooManyListenersException | IOException e) {
}
}
/**
*
* @param e
*/
@Override
public void serialEvent(SerialPortEvent e) {
// Determine type of event.
switch (e.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:
break;
case SerialPortEvent.DATA_AVAILABLE:
try {
while (m_in.available() > 0) {
int b = m_in.read();
if (b == 0x001E) { // RS ASCII
// Fin de lectura
synchronized (this) {
m_iStatusScale = SCALE_READY;
notifyAll();
}
} else if (b > 0x002F && b < 0x003A){
synchronized(this) {
if (m_iStatusScale == SCALE_READY) {
m_dWeightBuffer = 0.0; // se supone que esto debe estar ya garantizado
m_iStatusScale = SCALE_READING;
}
m_dWeightBuffer = m_dWeightBuffer * 10.0 + b - 0x0030;
}
} else {
// caracteres invalidos, reseteamos.
m_dWeightBuffer = 0.0; // se supone que esto debe estar ya garantizado
m_iStatusScale = SCALE_READY;
}
}
} catch (IOException eIO) {}
break;
}
}
}
@@ -0,0 +1,57 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.pos.scale;
import com.unicenta.beans.JNumberDialog;
import com.unicenta.pos.forms.AppLocal;
import java.awt.Component;
import javax.swing.ImageIcon;
/**
*
* @author adrian
*/
public class ScaleDialog implements Scale {
private Component parent;
/**
*
* @param parent
*/
public ScaleDialog(Component parent) {
this.parent = parent;
}
/**
*
* @return
* @throws ScaleException
*/
@Override
public Double readWeight() throws ScaleException {
// Set title for grams Kilos, ounzes, pounds, ...
return JNumberDialog.showEditNumber(parent,
AppLocal.getIntString("label.scale"),
AppLocal.getIntString("label.scaleinput"),
new ImageIcon(ScaleDialog.class.getResource("/com/unicenta/images/ark2.png")));
}
}
@@ -0,0 +1,41 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.pos.scale;
/**
*
* @author JG uniCenta
*/
public class ScaleException extends java.lang.Exception {
/**
* Creates a new instance of <code>ScaleException</code> without detail message.
*/
public ScaleException() {
}
/**
* Constructs an instance of <code>ScaleException</code> with the specified detail message.
* @param msg the detail message.
*/
public ScaleException(String msg) {
super(msg);
}
}
@@ -0,0 +1,38 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009 Openbravo, S.L.
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.pos.scale;
public class ScaleFake implements Scale {
/** Creates a new instance of ScaleFake */
public ScaleFake() {
}
/**
*
* @return
* @throws ScaleException
*/
@Override
public Double readWeight() throws ScaleException {
return new Double(Math.random() * 2.0);
}
}
@@ -0,0 +1,198 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.pos.scale;
import gnu.io.*;
import lombok.extern.slf4j.Slf4j;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;import java.util.TooManyListenersException;
/**
*
* @author Nicholas Fritz - changes by JG
*/
@Slf4j
public class ScaleMTIND221 implements Scale, SerialPortEventListener {
private CommPortIdentifier m_PortIdPrinter;
private SerialPort m_CommPortPrinter;
private final String m_sPortScale;
private OutputStream m_out;
private InputStream m_in;
private static final int SCALE_READY = 0;
private static final int SCALE_READING = 1;
private static final int SCALE_READINGDECIMALS = 2;
private double m_dWeightBuffer;
private double m_dWeightDecimals;
private int m_iStatusScale;
/** Creates a new instance of ScaleComm
* @param sPortPrinter */
public ScaleMTIND221(String sPortPrinter) {
m_sPortScale = sPortPrinter;
m_out = null;
m_in = null;
m_iStatusScale = SCALE_READY;
m_dWeightBuffer = 0.0;
m_dWeightDecimals = 1.0;
}
/**
*
* @return
*/
@Override
public Double readWeight() {
synchronized(this) {
if (m_iStatusScale != SCALE_READY) {
try {
wait(1000);
} catch (InterruptedException ex) {
log.error(ex.getMessage());
}
if (m_iStatusScale != SCALE_READY) {
// bascula tonta.
m_iStatusScale = SCALE_READY;
}
}
m_dWeightBuffer = 0.0;
m_dWeightDecimals = 1.0;
try {
write(new byte[] {0x50}); // P
} catch (TooManyListenersException ex) {
log.error(ex.getMessage());
}
flush();
try {
wait(1000);
} catch (InterruptedException ex) {
log.error(ex.getMessage());
}
if (m_iStatusScale == SCALE_READY) {
// hemos recibido cositas o si no hemos recibido nada estamos a 0.0
double dWeight = m_dWeightBuffer / (m_dWeightDecimals*100.0);
m_dWeightBuffer = 0.0;
m_dWeightDecimals = 1.0;
return dWeight;
} else {
m_iStatusScale = SCALE_READY;
m_dWeightBuffer = 0.0;
m_dWeightDecimals = 1.0;
return 0.0;
}
}
}
private void flush() {
try {
m_out.flush();
} catch (IOException e) {
}
}
private void write(byte[] data) throws TooManyListenersException {
try {
if (m_out == null) {
m_PortIdPrinter = CommPortIdentifier.getPortIdentifier(m_sPortScale); // Tomamos el puerto
m_CommPortPrinter = (SerialPort) m_PortIdPrinter.open("PORTID", 2000); // Abrimos el puerto
m_out = m_CommPortPrinter.getOutputStream(); // Tomamos el chorro de escritura
m_in = m_CommPortPrinter.getInputStream();
m_CommPortPrinter.addEventListener(this);
m_CommPortPrinter.notifyOnDataAvailable(true);
m_CommPortPrinter.setSerialPortParams(9600, 8, 1, 0); // Configuramos el puerto
}
m_out.write(data);
} catch (NoSuchPortException | PortInUseException | UnsupportedCommOperationException | IOException e) {
}
}
/**
*
* @param e
*/
@Override
public void serialEvent(SerialPortEvent e) {
// Determine type of event.
switch (e.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:
break;
case SerialPortEvent.DATA_AVAILABLE:
try {
while (m_in.available() > 0) {
int b = m_in.read();
if (b == 0x000D) { // CR ASCII
// Fin de lectura
synchronized (this) {
m_iStatusScale = SCALE_READY;
notifyAll();
}
} else if (((b > 0x002F) && (b < 0x003A)) || (b == 0x002E)){
synchronized(this) {
if (m_iStatusScale == SCALE_READY) {
m_dWeightBuffer = 0.0; // se supone que esto debe estar ya garantizado
m_dWeightDecimals = 1.0;
m_iStatusScale = SCALE_READING;
}
if (b == 0x002E) {
m_iStatusScale = SCALE_READINGDECIMALS;
} else {
m_dWeightBuffer = m_dWeightBuffer * 10.0 + b - 0x0030;
if (m_iStatusScale == SCALE_READINGDECIMALS) {
m_dWeightDecimals *= 10.0;
}
}
}
} else {
// caracteres invalidos, reseteamos.
//m_dWeightBuffer = 0.0; // se supone que esto debe estar ya garantizado
m_dWeightDecimals = 1.0;
m_iStatusScale = SCALE_READY;
}
}
} catch (IOException eIO) {}
break;
}
}
}
@@ -0,0 +1,193 @@
// uniCenta oPOS - Touch Friendly Point Of Sale
// Copyright (c) 2009-2018 uniCenta & previous Openbravo POS works
// https://unicenta.com
//
// This file is part of uniCenta oPOS
//
// uniCenta oPOS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// uniCenta oPOS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>.
package com.unicenta.pos.scale;
import gnu.io.*;
import java.io.*;
import java.util.TooManyListenersException;
/**
*
* @author JG uniCenta
*/
public class ScaleSamsungEsp implements Scale, SerialPortEventListener {
private CommPortIdentifier m_PortIdPrinter;
private SerialPort m_CommPortPrinter;
private String m_sPortScale;
private OutputStream m_out;
private InputStream m_in;
private static final int SCALE_READY = 0;
private static final int SCALE_READING = 1;
private static final int SCALE_READINGDECIMALS = 2;
private double m_dWeightBuffer;
private double m_dWeightDecimals;
private int m_iStatusScale;
/** Creates a new instance of ScaleComm
* @param sPortPrinter */
public ScaleSamsungEsp(String sPortPrinter) {
m_sPortScale = sPortPrinter;
m_out = null;
m_in = null;
m_iStatusScale = SCALE_READY;
m_dWeightBuffer = 0.0;
m_dWeightDecimals = 1.0;
}
/**
*
* @return
*/
@Override
public Double readWeight() {
synchronized(this) {
if (m_iStatusScale != SCALE_READY) {
try {
wait(1000);
} catch (InterruptedException e) {
}
if (m_iStatusScale != SCALE_READY) {
// bascula tonta.
m_iStatusScale = SCALE_READY;
}
}
// Ya estamos en SCALE_READY
m_dWeightBuffer = 0.0;
m_dWeightDecimals = 1.0;
write(new byte[] {0x24}); // $
flush();
// Esperamos un ratito
try {
wait(1000);
} catch (InterruptedException e) {
}
if (m_iStatusScale == SCALE_READY) {
// hemos recibido cositas o si no hemos recibido nada estamos a 0.0
double dWeight = m_dWeightBuffer / m_dWeightDecimals;
m_dWeightBuffer = 0.0;
m_dWeightDecimals = 1.0;
return new Double(dWeight);
} else {
m_iStatusScale = SCALE_READY;
m_dWeightBuffer = 0.0;
m_dWeightDecimals = 1.0;
return new Double(0.0);
}
}
}
private void flush() {
try {
m_out.flush();
} catch (IOException e) {
}
}
private void write(byte[] data) {
try {
if (m_out == null) {
m_PortIdPrinter = CommPortIdentifier.getPortIdentifier(m_sPortScale); // Tomamos el puerto
m_CommPortPrinter = (SerialPort) m_PortIdPrinter.open("PORTID", 2000); // Abrimos el puerto
m_out = m_CommPortPrinter.getOutputStream(); // Tomamos el chorro de escritura
m_in = m_CommPortPrinter.getInputStream();
m_CommPortPrinter.addEventListener(this);
m_CommPortPrinter.notifyOnDataAvailable(true);
m_CommPortPrinter.setSerialPortParams(4800,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_ODD); // Configuramos el puerto
}
m_out.write(data);
} catch (NoSuchPortException | PortInUseException | UnsupportedCommOperationException | TooManyListenersException | IOException e) {
}
}
/**
*
* @param e
*/
@Override
public void serialEvent(SerialPortEvent e) {
// Determine type of event.
switch (e.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:
break;
case SerialPortEvent.DATA_AVAILABLE:
try {
while (m_in.available() > 0) {
int b = m_in.read();
if (b == 0x000D) { // CR ASCII
// Fin de lectura
synchronized (this) {
m_iStatusScale = SCALE_READY;
notifyAll();
}
} else if ((b > 0x002F && b < 0x003A) || b == 0x002E){
synchronized(this) {
if (m_iStatusScale == SCALE_READY) {
m_dWeightBuffer = 0.0; // se supone que esto debe estar ya garantizado
m_dWeightDecimals = 1.0;
m_iStatusScale = SCALE_READING;
}
if (b == 0x002E) {
m_iStatusScale = SCALE_READINGDECIMALS;
} else {
m_dWeightBuffer = m_dWeightBuffer * 10.0 + b - 0x0030;
if (m_iStatusScale == SCALE_READINGDECIMALS) {
m_dWeightDecimals *= 10.0;
}
}
}
} else {
// caracteres invalidos, reseteamos.
m_dWeightBuffer = 0.0; // se supone que esto debe estar ya garantizado
m_dWeightDecimals = 1.0;
m_iStatusScale = SCALE_READY;
}
}
} catch (IOException eIO) {}
break;
}
}
}