Puck detetion mode - during loading only

This commit is contained in:
gac-S_Changer
2025-08-21 11:27:10 +02:00
parent 45cb47eb71
commit 114c800ac2
9 changed files with 159 additions and 178 deletions
+118 -93
View File
@@ -333,8 +333,10 @@ public class Controller {
final DeviceListener puckDetectionListener = new DeviceListener() {
@Override
public void onValueChanged(Device device, Object value, Object former) {
if (value != null) { //Keep last value
onPuckDetectionChanged();
if (puck_detection.isEnabled()){
if (value != null) { //Keep last value
onPuckDetectionChanged();
}
}
}
};
@@ -358,7 +360,7 @@ public class Controller {
} else {
Logger.getLogger(Controller.class.getName()).log(Level.SEVERE, "No puck_detection detected.");
}
checkPuckLoading();
checkPuckDetectionEnabling();
}
PuckState[] puckState;
@@ -692,16 +694,18 @@ public class Controller {
}
////////////////////// Puck Loading /////////////////////////////////
Boolean puckLoading;
boolean puckLoading;
Puck.Detection[] currentDetection;
boolean puckReaderOk = true;
String insertedPuckDatamatrix;
Puck removedPuck;
//true->load
//false->unload
//null->finish transfer mode
void setPuckLoading(Boolean load) {
void setPuckLoading(boolean load) {
if (load != puckLoading) {
if (load!=null){
if (load){
if (isDoorClosed()){
return;
}
@@ -709,7 +713,7 @@ public class Controller {
removedPuck = null;
} else {
Controller.getInstance().setLaserPos((Puck)null);
setLaserPos((Puck)null);
}
if ((dialogAskPuckDatamatrix != null) && (dialogAskPuckDatamatrix.isShowing())) {
dialogAskPuckDatamatrix.setVisible(false);
@@ -725,7 +729,7 @@ public class Controller {
if (puckReaderOk) {
Logger.getLogger(Controller.class.getName()).warning("Communication failure: " + name);
}
puckLoading = null;
puckLoading = false;
puckReaderOk = false;
} else {
if (!puckReaderOk) {
@@ -736,14 +740,14 @@ public class Controller {
return ret;
};
try {
if (puckLoading!=null) {
if (puckLoading) {
getMainFrame().evalAsync(name + ".enable(); " + name + ".polling = 100", true).handle(errorHandler);
currentDetection = basePlate.getDetection();
} else if (getState().isInitialized()) {
getMainFrame().evalAsync(name + ".polling = 0; " + name + ".disable()", true).handle(errorHandler);
onPuckScanned(null);
}
getMainFrame().evalAsync("onPuckLoadingChange(" + ((puckLoading!=null) ? "True" : "False") + ")");
getMainFrame().evalAsync("onPuckLoadingChange(" + (puckLoading ? "True" : "False") + ")");
} catch (Exception ex) {
errorHandler.apply(null, ex);
}
@@ -752,7 +756,18 @@ public class Controller {
}
}
public Boolean isPuckLoading() {
public boolean isPuckLoading() {
try {
if (isPuckDetectionLoading()){
if (!puck_detection.isEnabled()){
//Does not process load events if checking missing pucks before re-enabling detection
return false;
}
}
} catch (IOException ex) {
Logger.getLogger(Controller.class.getName()).log(Level.WARNING, null, ex);
}
return puckLoading;
}
@@ -784,7 +799,7 @@ public class Controller {
}
public void onPuckBarcode(String datamatrix) {
if (isPuckLoading()!=null) {
if (isPuckLoading()) {
playSound("scanned");
System.out.println("Detected Puck: " + datamatrix);
onPuckScanned(datamatrix);
@@ -796,9 +811,9 @@ public class Controller {
getMainFrame().setSampleDatamatrix(datamatrix);
System.out.println("Detected Sample: " + datamatrix);
}
void onPuckDetectionChanged() {
if (isPuckLoading()!=null) {
if (isPuckLoading()) {
Puck.Detection[] detection = basePlate.getDetection();
for (int i = 0; i < Controller.NUMBER_OF_PUCKS; i++) {
Puck puck = basePlate.getPucks()[i];
@@ -806,10 +821,8 @@ public class Controller {
boolean detectedPuckInserted = (currentDetection[i] != Puck.Detection.Present) && (detection[i] == Puck.Detection.Present);
boolean detectedPuckRemoved = (currentDetection[i] != Puck.Detection.Empty) && (detection[i] == Puck.Detection.Empty);
if (detectedPuckInserted) {
onPuckInserted(puck);
} else if (detectedPuckRemoved) {
playSound("unmounted");
onPuckMounted(puck);
} else if (detectedPuckRemoved) {
onPuckUnmounted(puck);
}
}
@@ -817,31 +830,9 @@ public class Controller {
currentDetection = detection;
}
}
String insertedPuckDatamatrix;
Puck removedPuck;
public void onPuckInserted(Puck puck) {
playSound("mounted");
String datamatrix = getMainFrame().getPuckDatamatrix();
logPuckDetectionChange(puck, true);
onPuckScanned(null);
if ((datamatrix==null) || (datamatrix.isBlank())){
if (puck == removedPuck){
datamatrix = insertedPuckDatamatrix;
}
}
onPuckMounted(puck, datamatrix);
insertedPuckDatamatrix = datamatrix;
removedPuck = null;
}
public void onPuckRemoved(Puck puck) {
playSound("unmounted");
logPuckDetectionChange(puck, false);
onPuckUnmounted(puck);
}
void linkPuckDatamatrix(Puck puck, String datamatrix, boolean showMessage) {
public void linkPuckDatamatrix(Puck puck, String datamatrix, boolean showMessage) {
// if ( ((puck.getId()==null) && (datamatrix!=null)) ||
// (puck.getId()!=null) && (!puck.getId().equals(datamatrix))){
String puckName = (puck == null) ? "" : puck.getName();
@@ -959,14 +950,22 @@ public class Controller {
}
}
Boolean puckDetectionLoading;
public boolean isPuckDetectionLoading() throws IOException{
if (puckDetectionLoading==null){
puckDetectionLoading = "loading".equals(Context.getSetting("puck_detection"));
}
return puckDetectionLoading;
}
boolean showingPuckLoadingDialog;
public void checkPuckLoading(){
boolean showingPuckLoadingDialog;
public void checkPuckDetectionEnabling(){
try{
showingPuckLoadingDialog = (dialogPuckLoading != null) && (dialogPuckLoading.isShowing());
if ("loading".equals(Context.getSetting("puck_detection"))){
if ( isPuckDetectionLoading()){
if (showingPuckLoadingDialog){
var werePresent = new ArrayList<String>();
Puck[] pucks = basePlate.getPucks();
@@ -988,10 +987,16 @@ public class Controller {
removed.removeAll(present);
if (removed.size()>0){
PuckDetectionErrorDialog dlg = new PuckDetectionErrorDialog(mainFrame.getTopLevel());
PuckDetectionErrorDialog dlg = new PuckDetectionErrorDialog(dialogPuckLoading, false);
dlg.initialize(removed);
dlg.setVisible(true);
}
dlg.setLocationRelativeTo(dialogPuckLoading);
dlg.setVisible(true);
for (String address: removed){
Puck puck = basePlate.getPuckByName(address);
clearPuckMountedSample(puck);
Controller.getInstance().linkPuckDatamatrix(puck, null, false);
}
}
}
puck_detection.setEnabled(showingPuckLoadingDialog);
}
@@ -1008,20 +1013,20 @@ public class Controller {
dialogPuckLoading = new PuckLoadingDialog(mainFrame.getTopLevel(), load, false);
dialogPuckLoading.setLocationRelativeTo(mainFrame);
dialogPuckLoading.setVisible(true);
checkPuckLoading();
checkPuckDetectionEnabling();
dialogPuckLoading.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
try{
setPuckLoading(null);
setPuckLoading(false);
} catch (Exception ex) {
Logger.getLogger(Controller.class.getName()).log(Level.WARNING, null, ex);
}
}
@Override
public void windowClosed(WindowEvent e) {
checkPuckLoading();
checkPuckDetectionEnabling();
}
});
@@ -1042,9 +1047,9 @@ public class Controller {
}
}
void onPuckLoadingModeChange(Boolean puckLoadMode) {
if (puckMountMode == PuckMountMode.Dialog) {
if (puckLoadMode!=null) {
public void onPuckLoadingModeChange(boolean puckLoadMode) {
if ( hasLoadDialog()) {
if (puckLoadMode) {
showDialogPuckLoading(puckLoadMode);
mainFrame.setViewDesign();
} else {
@@ -1054,10 +1059,10 @@ public class Controller {
}
}
void onPuckScanned(String datamatrix) {
if (isPuckLoading()!=null) {
public void onPuckScanned(String datamatrix) {
if (isPuckLoading()) {
getMainFrame().setPuckDatamatrix(datamatrix);
if (puckMountMode == PuckMountMode.Dialog) {
if ( hasLoadDialog()) {
showDialogPuckLoading(puckLoading);
dialogPuckLoading.onPuckScanned(datamatrix);
}
@@ -1065,46 +1070,66 @@ public class Controller {
getMainFrame().setPuckDatamatrix(null);
}
}
void onPuckMounted(Puck puck, String datamatrix) {
if (isPuckLoading()!=null) {
if (puckMountMode == PuckMountMode.Dialog) {
showDialogPuckLoading(puckLoading);
dialogPuckLoading.onPuckMounted(puck, datamatrix);
} else {
if (!datamatrix.isEmpty()) {
linkPuckDatamatrix(puck, datamatrix, true);
} else {
askPuckDatamatrix(puck);
}
}
}
public boolean hasLoadDialog(){
return(puckMountMode == PuckMountMode.Dialog);
}
void onPuckUnmounted(Puck puck) {
if (isPuckLoading()!=null) {
try{
Sample sample = getMountedSample();
if ((sample!=null) && (sample.getPuck() == puck)){
resetMountedSample();
sample.setLoaded(false);
SwingUtilities.invokeLater(()->{;
getMainFrame().refresh();
});
}
} catch (Exception ex) {
Logger.getLogger(Controller.class.getName()).log(Level.WARNING, null, ex);
public void onPuckMounted(Puck puck) {
String datamatrix = getMainFrame().getPuckDatamatrix();
Logger.getLogger(Controller.class.getName()).info("Mounted puck: " + puck.getName() + " - datamatrix:" + datamatrix);
playSound("mounted");
logPuckDetectionChange(puck, true);
onPuckScanned(null);
if ((datamatrix==null) || (datamatrix.isBlank())){
if (puck == removedPuck){
datamatrix = insertedPuckDatamatrix;
}
if (puckMountMode == PuckMountMode.Dialog) {
showDialogPuckLoading(puckLoading);
dialogPuckLoading.onPuckUnmounted(puck);
} else {
linkPuckDatamatrix(puck, null, true);
}
removedPuck = puck;
}
if ((datamatrix != null) && (!datamatrix.isEmpty())) {
Controller.getInstance().linkPuckDatamatrix(puck, datamatrix, !hasLoadDialog());
}
if (hasLoadDialog()) {
showDialogPuckLoading(puckLoading);
dialogPuckLoading.onPuckMounted(puck, datamatrix);
} else {
if ((datamatrix == null) || (datamatrix.isEmpty())){
askPuckDatamatrix(puck);
}
}
insertedPuckDatamatrix = datamatrix;
removedPuck = null;
}
public void onPuckUnmounted(Puck puck) {
Logger.getLogger(Controller.class.getName()).info("Unmounted puck: " + puck.getName());
playSound("unmounted");
clearPuckMountedSample(puck);
Controller.getInstance().linkPuckDatamatrix(puck, null, !hasLoadDialog());
if ( hasLoadDialog()) {
showDialogPuckLoading(puckLoading);
dialogPuckLoading.onPuckUnmounted(puck);
}
removedPuck = puck;
}
void clearPuckMountedSample(Puck puck){
try{
Sample sample = getMountedSample();
if ((sample!=null) && (sample.getPuck() == puck)){
resetMountedSample();
sample.setLoaded(false);
SwingUtilities.invokeLater(()->{;
getMainFrame().refresh();
});
}
} catch (Exception ex) {
Logger.getLogger(Controller.class.getName()).log(Level.WARNING, null, ex);
}
}
void logSampleMounted(String former, String current){
logEvent((current!=null) ? "Sample Mounted" : "Sample Unmounted", former, current);
}