WIP-160909 Simulation / MultiDevice
parent
94877bb85f
commit
e903133b95
|
@ -6,6 +6,6 @@
|
|||
<classpathentry combineaccessrules="false" kind="src" path="/org.hwo.ui"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/org.hwo.servicelink"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/org.hwo.platform"/>
|
||||
<classpathentry kind="lib" path="/data/src/java/external/hsqldb-2.3.4/hsqldb/lib/hsqldb.jar"/>
|
||||
<classpathentry kind="lib" path="lib/hsqldb.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
|
|
@ -2,9 +2,6 @@ package org.hwo.pulscounter;
|
|||
|
||||
public abstract class AbstractPulsCounterApplicationListener implements PulsCounterApplicationListener {
|
||||
|
||||
@Override
|
||||
public void serialPortChanged() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@ package org.hwo.pulscounter;
|
|||
import static org.hwo.logging.Logging.log;
|
||||
import static org.hwo.logging.LogLevel.*;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Frame;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
|
@ -19,6 +21,9 @@ import java.util.Vector;
|
|||
import java.util.prefs.BackingStoreException;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
|
||||
import org.hsqldb.persist.EventLogInterface;
|
||||
import org.hwo.StringHelper;
|
||||
import org.hwo.configuration.ConfigurableObjects;
|
||||
import org.hwo.io.NewSerialPort.NewSerialPort;
|
||||
|
@ -27,6 +32,7 @@ import org.hwo.servicelink.ServiceLink;
|
|||
import org.hwo.servicelink.ServiceLinkListener;
|
||||
import org.hwo.pulscounter.device.IDeviceConnector;
|
||||
import org.hwo.pulscounter.device.ServiceLinkDeviceConnector;
|
||||
import org.hwo.pulscounter.device.SimulatedCounter;
|
||||
import org.hwo.pulscounter.ui.AppSettingsListener;
|
||||
import org.hwo.pulscounter.ui.BatchRunner;
|
||||
import org.hwo.pulscounter.ui.NewMainWindow;
|
||||
|
@ -142,7 +148,10 @@ public class PulsCounterApplication implements ServiceLinkListener{
|
|||
|
||||
/* Initialize default configuration */
|
||||
applicationConfiguration.setProperty("ui.class", NewMainWindow.class.getCanonicalName());
|
||||
applicationConfiguration.setProperty("interface.classes", StringHelper.join(new String[]{ServiceLinkDeviceConnector.class.getCanonicalName() }, ","));
|
||||
applicationConfiguration.setProperty("interface.classes", StringHelper.join(new String[]{
|
||||
ServiceLinkDeviceConnector.class.getCanonicalName(),
|
||||
SimulatedCounter.class.getCanonicalName()
|
||||
}, ","));
|
||||
|
||||
|
||||
try {
|
||||
|
@ -246,14 +255,18 @@ public class PulsCounterApplication implements ServiceLinkListener{
|
|||
|
||||
log(INFO,"Application shutdown...");
|
||||
|
||||
|
||||
/* Dispose all left frames */
|
||||
for (Frame frame: JFrame.getFrames()){
|
||||
frame.setVisible(false);
|
||||
frame.dispose();
|
||||
}
|
||||
|
||||
if (shouldSaveConfiguration){
|
||||
|
||||
applicationConfiguration.setProperty("interfaces.n", Integer.toString(interfaces.size()));
|
||||
for (int n=0;n<interfaces.size();n++){
|
||||
applicationConfiguration.setProperty(String.format("interfaces.%d.class", n), interfaces.get(0).getClass().getCanonicalName());
|
||||
applicationConfiguration.setProperty(String.format("interfaces.%d.settings", n), interfaces.get(0).getConnectionSettings());
|
||||
applicationConfiguration.setProperty(String.format("interfaces.%d.class", n), interfaces.get(n).getClass().getCanonicalName());
|
||||
applicationConfiguration.setProperty(String.format("interfaces.%d.settings", n), interfaces.get(n).getConnectionSettings());
|
||||
}
|
||||
|
||||
|
||||
|
@ -272,7 +285,6 @@ public class PulsCounterApplication implements ServiceLinkListener{
|
|||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -404,21 +416,6 @@ public class PulsCounterApplication implements ServiceLinkListener{
|
|||
}
|
||||
}
|
||||
|
||||
public void fireSerialPortChanged(){
|
||||
for (PulsCounterApplicationListener listener: applicationListeners){
|
||||
listener.serialPortChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public void fireConnectionStateChanged(){
|
||||
fireConnectionStateChanged(getServiceLink().isOpen());
|
||||
}
|
||||
|
||||
public void fireConnectionStateChanged(Boolean connected){
|
||||
for (PulsCounterApplicationListener listener: applicationListeners){
|
||||
listener.connectionStateChanged(connected);
|
||||
}
|
||||
}
|
||||
|
||||
public void message(String message){
|
||||
|
||||
|
@ -454,7 +451,6 @@ public class PulsCounterApplication implements ServiceLinkListener{
|
|||
getServiceLink();
|
||||
|
||||
fireServiceLinkChanged();
|
||||
fireSerialPortChanged();
|
||||
}
|
||||
|
||||
public synchronized ServiceLink getServiceLink() {
|
||||
|
@ -543,7 +539,6 @@ public class PulsCounterApplication implements ServiceLinkListener{
|
|||
|
||||
@Override
|
||||
public void connectionStateChanged(Boolean connected) {
|
||||
fireConnectionStateChanged(connected);
|
||||
}
|
||||
|
||||
public SnapshotManager getSnapshotManager() {
|
||||
|
|
|
@ -2,10 +2,6 @@ package org.hwo.pulscounter;
|
|||
|
||||
public interface PulsCounterApplicationListener {
|
||||
|
||||
void serialPortChanged();
|
||||
void connectionStateChanged(Boolean connected);
|
||||
|
||||
|
||||
void interfaceClassesChanged(PulsCounterApplication pulsCounterApplication);
|
||||
void interfacesChanged(PulsCounterApplication pulsCounterApplication);
|
||||
|
||||
|
|
|
@ -15,11 +15,13 @@ public interface IDeviceConnector {
|
|||
public int getCounter(int channel);
|
||||
public void setCounter(int channel,int counter);
|
||||
|
||||
public float[] getAnalogs();
|
||||
public float getAnalog(int channel);
|
||||
|
||||
public int[] getSimpleScript();
|
||||
public void setSimpleScript(int[] simpleScript);
|
||||
|
||||
public int getInputs();
|
||||
public void setInputs(int inputs);
|
||||
public int getOutputs();
|
||||
public void setOutputs(int outputs);
|
||||
public int getPullups();
|
||||
|
|
|
@ -1,7 +1,16 @@
|
|||
package org.hwo.pulscounter.device;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.hwo.io.NewSerialPort.NewSerialPort;
|
||||
import org.hwo.pulscounter.ui.DeviceConfiguration;
|
||||
import org.hwo.servicelink.ServiceLink;
|
||||
import org.hwo.servicelink.ServiceLinkException;
|
||||
import org.hwo.servicelink.ServiceLinkRequestFailedException;
|
||||
import org.hwo.ui.dialog.SerialPortChooser;
|
||||
import static org.hwo.logging.Logging.*;
|
||||
import static org.hwo.logging.LogLevel.*;
|
||||
|
||||
|
||||
public class ServiceLinkDeviceConnector implements IDeviceConnector {
|
||||
|
||||
|
@ -9,8 +18,21 @@ public class ServiceLinkDeviceConnector implements IDeviceConnector {
|
|||
|
||||
public ServiceLinkDeviceConnector() {
|
||||
serviceLink = new ServiceLink(new NewSerialPort("COM1:"));
|
||||
|
||||
}
|
||||
|
||||
private void checkOpen(){
|
||||
if (!serviceLink.isOpen()){
|
||||
try {
|
||||
serviceLink.open();
|
||||
serviceLink.getSerialPort().setTimeOut(250);
|
||||
} catch (ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("Serial [%s]", this.serviceLink.getSerialPort().getPortName());
|
||||
|
@ -18,17 +40,21 @@ public class ServiceLinkDeviceConnector implements IDeviceConnector {
|
|||
|
||||
@Override
|
||||
public String getDeviceSerial() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setDeviceSerial() {
|
||||
public void setDeviceSerial(int serial) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean showConnctionSetup() {
|
||||
// TODO Auto-generated method stub
|
||||
NewSerialPort newSerialPort = SerialPortChooser.execute(serviceLink.getSerialPort().getPortName());
|
||||
if (newSerialPort != null){
|
||||
serviceLink.close();
|
||||
serviceLink.getSerialPort().setPortName(newSerialPort.getPortName());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -51,8 +77,25 @@ public class ServiceLinkDeviceConnector implements IDeviceConnector {
|
|||
|
||||
@Override
|
||||
public int[] getCounters() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
int[] values = new int[32];
|
||||
|
||||
checkOpen();
|
||||
|
||||
for (int n=0;n<32;n++){
|
||||
Integer v = null;
|
||||
try {
|
||||
v = serviceLink.readInt(13, 0, 0x600 + n );
|
||||
} catch (Exception e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
if (v != null){
|
||||
values[n] = v;
|
||||
} else {
|
||||
values[n] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -91,12 +134,6 @@ public class ServiceLinkDeviceConnector implements IDeviceConnector {
|
|||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInputs(int inputs) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOutputs() {
|
||||
// TODO Auto-generated method stub
|
||||
|
@ -133,6 +170,18 @@ public class ServiceLinkDeviceConnector implements IDeviceConnector {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public float[] getAnalogs() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getAnalog(int channel) {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,160 @@
|
|||
package org.hwo.pulscounter.device;
|
||||
|
||||
import java.util.Random;
|
||||
import static org.hwo.logging.Logging.*;
|
||||
import static org.hwo.logging.LogLevel.*;
|
||||
|
||||
|
||||
public class SimulatedCounter implements IDeviceConnector {
|
||||
|
||||
private int serial;
|
||||
private int[] values;
|
||||
private float[] analogs;
|
||||
|
||||
private int inputs,
|
||||
outputs,
|
||||
pullups,
|
||||
inverts;
|
||||
|
||||
private Random random;
|
||||
|
||||
public SimulatedCounter() {
|
||||
random = new Random();
|
||||
serial = random.nextInt();
|
||||
|
||||
values = new int[32];
|
||||
analogs = new float[8];
|
||||
|
||||
for (int i=0;i<8;i++){
|
||||
analogs[i] = (float)(random.nextFloat() * 10.0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("Simulated Counter [%d]", serial);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDeviceSerial() {
|
||||
return String.format("%d", serial);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean showConnctionSetup() {
|
||||
return SimulatedCounterSettingsDialog.show(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConnectionSettings() {
|
||||
return String.format("%d", serial);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConnectionSettings(String connectionSettings) {
|
||||
if (!connectionSettings.equals("")){
|
||||
log(INFO,"Simulated Counter changes serial %d -> %s",serial,connectionSettings);
|
||||
serial = Integer.parseInt(connectionSettings);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConnectionSettingsText() {
|
||||
return String.format("Device Serial: %d\nSimulated Values", serial);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getCounters() {
|
||||
int i = random.nextInt();
|
||||
|
||||
values[ i & 0x1F ] += random.nextInt() & 0x07;
|
||||
|
||||
for (i=0;i<8;i++){
|
||||
analogs[i] += (float)(random.nextFloat() * 0.6)-0.3;
|
||||
if (analogs[i] > 10.0f){
|
||||
analogs[i] = 10.0f;
|
||||
}
|
||||
if (analogs[i] < 0.0f){
|
||||
analogs[i] = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
inputs = random.nextInt();
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCounters(int[] values) {
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCounter(int channel) {
|
||||
return values[channel];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCounter(int channel, int counter) {
|
||||
values[channel] = counter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getSimpleScript() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSimpleScript(int[] simpleScript) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInputs() {
|
||||
return inputs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOutputs() {
|
||||
return outputs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOutputs(int outputs) {
|
||||
this.outputs = outputs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPullups() {
|
||||
return pullups;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPullups(int pullups) {
|
||||
this.pullups = pullups;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInverts() {
|
||||
return inverts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInverts(int inverts) {
|
||||
this.inverts = inverts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float[] getAnalogs() {
|
||||
return analogs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getAnalog(int channel) {
|
||||
return analogs[channel];
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,108 @@
|
|||
package org.hwo.pulscounter.device;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.GridBagLayout;
|
||||
import javax.swing.JLabel;
|
||||
import java.awt.GridBagConstraints;
|
||||
import javax.swing.JTextField;
|
||||
import java.awt.Insets;
|
||||
|
||||
public class SimulatedCounterSettingsDialog extends JDialog {
|
||||
|
||||
public static boolean show(SimulatedCounter counter){
|
||||
SimulatedCounterSettingsDialog dlg = new SimulatedCounterSettingsDialog();
|
||||
dlg.setSerial(counter.getConnectionSettings());
|
||||
dlg.setVisible(true);
|
||||
|
||||
if (dlg.accepted){
|
||||
counter.setConnectionSettings(dlg.getSerial());
|
||||
dlg.dispose();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private final JPanel contentPanel = new JPanel();
|
||||
|
||||
private boolean accepted;
|
||||
private JTextField tfSerial;
|
||||
|
||||
public SimulatedCounterSettingsDialog() {
|
||||
setTitle("Simulierter Zähler");
|
||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
setBounds(100, 100, 450, 300);
|
||||
setModalityType(ModalityType.APPLICATION_MODAL);
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
||||
GridBagLayout gbl_contentPanel = new GridBagLayout();
|
||||
gbl_contentPanel.columnWidths = new int[]{0, 0, 0};
|
||||
gbl_contentPanel.rowHeights = new int[]{0, 0};
|
||||
gbl_contentPanel.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
|
||||
gbl_contentPanel.rowWeights = new double[]{0.0, Double.MIN_VALUE};
|
||||
contentPanel.setLayout(gbl_contentPanel);
|
||||
{
|
||||
JLabel lblAnschluss = new JLabel("Seriennummer:");
|
||||
GridBagConstraints gbc_lblAnschluss = new GridBagConstraints();
|
||||
gbc_lblAnschluss.insets = new Insets(0, 0, 0, 5);
|
||||
gbc_lblAnschluss.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblAnschluss.gridx = 0;
|
||||
gbc_lblAnschluss.gridy = 0;
|
||||
contentPanel.add(lblAnschluss, gbc_lblAnschluss);
|
||||
}
|
||||
{
|
||||
tfSerial = new JTextField();
|
||||
GridBagConstraints gbc_tfSerial = new GridBagConstraints();
|
||||
gbc_tfSerial.anchor = GridBagConstraints.NORTH;
|
||||
gbc_tfSerial.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_tfSerial.gridx = 1;
|
||||
gbc_tfSerial.gridy = 0;
|
||||
contentPanel.add(tfSerial, gbc_tfSerial);
|
||||
tfSerial.setColumns(10);
|
||||
}
|
||||
{
|
||||
JPanel buttonPane = new JPanel();
|
||||
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
||||
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
||||
{
|
||||
JButton okButton = new JButton("OK");
|
||||
okButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
accepted = true;
|
||||
setVisible(false);
|
||||
}
|
||||
});
|
||||
okButton.setActionCommand("OK");
|
||||
buttonPane.add(okButton);
|
||||
getRootPane().setDefaultButton(okButton);
|
||||
}
|
||||
{
|
||||
JButton cancelButton = new JButton("Cancel");
|
||||
cancelButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
setVisible(false);
|
||||
}
|
||||
});
|
||||
cancelButton.setActionCommand("Cancel");
|
||||
buttonPane.add(cancelButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getSerial(){
|
||||
return tfSerial.getText();
|
||||
}
|
||||
public void setSerial(String serial){
|
||||
tfSerial.setText(serial);
|
||||
}
|
||||
|
||||
}
|
|
@ -44,17 +44,6 @@ public class BatchRunner implements PulsCounterApplicationListener{
|
|||
pulsCounterApplication.notifyUiIsFinished(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialPortChanged() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectionStateChanged(Boolean connected) {
|
||||
if (connected){
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void messageArrived(String message) {
|
||||
System.err.println(message);
|
||||
|
|
|
@ -151,7 +151,6 @@ public class ChannelDisplay extends JPanel {
|
|||
|
||||
lName = new JTextField();
|
||||
lName.setEditable(false);
|
||||
lName.setForeground(Color.LIGHT_GRAY);
|
||||
lName.setInheritsPopupMenu(true);
|
||||
GridBagConstraints gbc_lName = new GridBagConstraints();
|
||||
gbc_lName.fill = GridBagConstraints.HORIZONTAL;
|
||||
|
@ -291,7 +290,13 @@ public class ChannelDisplay extends JPanel {
|
|||
}
|
||||
public void setCounter(Integer counter) {
|
||||
this.counter = counter;
|
||||
if (counter != null){
|
||||
tfCounter.setText(String.format("%d", counter));
|
||||
tfCounter.setEnabled(true);
|
||||
} else {
|
||||
tfCounter.setEnabled(false);
|
||||
tfCounter.setText("");
|
||||
}
|
||||
}
|
||||
|
||||
public Double getVoltage() {
|
||||
|
@ -299,7 +304,13 @@ public class ChannelDisplay extends JPanel {
|
|||
}
|
||||
public void setVoltage(Double voltage) {
|
||||
this.voltage = voltage;
|
||||
if (voltage != null){
|
||||
tfAnalog.setText(String.format("%.02f V",voltage));
|
||||
tfAnalog.setEnabled(true);
|
||||
} else {
|
||||
tfAnalog.setEnabled(false);
|
||||
tfAnalog.setText("");
|
||||
}
|
||||
}
|
||||
|
||||
public void setChannelName(String channelName) {
|
||||
|
@ -317,4 +328,16 @@ public class ChannelDisplay extends JPanel {
|
|||
return lName.getText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnabled(boolean enabled) {
|
||||
if (enabled){
|
||||
} else {
|
||||
setVoltage(null);
|
||||
setCounter(null);
|
||||
setOutput(false);
|
||||
setInput(false);
|
||||
setPullup(false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -188,17 +188,11 @@ public class DeviceTestFrame extends JFrame implements PulsCounterApplicationLis
|
|||
lMessages.setModel(messageListModel);
|
||||
|
||||
application().addPulsCounterApplicationListener(this);
|
||||
application().fireConnectionStateChanged(false);
|
||||
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialPortChanged() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
@Override
|
||||
public void connectionStateChanged(Boolean connected) {
|
||||
|
||||
|
@ -237,6 +231,7 @@ public class DeviceTestFrame extends JFrame implements PulsCounterApplicationLis
|
|||
}
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
@Override
|
||||
public synchronized void messageArrived(String message) {
|
||||
|
|
|
@ -7,6 +7,7 @@ import java.awt.GridBagLayout;
|
|||
import java.awt.BorderLayout;
|
||||
import javax.swing.JToolBar;
|
||||
import javax.swing.JSplitPane;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JPanel;
|
||||
import java.awt.GridBagConstraints;
|
||||
import javax.swing.border.TitledBorder;
|
||||
|
@ -21,11 +22,13 @@ import org.hwo.pulscounter.PulsCounterApplication;
|
|||
import org.hwo.pulscounter.PulsCounterApplicationListener;
|
||||
import org.hwo.pulscounter.SnapshotManager.Notification;
|
||||
import org.hwo.pulscounter.device.IDeviceConnector;
|
||||
import org.hwo.pulscounter.device.NoDeviceConnectionException;
|
||||
import org.hwo.servicelink.ServiceLinkException;
|
||||
import org.hwo.servicelink.ServiceLinkRequestFailedException;
|
||||
import org.hwo.tasklet.Tasklet;
|
||||
import org.hwo.tasklet.TaskletListener;
|
||||
import org.hwo.tasklet.TaskletManager;
|
||||
import org.hwo.ui.JObjectSelector;
|
||||
import org.hwo.ui.dialog.SerialPortChooser;
|
||||
import org.omg.CORBA.Environment;
|
||||
|
||||
|
@ -69,8 +72,13 @@ import javax.swing.event.ChangeListener;
|
|||
import javax.swing.plaf.metal.MetalBorders.ToolBarBorder;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import static org.hwo.logging.Logging.log;
|
||||
import static org.hwo.logging.LogLevel.*;
|
||||
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.WindowAdapter;
|
||||
|
||||
public class NewMainWindow implements PulsCounterApplicationListener, TaskletListener{
|
||||
|
||||
|
@ -82,9 +90,10 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis
|
|||
private FlexibleObjectListModel<IDeviceConnector>
|
||||
lmInterfaces = new FlexibleObjectListModel<>();
|
||||
|
||||
private BackgroundThread backgroundThread;
|
||||
|
||||
private JFrame frmSynolog;
|
||||
private JSplitPane splitter;
|
||||
private JTextField tfConnection;
|
||||
private JButton btnSetup;
|
||||
|
||||
private DefaultListModel<String> messageListModel;
|
||||
|
@ -115,7 +124,7 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis
|
|||
private JButton bIntfAdd;
|
||||
private JButton bIntfDel;
|
||||
private JPanel panel_4;
|
||||
private JTextField tfConnectionSettings;
|
||||
private JTextArea tfConnectionSettings;
|
||||
|
||||
|
||||
public static void startGUI(){
|
||||
|
@ -172,9 +181,6 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis
|
|||
|
||||
application().addPulsCounterApplicationListener(this);
|
||||
|
||||
application().fireConnectionStateChanged();
|
||||
application().fireSerialPortChanged();
|
||||
|
||||
application().message("Synololog Applikation wurde gestartet.");
|
||||
|
||||
timerReconnect.scheduleAtFixedRate(new TimerTask() {
|
||||
|
@ -211,50 +217,24 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis
|
|||
}
|
||||
|
||||
|
||||
frmSynolog.addWindowListener(new WindowListener() {
|
||||
|
||||
@Override
|
||||
public void windowOpened(WindowEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowIconified(WindowEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowDeiconified(WindowEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowDeactivated(WindowEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e) {
|
||||
}
|
||||
frmSynolog.addWindowListener(new WindowAdapter() {
|
||||
|
||||
@Override
|
||||
public void windowClosed(WindowEvent e) {
|
||||
backgroundThread.exit();
|
||||
application().notifyUiIsFinished(true);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowActivated(WindowEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
lmInterfaces.setItems(pulsCounterApplication.getInterfaces());
|
||||
//lmInterfaces.setItems(pulsCounterApplication.getInterfaces());
|
||||
if (pulsCounterApplication.getInterfaces().size()>0){
|
||||
interfacesChanged(pulsCounterApplication);
|
||||
lInterfaces.setSelectedIndex(0);
|
||||
}
|
||||
|
||||
backgroundThread = new BackgroundThread();
|
||||
backgroundThread.start();
|
||||
|
||||
frmSynolog.setVisible(true);
|
||||
}
|
||||
|
@ -364,9 +344,9 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis
|
|||
splitter.setRightComponent(panel);
|
||||
GridBagLayout gbl_panel = new GridBagLayout();
|
||||
gbl_panel.columnWidths = new int[]{0, 0};
|
||||
gbl_panel.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0};
|
||||
gbl_panel.rowHeights = new int[]{0, 0, 0, 0};
|
||||
gbl_panel.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||
gbl_panel.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 1.0, 0.0, Double.MIN_VALUE};
|
||||
gbl_panel.rowWeights = new double[]{0.0, 1.0, 0.0, Double.MIN_VALUE};
|
||||
panel.setLayout(gbl_panel);
|
||||
|
||||
JPanel panel_1 = new JPanel();
|
||||
|
@ -381,9 +361,9 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis
|
|||
panel.add(panel_1, gbc_panel_1);
|
||||
GridBagLayout gbl_panel_1 = new GridBagLayout();
|
||||
gbl_panel_1.columnWidths = new int[]{0, 0, 0};
|
||||
gbl_panel_1.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0};
|
||||
gbl_panel_1.rowHeights = new int[]{0, 0, 0, 0, 0};
|
||||
gbl_panel_1.columnWeights = new double[]{1.0, 1.0, Double.MIN_VALUE};
|
||||
gbl_panel_1.rowWeights = new double[]{0.0, 1.0, 1.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
|
||||
gbl_panel_1.rowWeights = new double[]{0.0, 1.0, 1.0, 0.0, Double.MIN_VALUE};
|
||||
panel_1.setLayout(gbl_panel_1);
|
||||
|
||||
bIntfAdd = new JButton("+");
|
||||
|
@ -423,6 +403,17 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis
|
|||
panel_1.add(scrollPane_2, gbc_scrollPane_2);
|
||||
|
||||
lInterfaces = new JList(lmInterfaces);
|
||||
lInterfaces.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if ((e.getClickCount()==2)&&(e.getButton()==e.BUTTON1)){
|
||||
if (selectedDeviceInterface != null){
|
||||
selectedDeviceInterface.showConnctionSetup();
|
||||
frmSynolog.repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
lInterfaces.addListSelectionListener(new ListSelectionListener() {
|
||||
public void valueChanged(ListSelectionEvent e) {
|
||||
selectedInterfaceChanged();
|
||||
|
@ -445,7 +436,7 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis
|
|||
panel_4.setBorder(new TitledBorder(null, "Anschlusseinstellungen", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
||||
GridBagConstraints gbc_panel_4 = new GridBagConstraints();
|
||||
gbc_panel_4.gridwidth = 2;
|
||||
gbc_panel_4.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_panel_4.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_panel_4.fill = GridBagConstraints.BOTH;
|
||||
gbc_panel_4.gridx = 0;
|
||||
gbc_panel_4.gridy = 2;
|
||||
|
@ -457,7 +448,7 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis
|
|||
gbl_panel_4.rowWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||
panel_4.setLayout(gbl_panel_4);
|
||||
|
||||
tfConnectionSettings = new JTextField();
|
||||
tfConnectionSettings = new JTextArea();
|
||||
tfConnectionSettings.setEditable(false);
|
||||
GridBagConstraints gbc_tfConnectionSettings = new GridBagConstraints();
|
||||
gbc_tfConnectionSettings.fill = GridBagConstraints.BOTH;
|
||||
|
@ -467,25 +458,12 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis
|
|||
tfConnectionSettings.setColumns(10);
|
||||
|
||||
GridBagConstraints gbc_cbTrimDevice = new GridBagConstraints();
|
||||
gbc_cbTrimDevice.gridwidth = 2;
|
||||
gbc_cbTrimDevice.anchor = GridBagConstraints.WEST;
|
||||
gbc_cbTrimDevice.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_cbTrimDevice.gridx = 0;
|
||||
gbc_cbTrimDevice.gridy = 4;
|
||||
gbc_cbTrimDevice.gridy = 3;
|
||||
panel_1.add(cbTrimDevice, gbc_cbTrimDevice);
|
||||
|
||||
tfConnection = new JTextField();
|
||||
tfConnection.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
tfConnection.setText("...");
|
||||
tfConnection.setBackground(Color.WHITE);
|
||||
tfConnection.setEditable(false);
|
||||
GridBagConstraints gbc_tfConnection = new GridBagConstraints();
|
||||
gbc_tfConnection.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_tfConnection.gridwidth = 2;
|
||||
gbc_tfConnection.gridx = 0;
|
||||
gbc_tfConnection.gridy = 5;
|
||||
panel_1.add(tfConnection, gbc_tfConnection);
|
||||
tfConnection.setColumns(10);
|
||||
|
||||
JPanel panel_2 = new JPanel();
|
||||
panel_2.setBackground(Color.WHITE);
|
||||
panel_2.setBorder(new TitledBorder(null, "Meldungen", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
||||
|
@ -493,7 +471,7 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis
|
|||
gbc_panel_2.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_panel_2.fill = GridBagConstraints.BOTH;
|
||||
gbc_panel_2.gridx = 0;
|
||||
gbc_panel_2.gridy = 4;
|
||||
gbc_panel_2.gridy = 1;
|
||||
panel.add(panel_2, gbc_panel_2);
|
||||
GridBagLayout gbl_panel_2 = new GridBagLayout();
|
||||
gbl_panel_2.columnWidths = new int[]{142, 0};
|
||||
|
@ -519,7 +497,7 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis
|
|||
GridBagConstraints gbc_panel_3 = new GridBagConstraints();
|
||||
gbc_panel_3.fill = GridBagConstraints.BOTH;
|
||||
gbc_panel_3.gridx = 0;
|
||||
gbc_panel_3.gridy = 5;
|
||||
gbc_panel_3.gridy = 2;
|
||||
panel.add(panel_3, gbc_panel_3);
|
||||
panel_3.setLayout(new BoxLayout(panel_3, BoxLayout.X_AXIS));
|
||||
|
||||
|
@ -558,7 +536,9 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis
|
|||
} else {
|
||||
bIntfDel.setEnabled(true);
|
||||
|
||||
// tfConnectionSettings.setText(String.format("<html>%s</html>", selectedDeviceInterface.getConnectionSettingsText().replaceAll("\n", "<br/>")));
|
||||
tfConnectionSettings.setText(selectedDeviceInterface.getConnectionSettingsText());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -578,7 +558,17 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis
|
|||
|
||||
|
||||
private void addInterface(){
|
||||
pulsCounterApplication.addInterface(pulsCounterApplication.getInterfaceClasses().get(0), "");
|
||||
Class<IDeviceConnector> cidc;
|
||||
|
||||
if (pulsCounterApplication.getInterfaceClasses().size()==1){
|
||||
cidc = pulsCounterApplication.getInterfaceClasses().get(0);
|
||||
} else {
|
||||
cidc = (Class<IDeviceConnector>)JObjectSelector.execute(pulsCounterApplication.getInterfaceClasses().toArray());
|
||||
}
|
||||
|
||||
if (cidc != null){
|
||||
pulsCounterApplication.addInterface(cidc, "");
|
||||
};
|
||||
|
||||
}
|
||||
private void removeInterface(){
|
||||
|
@ -588,14 +578,53 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis
|
|||
}
|
||||
}
|
||||
|
||||
private void setSerialPort(NewSerialPort serialPort){
|
||||
PulsCounterApplication.getApplication().setSerialPort(serialPort);
|
||||
|
||||
|
||||
private synchronized void updateDeviceView(){
|
||||
if (selectedDeviceInterface != null){
|
||||
try {
|
||||
int[] values = selectedDeviceInterface.getCounters();
|
||||
float[] analogs = selectedDeviceInterface.getAnalogs();
|
||||
int inputs,
|
||||
outputs,
|
||||
pullups;
|
||||
|
||||
inputs = selectedDeviceInterface.getInputs();
|
||||
outputs = selectedDeviceInterface.getOutputs();
|
||||
pullups = selectedDeviceInterface.getPullups();
|
||||
|
||||
|
||||
for (int n=0;n<32;n++){
|
||||
channelDisplays[n].setEnabled(true);
|
||||
channelDisplays[n].setCounter(values[n]);
|
||||
|
||||
channelDisplays[n].setInput( ((inputs & (1<<n)) != 0) ? true : false);
|
||||
channelDisplays[n].setOutput( ((outputs & (1<<n)) != 0) ? true : false);
|
||||
channelDisplays[n].setPullup( ((pullups & (1<<n)) != 0) ? true : false);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialPortChanged() {
|
||||
for (int n=0;n<8;n++){
|
||||
channelDisplays[n].setVoltage((double)analogs[n]);
|
||||
}
|
||||
|
||||
} catch (NoDeviceConnectionException e){
|
||||
log("No Device");
|
||||
} catch (Exception e){
|
||||
log(e);
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
for (int n=0;n<32;n++){
|
||||
channelDisplays[n].setEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
@Override
|
||||
public void connectionStateChanged(Boolean connected) {
|
||||
if (connected){
|
||||
|
@ -615,7 +644,7 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis
|
|||
|
||||
trimDeviceTimeSlice = application().getServiceLink().getServiceRegisterCache().getCachedInteger(13, 0, 0x1302);
|
||||
|
||||
/* Trim helper initialisieren */
|
||||
// Trim helper initialisieren
|
||||
trimTicksOnConnect = null;
|
||||
|
||||
application().getSnapshotManager().notify(Notification.FULLSYNC);
|
||||
|
@ -656,7 +685,7 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis
|
|||
this.connected = connected;
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
@Override
|
||||
public synchronized void messageArrived(String message) {
|
||||
if (EventQueue.isDispatchThread()){
|
||||
|
@ -697,7 +726,7 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis
|
|||
Float[] analog = new Float[8];
|
||||
|
||||
for (int i=0;i<32;i++){
|
||||
values[i] = application().getServiceLink().getServiceRegisterCache().getCachedInteger(13, 0, 0x0600 + i);
|
||||
|
||||
|
||||
if (i<8){
|
||||
analog[i] = application().getServiceLink().getServiceRegisterCache().getCachedFloat(13, 0, 0x8000 + i ) * 10;
|
||||
|
@ -910,17 +939,7 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis
|
|||
}
|
||||
|
||||
private void channelReset(int channel,int setValue){
|
||||
try {
|
||||
|
||||
application().getServiceLink().writeInt(13, 0, 0x0600 + channel, setValue);
|
||||
|
||||
} catch (ServiceLinkRequestFailedException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ServiceLinkException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
selectedDeviceInterface.setCounter(channel, setValue);
|
||||
}
|
||||
|
||||
private void channelSet(ChannelDisplay display,int setValue){
|
||||
|
@ -932,6 +951,60 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
class BackgroundThread extends Thread {
|
||||
|
||||
private int timeout;
|
||||
private boolean exit;
|
||||
|
||||
public BackgroundThread(){
|
||||
timeout = 500;
|
||||
exit = false;
|
||||
}
|
||||
|
||||
public void exit(){
|
||||
synchronized (this){
|
||||
this.exit = true;
|
||||
notify();
|
||||
};
|
||||
while (isAlive()){
|
||||
try {
|
||||
sleep(50);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized int getTimeout() {
|
||||
return timeout;
|
||||
}
|
||||
public synchronized void setTimeout(int timeout) {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
synchronized (this) {
|
||||
log(INFO,"newMainWindow: backgroundThread: started");
|
||||
|
||||
while (!exit){
|
||||
try {
|
||||
wait(timeout);
|
||||
|
||||
updateDeviceView();
|
||||
} catch (InterruptedException e){
|
||||
}
|
||||
}
|
||||
|
||||
log(INFO,"newMainWindow: backgroundThread: exited");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue