WIP 160913

WIP-PC2
Harald Wolff 2016-09-13 12:07:01 +02:00
parent 246955f622
commit 84e912b73e
13 changed files with 1080 additions and 1563 deletions

View File

@ -125,78 +125,78 @@ public class ExportSetting {
}
public void export(){
SnapshotManager ssm = PulsCounterApplication.getApplication().getSnapshotManager();
Hashtable<String, CSV> hash = new Hashtable<String, CSV>();
for (int n=0;n<ssm.size();n++){
SnapShot ss = ssm.loadSnapShot(n);
String fn = calculateFileName(fileName, ss);
if ((triggerType==TriggerType.ALL)||(ss.getTriggerType()==triggerType)){
if (triggerSource.equals(-1) || triggerSource.equals(ss.getSource())){
if (!hash.containsKey(fn)){
hash.put(fn, new CSV());
if (extended){
hash.get(fn).getRecords().add(new CSVRecord(new Object[]{
"Zeitstempel", "Datum/Zeit", "Trigger", "Quelle",
"CH0","CH1","CH2","CH3","CH4","CH5","CH6","CH7",
"CH8","CH9","CH10","CH11","CH12","CH13","CH14","CH15",
"CH16","CH17","CH18","CH19","CH20","CH21","CH22","CH23",
"CH24","CH25","CH26","CH27","CH28","CH29","CH30","CH31",
"AN0","AN1","AN2","AN3","AN4","AN5","AN6","AN7"}));
} else {
hash.get(fn).getRecords().add(new CSVRecord(new Object[]{
"Datum/Zeit",
"CH0","CH1","CH2","CH3","CH4","CH5","CH6","CH7",
"CH8","CH9","CH10","CH11","CH12","CH13","CH14","CH15",
"CH16","CH17","CH18","CH19","CH20","CH21","CH22","CH23",
"CH24","CH25","CH26","CH27","CH28","CH29","CH30","CH31",
"AN0","AN1","AN2","AN3","AN4","AN5","AN6","AN7"}));
}
}
hash.get(fn).getRecords().add(ss.getCSVRecord(extended));
}
}
}
for (String fn: hash.keySet()){
if (recordDelta){
CSV csv = hash.get(fn);
if (!csv.getRecords().isEmpty()){
Iterator<CSVRecord> iter = csv.getRecords().iterator();
iter.next();
CSVRecord n = iter.next();
Integer[] vals = new Integer[32];
for (int i=0;i<32;i++){
vals[i] = n.getIntegerValue(extended ? i + 4 : i + 1 );
}
while (iter.hasNext()){
n = iter.next();
for (int i=0;i<32;i++){
Integer v = n.getIntegerValue(extended ? i + 4 : i + 1 );
n.setValue(extended ? i + 4 : i + 1 , v - vals[i]);
vals[i] = v;
}
}
csv.getRecords().remove(1);
}
}
hash.get(fn).saveToFile(new File(path,fn));
}
// SnapshotManager ssm = PulsCounterApplication.getApplication().getSnapshotManager();
//
// Hashtable<String, CSV> hash = new Hashtable<String, CSV>();
//
// for (int n=0;n<ssm.size();n++){
// SnapShot ss = ssm.loadSnapShot(n);
// String fn = calculateFileName(fileName, ss);
//
// if ((triggerType==TriggerType.ALL)||(ss.getTriggerType()==triggerType)){
// if (triggerSource.equals(-1) || triggerSource.equals(ss.getSource())){
//
// if (!hash.containsKey(fn)){
// hash.put(fn, new CSV());
// if (extended){
// hash.get(fn).getRecords().add(new CSVRecord(new Object[]{
// "Zeitstempel", "Datum/Zeit", "Trigger", "Quelle",
// "CH0","CH1","CH2","CH3","CH4","CH5","CH6","CH7",
// "CH8","CH9","CH10","CH11","CH12","CH13","CH14","CH15",
// "CH16","CH17","CH18","CH19","CH20","CH21","CH22","CH23",
// "CH24","CH25","CH26","CH27","CH28","CH29","CH30","CH31",
// "AN0","AN1","AN2","AN3","AN4","AN5","AN6","AN7"}));
// } else {
// hash.get(fn).getRecords().add(new CSVRecord(new Object[]{
// "Datum/Zeit",
// "CH0","CH1","CH2","CH3","CH4","CH5","CH6","CH7",
// "CH8","CH9","CH10","CH11","CH12","CH13","CH14","CH15",
// "CH16","CH17","CH18","CH19","CH20","CH21","CH22","CH23",
// "CH24","CH25","CH26","CH27","CH28","CH29","CH30","CH31",
// "AN0","AN1","AN2","AN3","AN4","AN5","AN6","AN7"}));
// }
// }
//
// hash.get(fn).getRecords().add(ss.getCSVRecord(extended));
// }
// }
// }
//
// for (String fn: hash.keySet()){
// if (recordDelta){
// CSV csv = hash.get(fn);
// if (!csv.getRecords().isEmpty()){
// Iterator<CSVRecord> iter = csv.getRecords().iterator();
//
// iter.next();
//
// CSVRecord n = iter.next();
// Integer[] vals = new Integer[32];
//
// for (int i=0;i<32;i++){
// vals[i] = n.getIntegerValue(extended ? i + 4 : i + 1 );
// }
//
// while (iter.hasNext()){
// n = iter.next();
//
// for (int i=0;i<32;i++){
// Integer v = n.getIntegerValue(extended ? i + 4 : i + 1 );
// n.setValue(extended ? i + 4 : i + 1 , v - vals[i]);
// vals[i] = v;
// }
// }
//
// csv.getRecords().remove(1);
//
// }
//
//
// }
//
//
// hash.get(fn).saveToFile(new File(path,fn));
// }
}

View File

@ -52,7 +52,6 @@ public class PulsCounterApplication implements ServiceLinkListener{
private Properties applicationConfiguration,
defaultConfiguration;
private List<IDeviceConnector> deviceConnectors;
private Object uiSynchronization;
private boolean uiIsFinished;
@ -80,8 +79,6 @@ public class PulsCounterApplication implements ServiceLinkListener{
private boolean snapshotLock;
private SnapshotManager snapshotManager;
private List<ExportSetting> exportSettings;
private Scheduler scheduler;
@ -102,7 +99,6 @@ public class PulsCounterApplication implements ServiceLinkListener{
/* Initialize fields... */
uiIsFinished = false;
uiSynchronization = new Object();
deviceConnectors = new ArrayList<>();
applicationListeners = new LinkedList<PulsCounterApplicationListener>();
unseenMessages = new Vector<String>();
@ -403,6 +399,27 @@ public class PulsCounterApplication implements ServiceLinkListener{
}
/* Snapshots */
public void checkForSnapShots(){
for (IDeviceConnector idc: this.interfaces){
Integer avail = idc.getAvailableSnapshots();
log(INFO,"Interface %s has %d available Snapshots", idc.toString(), avail);
SnapShot[] snapshots = idc.readSnapShots();
if (snapshots != null){
getDatabase().storeSnapshots(snapshots);
}
}
}
public void addSnapshotToDatabase(SnapShot snapShot){
getDatabase().storeSnapshots(new SnapShot[]{ snapShot });
}
/* ToDO: Upgrade the old stuff ... */
/*
@ -464,116 +481,11 @@ public class PulsCounterApplication implements ServiceLinkListener{
}
};
}
public synchronized NewSerialPort getSerialPort() {
if (serialPort == null){
serialPort = new NewSerialPort("COM1:");
}
return serialPort;
}
public synchronized void setSerialPort(NewSerialPort serialPort) {
if (serviceLink != null){
serviceLink.close();
serviceLink = null;
}
this.serialPort = serialPort;
getServiceLink();
fireServiceLinkChanged();
}
public synchronized ServiceLink getServiceLink() {
if (serviceLink == null){
serviceLink = new ServiceLink(getSerialPort());
serviceLink.getSerialPort().setTimeOut(200);
serviceLink.addServiceLinkListener(this);
}
return serviceLink;
}
public synchronized void setServiceLink(ServiceLink serviceLink) {
if (serviceLink != null){
serviceLink.close();
}
this.serviceLink = serviceLink;
fireServiceLinkChanged();
}
private Preferences getPreferencesNode(){
return Preferences.userNodeForPackage(getClass());
}
public void savePrefs(){
Preferences prefs = getPreferencesNode();
if (serialPort != null)
prefs.put("io.port", getSerialPort().getPortName());
System.out.println(String.format("savePrefs(): %d exportSettings werden gesichert.", exportSettings.size()));
if (exportSettings.size()>0)
{
for (int n=0;n<exportSettings.size();n++){
prefs.put(String.format("export.configuration.%d", n), ConfigurableObjects.getConfiguration(exportSettings.get(n)));
}
prefs.putInt("export.configurations", exportSettings.size());
};
Preferences nChannels = prefs.node("channels");
for (int n=0;n<32;n++){
nChannels.put(String.format("%d.description", n), channelDescriptions[n]);
}
try {
prefs.flush();
} catch (BackingStoreException e)
{
e.printStackTrace();
}
}
private void loadPrefs(){
Preferences prefs = getPreferencesNode();
String sn = prefs.get("io.port", null);
if (sn != null){
NewSerialPort nsp = new NewSerialPort(sn);
setSerialPort(nsp);
}
exportSettings.clear();
int nESC = prefs.getInt("export.configurations", 0);
for (int n=0;n<nESC;n++){
ExportSetting es = new ExportSetting();
ConfigurableObjects.setConfiguration(es, prefs.get(String.format("export.configuration.%d", n), ""));
exportSettings.add(es);
}
System.out.println(String.format("loadPrefs(): %d exportSettings geladen.", nESC));
Preferences nChannels = prefs.node("channels");
for (int n=0;n<32;n++){
channelDescriptions[n] = nChannels.get(String.format("%d.description", n), "");
}
}
public String getChannelDescription(int n){
return ""; // channelDescriptions[n];
}
public void setChannelDescription(int n,String desc){
channelDescriptions[n] = desc;
}
@Override
public void connectionStateChanged(Boolean connected) {
}
public SnapshotManager getSnapshotManager() {
return snapshotManager;
}
public List<ExportSetting> getExportSettings() {
return exportSettings;

View File

@ -211,20 +211,7 @@ public class SnapShot {
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("SnapShot(");
sb.append(this.timestamp);
sb.append(":");
for (int i=0;i<32;i++){
if (i>0)
sb.append(",");
sb.append(this.values[i]);
}
sb.append(")");
return sb.toString();
return String.format("SnapShot [ Device: %d Timestamp: %d ]",this.deviceSerial,this.timestamp);
}
}

View File

@ -1,321 +0,0 @@
package org.hwo.pulscounter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.util.Hashtable;
import org.hwo.servicelink.ServiceLinkException;
import org.hwo.servicelink.ServiceLinkRequestFailedException;
import org.hwo.tasklet.Tasklet;
import org.hwo.tasklet.TaskletManager;
public class SnapshotManager {
public enum Notification { INITIALIZE, SHUTDOWN, SYNC, FULLSYNC };
private RandomAccessFile file;
private Hashtable<Long,Integer> hashList;
private Integer lastNewest,
snapshotSize;
public SnapshotManager() throws FileNotFoundException {
this.file = new RandomAccessFile("snapshots.dat", "rws");
this.initialize();
}
public SnapshotManager(File file) throws FileNotFoundException {
this.file = new RandomAccessFile(file, "rws");
this.initialize();
}
private synchronized void initialize(){
hashList = new Hashtable<Long, Integer>();
}
private PulsCounterApplication application(){
return PulsCounterApplication.getApplication();
}
public synchronized void notify(Notification notification){
switch (notification){
case INITIALIZE:
TaskletManager.instance().enqueue(new Tasklet("SnapShot Manager initialisieren") {
@Override
public void run() {
doInitialize();
}
});
break;
case SHUTDOWN:
doShutdown();
return;
case FULLSYNC:
TaskletManager.instance().enqueue(new Tasklet("Volle Synchronisation") {
@Override
public void run() {
doFullSync();
}
});
break;
case SYNC:
TaskletManager.instance().enqueue(new Tasklet("Schnelle Synchronisation") {
@Override
public void run() {
doSync();
}
});
break;
}
}
public synchronized void doInitialize(){
try {
byte[] buffer = new byte[256];
ByteBuffer bb = ByteBuffer.wrap(buffer);
Integer ind = 0;
application().message("SnapShotManager: Initialisieren");
hashList.clear();
file.seek(0);
while (file.read(buffer)==256){
Integer timestamp,field0;
Long hash;
timestamp = bb.getInt(0);
field0 = bb.getInt(4);
hash = ((long)timestamp << 32) | field0;
hashList.put(hash, ind++);
}
application().message(String.format("SnapShotManager: %d SnapShots lokal", hashList.size()));
} catch (Exception e){
e.printStackTrace();
application().message("SnapShotManager meldet Fehler: " + e.toString());
}
}
public synchronized void doShutdown(){
}
public synchronized void doFullSync(){
Integer ind_oldest,ind_newest,ind;
int n = 0;
application().message("SnapShotManager: Beginne volle synchronisation");
try {
try {
snapshotSize = application().getServiceLink().readInt(13, 0, 0x0582);
} catch (ServiceLinkRequestFailedException e){
snapshotSize = 512;
}
ind_oldest = application().getServiceLink().readInt(13, 0, 0x0580);
ind_newest = application().getServiceLink().readInt(13, 0, 0x0581);
lastNewest = ind_newest;
System.out.println(String.format("ind_oldest: %d", ind_oldest));
System.out.println(String.format("ind_newest: %d", ind_newest));
ind = ind_oldest;
do {
TaskletManager.instance().setProgress(String.format("%d / %d", n++, snapshotSize));
Integer id;
try {
application().getServiceLink().writeInt(13, 0, 0x0500, ind);
id = application().getServiceLink().readInt(13, 0, 0x0500);
if (!id.equals(ind)){
System.out.println(String.format("bus_snapshot_id: %d != %d",ind,id));
} else {
Integer ts,f0;
ts = application().getServiceLink().readInt(13, 0, 0x0501);
f0 = application().getServiceLink().readInt(13, 0, 0x0502);
Long hash = ((long)ts<<32) | f0;
if (!hashList.containsKey(hash)){
SnapShot snap = snapshotFromDevice(ind);
if (snap != null){
Integer find = snapshotToFile(snap);
if (find != -1){
hashList.put(snap.getHashCode(), find);
} else {
application().message("Snapshot konnte nicht gespeichert werden!");
}
};
};
};
if (ind.equals(ind_newest))
break;
} catch (ServiceLinkRequestFailedException failed){
failed.printStackTrace();
};
ind++;
if (ind > snapshotSize){
ind = 0;
}
} while (!ind.equals(ind_oldest));
} catch (Exception e){
e.printStackTrace();
}
application().message(String.format("SnapShotManager: %d bekannte Snapshots nach FullSync", hashList.size()));
}
private synchronized void doSync(){
Integer ind_oldest,ind_newest,ind;
int n,c;
try {
ind_newest = application().getServiceLink().readInt(13, 0, 0x0581);
if (ind_newest == lastNewest)
return;
ind = lastNewest;
c = ind_newest - lastNewest;
if (c < 0)
c+=snapshotSize;
n = 0;
if (c == 0){
return;
}
do {
TaskletManager.instance().setProgress(String.format("%d / %d", n,c));
ind ++;
ind &= 0x1FF;
n++;
SnapShot snap = snapshotFromDevice(ind);
if (snap != null){
Integer ind_file = snapshotToFile(snap);
hashList.put(snap.getHashCode(), ind_file);
}
} while (!ind.equals(ind_newest));
lastNewest = ind_newest;
application().message(String.format("%d neue Snapshots", n));
} catch (ServiceLinkRequestFailedException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ServiceLinkException e) {
e.printStackTrace();
}
}
public synchronized SnapShot loadSnapShot(int ind){
byte[] bytes = new byte[256];
try {
file.seek(ind * 256);
file.read(bytes);
return new SnapShot(bytes);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
public synchronized Integer size(){
try {
return ((int)(file.length())/256);
} catch (IOException e) {
e.printStackTrace();
}
return 0;
}
private synchronized Integer snapshotToFile(SnapShot snap){
Long find;
try {
find = file.length()/256;
file.seek(find * 256);
file.write(snap.toBytes());
return find.intValue();
} catch (IOException e) {
e.printStackTrace();
return -1;
}
}
private SnapShot snapshotFromDevice(Integer ind){
SnapShot ss = new SnapShot();
Integer id;
try {
application().getServiceLink().writeInt(13, 0, 0x0500, ind);
id = application().getServiceLink().readInt(13, 0, 0x0500);
if (!id.equals(ind)){
System.out.println(String.format("bus_snapshot_id: %d != %d",ind,id));
return null;
};
ss.setTimestamp( application().getServiceLink().readInt(13, 0, 0x0501));
ss.setField0( application().getServiceLink().readInt(13, 0, 0x0502));
ss.setInputmask( application().getServiceLink().readInt(13, 0, 0x0503));
ss.setOutputmask( application().getServiceLink().readInt(13, 0, 0x0504));
ss.setPullupmask( application().getServiceLink().readInt(13, 0, 0x0505));
ss.setInvertmask( application().getServiceLink().readInt(13, 0, 0x0506));
ss.setTriggermask( application().getServiceLink().readInt(13, 0, 0x0507));
for (int i=0;i<32;i++){
ss.setValue(i, application().getServiceLink().readInt(13, 0, 0x0510 + i));
}
for (int i=0;i<8;i++){
ss.setAnalog(i, application().getServiceLink().readInt(13, 0, 0x0508 + i));
}
} catch (Exception e){
e.printStackTrace();
return null;
}
System.out.print(String.format("Snapshot from Device: %s\n", ss.toString()));
return ss;
}
}

View File

@ -94,6 +94,26 @@ public class PulsCounterDatabase {
}
public void storeSnapshots(SnapShot[] snapShots){
for (SnapShot snapShot: snapShots){
storeSnapshot(snapShot);
}
}
private void storeSnapshot(SnapShot snapShot){
executeVerySimpleQuery("INSERT INTO snapshots (id,device,timestamp,counters,analogs,inputs,outputs,pullups,inverts) VALUES(uuid(),?,?,?,?,?,?,?,?)",
snapShot.getDeviceSerial(),
snapShot.getTimestamp(),
snapShot.getValues(),
snapShot.getAnalog(),
snapShot.getInputmask(),
snapShot.getOutputmask(),
snapShot.getPullupmask(),
snapShot.getInvertmask()
);
// (id uuid,device integer,timestamp integer,counters integer array[32],analogs integer array[8],inputs integer,outputs integer,pullups integer,inverts integer);
}

View File

@ -5,9 +5,10 @@
*/
create table properties (id uuid primary key,name varchar(255) unique,value varchar(255));
create table props (id uuid primary key,name varchar(255) unique,value varchar(255));
create table devices (id uuid,serial varchar(12));
create table snapshots (id uuid,device uuid,timestamp integer,counters int array[32],analogs int array[8],inputs int,outputs int,pullups int,inverts int);
create table snapshots (id uuid,device integer,timestamp integer,counters integer array[32],analogs integer array[8],inputs integer,outputs integer,pullups integer,inverts integer);
insert into properties (id,name,value) values(uuid(),'db.schema.version','0');
insert into props (id,name,value) values(uuid(),'db.schema.version','0');

View File

@ -1,6 +1,9 @@
package org.hwo.pulscounter.device;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import org.hwo.io.NewSerialPort.NewSerialPort;
import org.hwo.pulscounter.SnapShot;
@ -292,6 +295,7 @@ public class ServiceLinkDeviceConnector implements IDeviceConnector {
@Override
public SnapShot[] readSnapShots() {
Integer s = readDeviceSerial();
List<SnapShot> snapshots = new LinkedList<>();
if (s != null){
Integer oldest,newest,sssize;
@ -307,6 +311,9 @@ public class ServiceLinkDeviceConnector implements IDeviceConnector {
newest = serviceLink.readInt(13, 0, 0x0581);
sssize = serviceLink.readInt(13, 0, 0x0582);
if (newest == null)
return null;
while (!oldest.equals(newest)){
Integer id;
@ -348,25 +355,40 @@ public class ServiceLinkDeviceConnector implements IDeviceConnector {
SnapShot ss = new SnapShot(s);
ss.setTimestamp(timestamp);
ss.setField0(flags);
ss.setInputmask(in);
ss.setOutputmask(out);
ss.setInvertmask(inv);
ss.setTriggermask(trigger);
ss.setPullupmask(pu);
for (int i=0;i<32;i++){
ss.setValue(i, counters[i]);
}
for (int i=0;i<8;i++){
ss.setAnalog(i, analogs[i]);
}
log(INFO,"Snapshot read: %s",id);
snapshots.add(ss);
};
} catch (ServiceLinkRequestFailedException e){
log(e);
}
oldest++;
if (oldest >= sssize){
oldest = 0;
}
}
indSnapshotOldest = oldest;
} catch (IOException | ServiceLinkException e) {
log(e);
}
}
return null;
return snapshots.toArray(new SnapShot[0]);
}
@Override

View File

@ -28,7 +28,6 @@ import org.hwo.io.SerialPort;
import org.hwo.io.NewSerialPort.NewSerialPort;
import org.hwo.pulscounter.PulsCounterApplication;
import org.hwo.pulscounter.SnapShot;
import org.hwo.pulscounter.SnapshotManager;
import org.hwo.servicelink.ServiceLink;
import org.hwo.servicelink.ServiceLinkException;
import org.hwo.servicelink.ServiceLinkRequestFailedException;
@ -132,7 +131,7 @@ public class AppSettingsFrame extends JDialog {
JButton btnWhlen = new JButton("wählen...");
btnWhlen.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
chooseSerialPort();
}
});
GridBagConstraints gbc_btnWhlen = new GridBagConstraints();
@ -239,7 +238,7 @@ public class AppSettingsFrame extends JDialog {
JButton btnUpdate = new JButton("Update...");
btnUpdate.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
readDebug();
// readDebug();
}
});
GridBagConstraints gbc_btnUpdate = new GridBagConstraints();
@ -258,7 +257,7 @@ public class AppSettingsFrame extends JDialog {
JButton btnDumpSnapshots = new JButton("Dump Snapshots");
btnDumpSnapshots.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dumpSnapshots();
// dumpSnapshots();
}
});
GridBagConstraints gbc_btnDumpSnapshots = new GridBagConstraints();
@ -270,7 +269,7 @@ public class AppSettingsFrame extends JDialog {
JButton btnResetDevice = new JButton("Reset Device");
btnResetDevice.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
doRESETDevice();
// doRESETDevice();
}
});
GridBagConstraints gbc_btnResetDevice = new GridBagConstraints();
@ -282,7 +281,7 @@ public class AppSettingsFrame extends JDialog {
JButton btnRckDump = new JButton("RCK Dump");
btnRckDump.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
doRCKDump();
// doRCKDump();
}
});
GridBagConstraints gbc_btnRckDump = new GridBagConstraints();
@ -291,7 +290,7 @@ public class AppSettingsFrame extends JDialog {
panel_5.add(btnRckDump, gbc_btnRckDump);
btnRamImage.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
doRAMImage();
// doRAMImage();
}
});
@ -395,9 +394,7 @@ public class AppSettingsFrame extends JDialog {
JButton bOK = new JButton("OK");
bOK.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
accept();
setVisible(false);
application().savePrefs();
}
});
GridBagConstraints gbc_bOK = new GridBagConstraints();
@ -406,9 +403,10 @@ public class AppSettingsFrame extends JDialog {
gbc_bOK.gridy = 0;
panel_1.add(bOK, gbc_bOK);
initialize();
//initialize();
}
/*
private void initialize(){
PulsCounterApplication pc2a = PulsCounterApplication.getApplication();
@ -554,10 +552,6 @@ public class AppSettingsFrame extends JDialog {
Integer i32 = sl.readInt(13, 0, 0x00ee);
o.write(i32 & 0xff);
/* o.write((i32>>8) & 0xff);
o.write((i32>>16) & 0xff);
o.write((i32>>24) & 0xff);
*/
}
o.close();
@ -638,6 +632,6 @@ SnapshotManager ssm = PulsCounterApplication.getApplication().getSnapshotManager
}
msgExc.setText(sb.toString());
}
*/
}

View File

@ -3,7 +3,6 @@ package org.hwo.pulscounter.ui;
import org.hwo.pulscounter.ExportSetting;
import org.hwo.pulscounter.PulsCounterApplication;
import org.hwo.pulscounter.PulsCounterApplicationListener;
import org.hwo.pulscounter.SnapshotManager.Notification;
import org.hwo.servicelink.ServiceLinkException;
public class BatchRunner implements PulsCounterApplicationListener{
@ -21,12 +20,8 @@ public class BatchRunner implements PulsCounterApplicationListener{
}
public void run(){
/*
try {
pulsCounterApplication.getServiceLink().open();
Thread.sleep(500);
pulsCounterApplication.getSnapshotManager().doFullSync();
for (ExportSetting es: pulsCounterApplication.getExportSettings()){
if (es.getAutostart()){
@ -40,7 +35,7 @@ public class BatchRunner implements PulsCounterApplicationListener{
// TODO Auto-generated catch block
e.printStackTrace();
}
*/
pulsCounterApplication.notifyUiIsFinished(false);
}

View File

@ -43,466 +43,468 @@ import javax.swing.JScrollPane;
import javax.swing.JTable;
public class DeviceConfiguration extends JFrame {
};
private JPanel contentPane;
int currentChannel;
private BitFieldEditor bfeIntervall;
private JTimeSpanEditor tseI3;
private JTimeSpanEditor tseI2;
private JTimeSpanEditor tseI1;
private JTimeSpanEditor tseI0;
private TableMapper tmSettings;
int outputs,
pullups,
inverts,
trigger;
int[] filter,
windows;
private JTable tSettings;
/**
* Create the frame.
*/
public DeviceConfiguration() {
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setBounds(100, 100, 860, 498);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
GridBagLayout gbl_contentPane = new GridBagLayout();
gbl_contentPane.columnWidths = new int[] {30, 0, 0};
gbl_contentPane.rowHeights = new int[] {183, 0};
gbl_contentPane.columnWeights = new double[]{1.0, 0.0, 0.0};
gbl_contentPane.rowWeights = new double[]{1.0, 0.0};
contentPane.setLayout(gbl_contentPane);
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
GridBagConstraints gbc_tabbedPane = new GridBagConstraints();
gbc_tabbedPane.gridwidth = 3;
gbc_tabbedPane.fill = GridBagConstraints.BOTH;
gbc_tabbedPane.insets = new Insets(0, 0, 5, 0);
gbc_tabbedPane.gridx = 0;
gbc_tabbedPane.gridy = 0;
contentPane.add(tabbedPane, gbc_tabbedPane);
JPanel panel_2 = new JPanel();
tabbedPane.addTab("Intervalle", null, panel_2, null);
GridBagLayout gbl_panel_2 = new GridBagLayout();
gbl_panel_2.columnWidths = new int[]{0, 0, 0};
gbl_panel_2.rowHeights = new int[]{0, 0, 0, 0, 0, 0};
gbl_panel_2.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
gbl_panel_2.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
panel_2.setLayout(gbl_panel_2);
bfeIntervall = new BitFieldEditor();
bfeIntervall.setToolTipText("<html>\n<b>Tagesbasierte Intervalle</b><br/>\n<br/>\nTagesbasierte Intervalle werden immer auf 0:00:00 Uhr des aktuellen Tages bezogen ausgeführt.<br/>\nDies ermöglicht nicht nur eine Regelmäßige Aufzeichnung, sondern erzwingt auch eine Aufzeichnung<br/>\nin einem festgelegten immer gleichen Raster.<br/>\n<br/>\nNicht tageszeitbasierte Intervalle werden mit Bezug auf den 1.1.1970 0:00:00 Uhr ausgeführt.<br/>\nDiese ermöglichen eine stete regelmäßige Aufzeichnung bei der die tageszeit ignoriert wird.\n</html>");
bfeIntervall.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
int v = bfeIntervall.getIntValue();
tseI0.setDaysEnabled(((v & 0x01)==0));
tseI1.setDaysEnabled(((v & 0x02)==0));
tseI2.setDaysEnabled(((v & 0x04)==0));
tseI3.setDaysEnabled(((v & 0x08)==0));
ServiceLink sl = PulsCounterApplication.getApplication().getServiceLink();
try {
sl.writeInt(13, 0, 0x1003, bfeIntervall.getIntValue());
} catch (ServiceLinkRequestFailedException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
} catch (ServiceLinkException e1) {
e1.printStackTrace();
}
}
});
JLabel lblTageszeitabhngigkeit = new JLabel("Tageszeitabhängigkeit:");
GridBagConstraints gbc_lblTageszeitabhngigkeit = new GridBagConstraints();
gbc_lblTageszeitabhngigkeit.fill = GridBagConstraints.HORIZONTAL;
gbc_lblTageszeitabhngigkeit.insets = new Insets(0, 0, 5, 5);
gbc_lblTageszeitabhngigkeit.gridx = 0;
gbc_lblTageszeitabhngigkeit.gridy = 0;
panel_2.add(lblTageszeitabhngigkeit, gbc_lblTageszeitabhngigkeit);
GridBagConstraints gbc_bfeIntervall = new GridBagConstraints();
gbc_bfeIntervall.anchor = GridBagConstraints.NORTH;
gbc_bfeIntervall.insets = new Insets(0, 0, 5, 0);
gbc_bfeIntervall.fill = GridBagConstraints.HORIZONTAL;
gbc_bfeIntervall.gridx = 1;
gbc_bfeIntervall.gridy = 0;
panel_2.add(bfeIntervall, gbc_bfeIntervall);
JLabel lblIntervall = new JLabel("Intervall 0:");
lblIntervall.setToolTipText("<html>\n<b>Intervall</b><br/>\n<br/>\nStellen Sie die gewünschten Intervalllängen ein.<br/>\n<br/>\nEinheiten: <b>Tage, Stunden, Minuten, Sekunden</b>\n</html>");
GridBagConstraints gbc_lblIntervall = new GridBagConstraints();
gbc_lblIntervall.fill = GridBagConstraints.HORIZONTAL;
gbc_lblIntervall.insets = new Insets(0, 0, 5, 5);
gbc_lblIntervall.gridx = 0;
gbc_lblIntervall.gridy = 1;
panel_2.add(lblIntervall, gbc_lblIntervall);
tseI0 = new JTimeSpanEditor();
tseI0.setToolTipText("<html>\n<b>Intervall</b><br/>\n<br/>\nStellen Sie die gewünschten Intervalllängen ein.<br/>\n<br/>\nEinheiten: <b>Tage, Stunden, Minuten, Sekunden</b>\n</html>");
tseI0.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
System.err.println("FOCUS LOST 0");
ServiceLink sl = PulsCounterApplication.getApplication().getServiceLink();
try {
sl.writeInt(13, 0, 0x1010, (Integer)tseI0.getValue());
} catch (ServiceLinkRequestFailedException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
} catch (ServiceLinkException e1) {
e1.printStackTrace();
}
}
});
GridBagConstraints gbc_tseI0 = new GridBagConstraints();
gbc_tseI0.anchor = GridBagConstraints.WEST;
gbc_tseI0.insets = new Insets(0, 0, 5, 0);
gbc_tseI0.gridx = 1;
gbc_tseI0.gridy = 1;
panel_2.add(tseI0, gbc_tseI0);
JLabel lblIntervall_1 = new JLabel("Intervall 1:");
lblIntervall_1.setToolTipText("<html>\n<b>Intervall</b><br/>\n<br/>\nStellen Sie die gewünschten Intervalllängen ein.<br/>\n<br/>\nEinheiten: <b>Tage, Stunden, Minuten, Sekunden</b>\n</html>");
GridBagConstraints gbc_lblIntervall_1 = new GridBagConstraints();
gbc_lblIntervall_1.fill = GridBagConstraints.HORIZONTAL;
gbc_lblIntervall_1.insets = new Insets(0, 0, 5, 5);
gbc_lblIntervall_1.gridx = 0;
gbc_lblIntervall_1.gridy = 2;
panel_2.add(lblIntervall_1, gbc_lblIntervall_1);
tseI1 = new JTimeSpanEditor();
tseI1.setToolTipText("<html>\n<b>Intervall</b><br/>\n<br/>\nStellen Sie die gewünschten Intervalllängen ein.<br/>\n<br/>\nEinheiten: <b>Tage, Stunden, Minuten, Sekunden</b>\n</html>");
tseI1.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
ServiceLink sl = PulsCounterApplication.getApplication().getServiceLink();
try {
sl.writeInt(13, 0, 0x1011, (Integer)tseI1.getValue());
} catch (ServiceLinkRequestFailedException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
} catch (ServiceLinkException e1) {
e1.printStackTrace();
}
}
});
GridBagConstraints gbc_tseI1 = new GridBagConstraints();
gbc_tseI1.anchor = GridBagConstraints.WEST;
gbc_tseI1.insets = new Insets(0, 0, 5, 0);
gbc_tseI1.gridx = 1;
gbc_tseI1.gridy = 2;
panel_2.add(tseI1, gbc_tseI1);
JLabel lblIntervall_2 = new JLabel("Intervall 2:");
lblIntervall_2.setToolTipText("<html>\n<b>Intervall</b><br/>\n<br/>\nStellen Sie die gewünschten Intervalllängen ein.<br/>\n<br/>\nEinheiten: <b>Tage, Stunden, Minuten, Sekunden</b>\n</html>");
GridBagConstraints gbc_lblIntervall_2 = new GridBagConstraints();
gbc_lblIntervall_2.fill = GridBagConstraints.HORIZONTAL;
gbc_lblIntervall_2.insets = new Insets(0, 0, 5, 5);
gbc_lblIntervall_2.gridx = 0;
gbc_lblIntervall_2.gridy = 3;
panel_2.add(lblIntervall_2, gbc_lblIntervall_2);
tseI2 = new JTimeSpanEditor();
tseI2.setToolTipText("<html>\n<b>Intervall</b><br/>\n<br/>\nStellen Sie die gewünschten Intervalllängen ein.<br/>\n<br/>\nEinheiten: <b>Tage, Stunden, Minuten, Sekunden</b>\n</html>");
tseI2.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
ServiceLink sl = PulsCounterApplication.getApplication().getServiceLink();
try {
sl.writeInt(13, 0, 0x1012, (Integer)tseI2.getValue());
} catch (ServiceLinkRequestFailedException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
} catch (ServiceLinkException e1) {
e1.printStackTrace();
}
}
});
GridBagConstraints gbc_tseI2 = new GridBagConstraints();
gbc_tseI2.anchor = GridBagConstraints.WEST;
gbc_tseI2.insets = new Insets(0, 0, 5, 0);
gbc_tseI2.gridx = 1;
gbc_tseI2.gridy = 3;
panel_2.add(tseI2, gbc_tseI2);
JLabel lblIntervall_3 = new JLabel("Intervall 3:");
lblIntervall_3.setToolTipText("<html>\n<b>Intervall</b><br/>\n<br/>\nStellen Sie die gewünschten Intervalllängen ein.<br/>\n<br/>\nEinheiten: <b>Tage, Stunden, Minuten, Sekunden</b>\n</html>");
GridBagConstraints gbc_lblIntervall_3 = new GridBagConstraints();
gbc_lblIntervall_3.fill = GridBagConstraints.HORIZONTAL;
gbc_lblIntervall_3.insets = new Insets(0, 0, 0, 5);
gbc_lblIntervall_3.gridx = 0;
gbc_lblIntervall_3.gridy = 4;
panel_2.add(lblIntervall_3, gbc_lblIntervall_3);
tseI3 = new JTimeSpanEditor();
tseI3.setToolTipText("<html>\n<b>Intervall</b><br/>\n<br/>\nStellen Sie die gewünschten Intervalllängen ein.<br/>\n<br/>\nEinheiten: <b>Tage, Stunden, Minuten, Sekunden</b>\n</html>");
tseI3.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
ServiceLink sl = PulsCounterApplication.getApplication().getServiceLink();
try {
sl.writeInt(13, 0, 0x1013, (Integer)tseI3.getValue());
} catch (ServiceLinkRequestFailedException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
} catch (ServiceLinkException e1) {
e1.printStackTrace();
}
}
});
GridBagConstraints gbc_tseI3 = new GridBagConstraints();
gbc_tseI3.anchor = GridBagConstraints.WEST;
gbc_tseI3.gridx = 1;
gbc_tseI3.gridy = 4;
panel_2.add(tseI3, gbc_tseI3);
JPanel panel_1 = new JPanel();
tabbedPane.addTab("Kanäle", null, panel_1, null);
GridBagLayout gbl_panel_1 = new GridBagLayout();
gbl_panel_1.columnWidths = new int[] {100};
gbl_panel_1.rowHeights = new int[] {30};
gbl_panel_1.columnWeights = new double[]{1.0};
gbl_panel_1.rowWeights = new double[]{1.0};
panel_1.setLayout(gbl_panel_1);
JScrollPane scrollPane = new JScrollPane();
GridBagConstraints gbc_scrollPane = new GridBagConstraints();
gbc_scrollPane.fill = GridBagConstraints.BOTH;
gbc_scrollPane.gridx = 0;
gbc_scrollPane.gridy = 0;
panel_1.add(scrollPane, gbc_scrollPane);
tSettings = new JTable();
tSettings.setRowHeight(32);
tSettings.setFillsViewportHeight(true);
tSettings.setCellSelectionEnabled(true);
scrollPane.setViewportView(tSettings);
JButton btnSchliessen = new JButton("abbrechen");
btnSchliessen.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setVisible(false);
}
});
JButton btnOk = new JButton("OK");
btnOk.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
writeDevice();
setVisible(false);
}
});
GridBagConstraints gbc_btnOk = new GridBagConstraints();
gbc_btnOk.fill = GridBagConstraints.BOTH;
gbc_btnOk.insets = new Insets(0, 0, 0, 5);
gbc_btnOk.gridx = 1;
gbc_btnOk.gridy = 1;
contentPane.add(btnOk, gbc_btnOk);
GridBagConstraints gbc_btnSchliessen = new GridBagConstraints();
gbc_btnSchliessen.fill = GridBagConstraints.BOTH;
gbc_btnSchliessen.gridx = 2;
gbc_btnSchliessen.gridy = 1;
contentPane.add(btnSchliessen, gbc_btnSchliessen);
this.initialize();
}
private Integer intOr0(Integer i){
if (i==null)
return 0;
return i;
}
private void initialize(){
currentChannel = -1;
filter = new int[32];
windows = new int[32];
tmSettings = new TableMapper(ChannelConfiguration.class, tSettings);
BitField bf = new BitField();
bf.clear();
bf.addField(new Field(bf, 0, 1, "Intervall 0 basiert auf Tageszeit"));
bf.addField(new Field(bf, 1, 1, "Intervall 1 basiert auf Tageszeit"));
bf.addField(new Field(bf, 2, 1, "Intervall 2 basiert auf Tageszeit"));
bf.addField(new Field(bf, 3, 1, "Intervall 3 basiert auf Tageszeit"));
bfeIntervall.setBitField(bf);
for (int i=0;i<32;i++){
tmSettings.addRow(new ChannelConfiguration(i));
}
readDevice();
}
private void readDevice(){
Integer v;
ServiceLink sl = PulsCounterApplication.getApplication().getServiceLink();
outputs = intOr0(sl.getServiceRegisterCache().getCachedInteger(13, 0, 0x1008));
pullups = intOr0(sl.getServiceRegisterCache().getCachedInteger(13, 0, 0x1009));
inverts = intOr0(sl.getServiceRegisterCache().getCachedInteger(13, 0, 0x100A));
trigger = intOr0(sl.getServiceRegisterCache().getCachedInteger(13, 0, 0x100B));
bfeIntervall.setIntValue(sl.getServiceRegisterCache().getCachedInteger(13, 0, 0x1003));
for (int i=0;i<32;i++){
filter[i] = intOr0( sl.getServiceRegisterCache().getCachedInteger(13, 0, 0x1020 + i));
windows[i] = intOr0( sl.getServiceRegisterCache().getCachedInteger(13, 0, 0x1280 + i));
}
v = sl.getServiceRegisterCache().getCachedInteger(13, 0, 0x1010);
if (v!=null){
tseI0.setValue(v);
}
v = sl.getServiceRegisterCache().getCachedInteger(13, 0, 0x1011);
if (v!=null){
tseI1.setValue(v);
}
v = sl.getServiceRegisterCache().getCachedInteger(13, 0, 0x1012);
if (v!=null){
tseI2.setValue(v);
}
v = sl.getServiceRegisterCache().getCachedInteger(13, 0, 0x1013);
if (v!=null){
tseI3.setValue(v);
}
}
private void writeDevice(){
ServiceLink sl = PulsCounterApplication.getApplication().getServiceLink();
try {
sl.writeInt(13, 0, 0x1008, outputs);
sl.writeInt(13, 0, 0x1009, pullups);
sl.writeInt(13, 0, 0x100A, inverts);
sl.writeInt(13, 0, 0x100B, trigger);
sl.writeInt(13, 0, 0x1003, bfeIntervall.getIntValue());
for (int i=0;i<32;i++){
sl.writeInt(13, 0, 0x1020 + i, filter[i]);
sl.writeInt(13, 0, 0x1280 + i, windows[i]);
}
sl.writeInt(13, 0, 0x1010, tseI0.getValue());
sl.writeInt(13, 0, 0x1011, tseI1.getValue());
sl.writeInt(13, 0, 0x1012, tseI2.getValue());
sl.writeInt(13, 0, 0x1013, tseI3.getValue());
/* Konfiguration auf Live-System übertragen */
sl.writeInt(13, 0, 0x1001, 1);
} catch (Exception e){
e.printStackTrace();
}
}
class ChannelConfiguration{
int channel;
public ChannelConfiguration(int channel) {
this.channel = channel;
}
@TableColumn(label="Channel",width=80,order=0)
public int getChannel(){
return channel;
}
@TableColumn(label="Ausgang",width=80,order=10)
public Boolean getOutput(){
return (outputs & 1<<channel) == 0 ? false : true;
}
public void setOutput(Boolean value){
outputs &= ~(1<<channel);
if (value){
outputs |= (1<<channel);
}
}
@TableColumn(label="Passiver Schalter",width=80,order=20)
public Boolean getPullup(){
return (pullups & 1<<channel) == 0 ? false : true;
}
public void setPullup(Boolean value){
pullups &= ~(1<<channel);
if (value){
pullups |= (1<<channel);
}
}
@TableColumn(label="Invertiert",width=80,order=30)
public Boolean getInvert(){
return (inverts & 1<<channel) == 0 ? false : true;
}
public void setInvert(Boolean value){
inverts &= ~(1<<channel);
if (value){
inverts |= (1<<channel);
}
}
@TableColumn(label="Löst Snapshot aus",width=80,order=40)
public Boolean getTrigger(){
return (trigger & 1<<channel) == 0 ? false : true;
}
public void setTrigger(Boolean value){
trigger &= ~(1<<channel);
if (value){
trigger |= (1<<channel);
}
}
@TableColumn(label="Signalfenster",width=80,order=200)
public Integer getWindow(){
return windows[channel];
}
public void setWindow(Integer value){
windows[channel] = value;
}
@TableColumn(label="Signalfilter",width=80,order=210)
public Integer getFilter(){
return filter[channel];
}
public void setFilter(Integer value){
filter[channel] = value;
}
}
}
// private JPanel contentPane;
//
//
// int currentChannel;
// private BitFieldEditor bfeIntervall;
// private JTimeSpanEditor tseI3;
// private JTimeSpanEditor tseI2;
// private JTimeSpanEditor tseI1;
// private JTimeSpanEditor tseI0;
//
// private TableMapper tmSettings;
//
// int outputs,
// pullups,
// inverts,
// trigger;
//
// int[] filter,
// windows;
// private JTable tSettings;
//
//
//
// /**
// * Create the frame.
// */
// public DeviceConfiguration() {
// setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
// setBounds(100, 100, 860, 498);
// contentPane = new JPanel();
// contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
// setContentPane(contentPane);
// GridBagLayout gbl_contentPane = new GridBagLayout();
// gbl_contentPane.columnWidths = new int[] {30, 0, 0};
// gbl_contentPane.rowHeights = new int[] {183, 0};
// gbl_contentPane.columnWeights = new double[]{1.0, 0.0, 0.0};
// gbl_contentPane.rowWeights = new double[]{1.0, 0.0};
// contentPane.setLayout(gbl_contentPane);
//
// JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
// GridBagConstraints gbc_tabbedPane = new GridBagConstraints();
// gbc_tabbedPane.gridwidth = 3;
// gbc_tabbedPane.fill = GridBagConstraints.BOTH;
// gbc_tabbedPane.insets = new Insets(0, 0, 5, 0);
// gbc_tabbedPane.gridx = 0;
// gbc_tabbedPane.gridy = 0;
// contentPane.add(tabbedPane, gbc_tabbedPane);
//
// JPanel panel_2 = new JPanel();
// tabbedPane.addTab("Intervalle", null, panel_2, null);
// GridBagLayout gbl_panel_2 = new GridBagLayout();
// gbl_panel_2.columnWidths = new int[]{0, 0, 0};
// gbl_panel_2.rowHeights = new int[]{0, 0, 0, 0, 0, 0};
// gbl_panel_2.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
// gbl_panel_2.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
// panel_2.setLayout(gbl_panel_2);
//
// bfeIntervall = new BitFieldEditor();
// bfeIntervall.setToolTipText("<html>\n<b>Tagesbasierte Intervalle</b><br/>\n<br/>\nTagesbasierte Intervalle werden immer auf 0:00:00 Uhr des aktuellen Tages bezogen ausgeführt.<br/>\nDies ermöglicht nicht nur eine Regelmäßige Aufzeichnung, sondern erzwingt auch eine Aufzeichnung<br/>\nin einem festgelegten immer gleichen Raster.<br/>\n<br/>\nNicht tageszeitbasierte Intervalle werden mit Bezug auf den 1.1.1970 0:00:00 Uhr ausgeführt.<br/>\nDiese ermöglichen eine stete regelmäßige Aufzeichnung bei der die tageszeit ignoriert wird.\n</html>");
// bfeIntervall.addChangeListener(new ChangeListener() {
// public void stateChanged(ChangeEvent e) {
// int v = bfeIntervall.getIntValue();
// tseI0.setDaysEnabled(((v & 0x01)==0));
// tseI1.setDaysEnabled(((v & 0x02)==0));
// tseI2.setDaysEnabled(((v & 0x04)==0));
// tseI3.setDaysEnabled(((v & 0x08)==0));
//
// ServiceLink sl = PulsCounterApplication.getApplication().getServiceLink();
// try {
//
// sl.writeInt(13, 0, 0x1003, bfeIntervall.getIntValue());
//
// } catch (ServiceLinkRequestFailedException e1) {
// e1.printStackTrace();
// } catch (IOException e1) {
// e1.printStackTrace();
// } catch (ServiceLinkException e1) {
// e1.printStackTrace();
// }
// }
// });
//
// JLabel lblTageszeitabhngigkeit = new JLabel("Tageszeitabhängigkeit:");
// GridBagConstraints gbc_lblTageszeitabhngigkeit = new GridBagConstraints();
// gbc_lblTageszeitabhngigkeit.fill = GridBagConstraints.HORIZONTAL;
// gbc_lblTageszeitabhngigkeit.insets = new Insets(0, 0, 5, 5);
// gbc_lblTageszeitabhngigkeit.gridx = 0;
// gbc_lblTageszeitabhngigkeit.gridy = 0;
// panel_2.add(lblTageszeitabhngigkeit, gbc_lblTageszeitabhngigkeit);
// GridBagConstraints gbc_bfeIntervall = new GridBagConstraints();
// gbc_bfeIntervall.anchor = GridBagConstraints.NORTH;
// gbc_bfeIntervall.insets = new Insets(0, 0, 5, 0);
// gbc_bfeIntervall.fill = GridBagConstraints.HORIZONTAL;
// gbc_bfeIntervall.gridx = 1;
// gbc_bfeIntervall.gridy = 0;
// panel_2.add(bfeIntervall, gbc_bfeIntervall);
//
// JLabel lblIntervall = new JLabel("Intervall 0:");
// lblIntervall.setToolTipText("<html>\n<b>Intervall</b><br/>\n<br/>\nStellen Sie die gewünschten Intervalllängen ein.<br/>\n<br/>\nEinheiten: <b>Tage, Stunden, Minuten, Sekunden</b>\n</html>");
// GridBagConstraints gbc_lblIntervall = new GridBagConstraints();
// gbc_lblIntervall.fill = GridBagConstraints.HORIZONTAL;
// gbc_lblIntervall.insets = new Insets(0, 0, 5, 5);
// gbc_lblIntervall.gridx = 0;
// gbc_lblIntervall.gridy = 1;
// panel_2.add(lblIntervall, gbc_lblIntervall);
//
// tseI0 = new JTimeSpanEditor();
// tseI0.setToolTipText("<html>\n<b>Intervall</b><br/>\n<br/>\nStellen Sie die gewünschten Intervalllängen ein.<br/>\n<br/>\nEinheiten: <b>Tage, Stunden, Minuten, Sekunden</b>\n</html>");
// tseI0.addFocusListener(new FocusAdapter() {
// @Override
// public void focusLost(FocusEvent e) {
// System.err.println("FOCUS LOST 0");
// ServiceLink sl = PulsCounterApplication.getApplication().getServiceLink();
// try {
//
// sl.writeInt(13, 0, 0x1010, (Integer)tseI0.getValue());
//
// } catch (ServiceLinkRequestFailedException e1) {
// e1.printStackTrace();
// } catch (IOException e1) {
// e1.printStackTrace();
// } catch (ServiceLinkException e1) {
// e1.printStackTrace();
// }
// }
// });
// GridBagConstraints gbc_tseI0 = new GridBagConstraints();
// gbc_tseI0.anchor = GridBagConstraints.WEST;
// gbc_tseI0.insets = new Insets(0, 0, 5, 0);
// gbc_tseI0.gridx = 1;
// gbc_tseI0.gridy = 1;
// panel_2.add(tseI0, gbc_tseI0);
//
// JLabel lblIntervall_1 = new JLabel("Intervall 1:");
// lblIntervall_1.setToolTipText("<html>\n<b>Intervall</b><br/>\n<br/>\nStellen Sie die gewünschten Intervalllängen ein.<br/>\n<br/>\nEinheiten: <b>Tage, Stunden, Minuten, Sekunden</b>\n</html>");
// GridBagConstraints gbc_lblIntervall_1 = new GridBagConstraints();
// gbc_lblIntervall_1.fill = GridBagConstraints.HORIZONTAL;
// gbc_lblIntervall_1.insets = new Insets(0, 0, 5, 5);
// gbc_lblIntervall_1.gridx = 0;
// gbc_lblIntervall_1.gridy = 2;
// panel_2.add(lblIntervall_1, gbc_lblIntervall_1);
//
// tseI1 = new JTimeSpanEditor();
// tseI1.setToolTipText("<html>\n<b>Intervall</b><br/>\n<br/>\nStellen Sie die gewünschten Intervalllängen ein.<br/>\n<br/>\nEinheiten: <b>Tage, Stunden, Minuten, Sekunden</b>\n</html>");
// tseI1.addFocusListener(new FocusAdapter() {
// @Override
// public void focusLost(FocusEvent e) {
//
// ServiceLink sl = PulsCounterApplication.getApplication().getServiceLink();
// try {
//
// sl.writeInt(13, 0, 0x1011, (Integer)tseI1.getValue());
//
// } catch (ServiceLinkRequestFailedException e1) {
// e1.printStackTrace();
// } catch (IOException e1) {
// e1.printStackTrace();
// } catch (ServiceLinkException e1) {
// e1.printStackTrace();
// }
// }
// });
// GridBagConstraints gbc_tseI1 = new GridBagConstraints();
// gbc_tseI1.anchor = GridBagConstraints.WEST;
// gbc_tseI1.insets = new Insets(0, 0, 5, 0);
// gbc_tseI1.gridx = 1;
// gbc_tseI1.gridy = 2;
// panel_2.add(tseI1, gbc_tseI1);
//
// JLabel lblIntervall_2 = new JLabel("Intervall 2:");
// lblIntervall_2.setToolTipText("<html>\n<b>Intervall</b><br/>\n<br/>\nStellen Sie die gewünschten Intervalllängen ein.<br/>\n<br/>\nEinheiten: <b>Tage, Stunden, Minuten, Sekunden</b>\n</html>");
// GridBagConstraints gbc_lblIntervall_2 = new GridBagConstraints();
// gbc_lblIntervall_2.fill = GridBagConstraints.HORIZONTAL;
// gbc_lblIntervall_2.insets = new Insets(0, 0, 5, 5);
// gbc_lblIntervall_2.gridx = 0;
// gbc_lblIntervall_2.gridy = 3;
// panel_2.add(lblIntervall_2, gbc_lblIntervall_2);
//
// tseI2 = new JTimeSpanEditor();
// tseI2.setToolTipText("<html>\n<b>Intervall</b><br/>\n<br/>\nStellen Sie die gewünschten Intervalllängen ein.<br/>\n<br/>\nEinheiten: <b>Tage, Stunden, Minuten, Sekunden</b>\n</html>");
// tseI2.addFocusListener(new FocusAdapter() {
// @Override
// public void focusLost(FocusEvent e) {
// ServiceLink sl = PulsCounterApplication.getApplication().getServiceLink();
// try {
//
// sl.writeInt(13, 0, 0x1012, (Integer)tseI2.getValue());
//
// } catch (ServiceLinkRequestFailedException e1) {
// e1.printStackTrace();
// } catch (IOException e1) {
// e1.printStackTrace();
// } catch (ServiceLinkException e1) {
// e1.printStackTrace();
// }
// }
// });
// GridBagConstraints gbc_tseI2 = new GridBagConstraints();
// gbc_tseI2.anchor = GridBagConstraints.WEST;
// gbc_tseI2.insets = new Insets(0, 0, 5, 0);
// gbc_tseI2.gridx = 1;
// gbc_tseI2.gridy = 3;
// panel_2.add(tseI2, gbc_tseI2);
//
// JLabel lblIntervall_3 = new JLabel("Intervall 3:");
// lblIntervall_3.setToolTipText("<html>\n<b>Intervall</b><br/>\n<br/>\nStellen Sie die gewünschten Intervalllängen ein.<br/>\n<br/>\nEinheiten: <b>Tage, Stunden, Minuten, Sekunden</b>\n</html>");
// GridBagConstraints gbc_lblIntervall_3 = new GridBagConstraints();
// gbc_lblIntervall_3.fill = GridBagConstraints.HORIZONTAL;
// gbc_lblIntervall_3.insets = new Insets(0, 0, 0, 5);
// gbc_lblIntervall_3.gridx = 0;
// gbc_lblIntervall_3.gridy = 4;
// panel_2.add(lblIntervall_3, gbc_lblIntervall_3);
//
// tseI3 = new JTimeSpanEditor();
// tseI3.setToolTipText("<html>\n<b>Intervall</b><br/>\n<br/>\nStellen Sie die gewünschten Intervalllängen ein.<br/>\n<br/>\nEinheiten: <b>Tage, Stunden, Minuten, Sekunden</b>\n</html>");
// tseI3.addFocusListener(new FocusAdapter() {
// @Override
// public void focusLost(FocusEvent e) {
// ServiceLink sl = PulsCounterApplication.getApplication().getServiceLink();
// try {
//
// sl.writeInt(13, 0, 0x1013, (Integer)tseI3.getValue());
//
// } catch (ServiceLinkRequestFailedException e1) {
// e1.printStackTrace();
// } catch (IOException e1) {
// e1.printStackTrace();
// } catch (ServiceLinkException e1) {
// e1.printStackTrace();
// }
// }
// });
// GridBagConstraints gbc_tseI3 = new GridBagConstraints();
// gbc_tseI3.anchor = GridBagConstraints.WEST;
// gbc_tseI3.gridx = 1;
// gbc_tseI3.gridy = 4;
// panel_2.add(tseI3, gbc_tseI3);
//
// JPanel panel_1 = new JPanel();
// tabbedPane.addTab("Kanäle", null, panel_1, null);
// GridBagLayout gbl_panel_1 = new GridBagLayout();
// gbl_panel_1.columnWidths = new int[] {100};
// gbl_panel_1.rowHeights = new int[] {30};
// gbl_panel_1.columnWeights = new double[]{1.0};
// gbl_panel_1.rowWeights = new double[]{1.0};
// panel_1.setLayout(gbl_panel_1);
//
// JScrollPane scrollPane = new JScrollPane();
// GridBagConstraints gbc_scrollPane = new GridBagConstraints();
// gbc_scrollPane.fill = GridBagConstraints.BOTH;
// gbc_scrollPane.gridx = 0;
// gbc_scrollPane.gridy = 0;
// panel_1.add(scrollPane, gbc_scrollPane);
//
// tSettings = new JTable();
// tSettings.setRowHeight(32);
// tSettings.setFillsViewportHeight(true);
// tSettings.setCellSelectionEnabled(true);
// scrollPane.setViewportView(tSettings);
//
// JButton btnSchliessen = new JButton("abbrechen");
// btnSchliessen.addActionListener(new ActionListener() {
// public void actionPerformed(ActionEvent e) {
// setVisible(false);
// }
// });
//
// JButton btnOk = new JButton("OK");
// btnOk.addActionListener(new ActionListener() {
// public void actionPerformed(ActionEvent e) {
// writeDevice();
// setVisible(false);
// }
// });
// GridBagConstraints gbc_btnOk = new GridBagConstraints();
// gbc_btnOk.fill = GridBagConstraints.BOTH;
// gbc_btnOk.insets = new Insets(0, 0, 0, 5);
// gbc_btnOk.gridx = 1;
// gbc_btnOk.gridy = 1;
// contentPane.add(btnOk, gbc_btnOk);
// GridBagConstraints gbc_btnSchliessen = new GridBagConstraints();
// gbc_btnSchliessen.fill = GridBagConstraints.BOTH;
// gbc_btnSchliessen.gridx = 2;
// gbc_btnSchliessen.gridy = 1;
// contentPane.add(btnSchliessen, gbc_btnSchliessen);
//
// this.initialize();
// }
//
// private Integer intOr0(Integer i){
// if (i==null)
// return 0;
// return i;
// }
//
// private void initialize(){
// currentChannel = -1;
// filter = new int[32];
// windows = new int[32];
// tmSettings = new TableMapper(ChannelConfiguration.class, tSettings);
//
// BitField bf = new BitField();
// bf.clear();
// bf.addField(new Field(bf, 0, 1, "Intervall 0 basiert auf Tageszeit"));
// bf.addField(new Field(bf, 1, 1, "Intervall 1 basiert auf Tageszeit"));
// bf.addField(new Field(bf, 2, 1, "Intervall 2 basiert auf Tageszeit"));
// bf.addField(new Field(bf, 3, 1, "Intervall 3 basiert auf Tageszeit"));
// bfeIntervall.setBitField(bf);
// for (int i=0;i<32;i++){
// tmSettings.addRow(new ChannelConfiguration(i));
// }
//
//
// readDevice();
// }
//
// private void readDevice(){
// Integer v;
//
// ServiceLink sl = PulsCounterApplication.getApplication().getServiceLink();
//
// outputs = intOr0(sl.getServiceRegisterCache().getCachedInteger(13, 0, 0x1008));
// pullups = intOr0(sl.getServiceRegisterCache().getCachedInteger(13, 0, 0x1009));
// inverts = intOr0(sl.getServiceRegisterCache().getCachedInteger(13, 0, 0x100A));
// trigger = intOr0(sl.getServiceRegisterCache().getCachedInteger(13, 0, 0x100B));
//
// bfeIntervall.setIntValue(sl.getServiceRegisterCache().getCachedInteger(13, 0, 0x1003));
//
// for (int i=0;i<32;i++){
// filter[i] = intOr0( sl.getServiceRegisterCache().getCachedInteger(13, 0, 0x1020 + i));
// windows[i] = intOr0( sl.getServiceRegisterCache().getCachedInteger(13, 0, 0x1280 + i));
// }
//
//
// v = sl.getServiceRegisterCache().getCachedInteger(13, 0, 0x1010);
// if (v!=null){
// tseI0.setValue(v);
// }
// v = sl.getServiceRegisterCache().getCachedInteger(13, 0, 0x1011);
// if (v!=null){
// tseI1.setValue(v);
// }
// v = sl.getServiceRegisterCache().getCachedInteger(13, 0, 0x1012);
// if (v!=null){
// tseI2.setValue(v);
// }
// v = sl.getServiceRegisterCache().getCachedInteger(13, 0, 0x1013);
// if (v!=null){
// tseI3.setValue(v);
// }
//
//
//
//
// }
//
// private void writeDevice(){
// ServiceLink sl = PulsCounterApplication.getApplication().getServiceLink();
// try {
// sl.writeInt(13, 0, 0x1008, outputs);
// sl.writeInt(13, 0, 0x1009, pullups);
// sl.writeInt(13, 0, 0x100A, inverts);
// sl.writeInt(13, 0, 0x100B, trigger);
//
// sl.writeInt(13, 0, 0x1003, bfeIntervall.getIntValue());
//
// for (int i=0;i<32;i++){
// sl.writeInt(13, 0, 0x1020 + i, filter[i]);
// sl.writeInt(13, 0, 0x1280 + i, windows[i]);
// }
//
//
// sl.writeInt(13, 0, 0x1010, tseI0.getValue());
// sl.writeInt(13, 0, 0x1011, tseI1.getValue());
// sl.writeInt(13, 0, 0x1012, tseI2.getValue());
// sl.writeInt(13, 0, 0x1013, tseI3.getValue());
//
// /* Konfiguration auf Live-System übertragen */
// sl.writeInt(13, 0, 0x1001, 1);
// } catch (Exception e){
// e.printStackTrace();
// }
// }
//
// class ChannelConfiguration{
//
// int channel;
//
// public ChannelConfiguration(int channel) {
// this.channel = channel;
// }
//
// @TableColumn(label="Channel",width=80,order=0)
// public int getChannel(){
// return channel;
// }
//
// @TableColumn(label="Ausgang",width=80,order=10)
// public Boolean getOutput(){
// return (outputs & 1<<channel) == 0 ? false : true;
// }
// public void setOutput(Boolean value){
// outputs &= ~(1<<channel);
// if (value){
// outputs |= (1<<channel);
// }
// }
//
// @TableColumn(label="Passiver Schalter",width=80,order=20)
// public Boolean getPullup(){
// return (pullups & 1<<channel) == 0 ? false : true;
// }
// public void setPullup(Boolean value){
// pullups &= ~(1<<channel);
// if (value){
// pullups |= (1<<channel);
// }
// }
//
// @TableColumn(label="Invertiert",width=80,order=30)
// public Boolean getInvert(){
// return (inverts & 1<<channel) == 0 ? false : true;
// }
// public void setInvert(Boolean value){
// inverts &= ~(1<<channel);
// if (value){
// inverts |= (1<<channel);
// }
// }
//
// @TableColumn(label="Löst Snapshot aus",width=80,order=40)
// public Boolean getTrigger(){
// return (trigger & 1<<channel) == 0 ? false : true;
// }
// public void setTrigger(Boolean value){
// trigger &= ~(1<<channel);
// if (value){
// trigger |= (1<<channel);
// }
// }
//
// @TableColumn(label="Signalfenster",width=80,order=200)
// public Integer getWindow(){
// return windows[channel];
// }
// public void setWindow(Integer value){
// windows[channel] = value;
// }
//
// @TableColumn(label="Signalfilter",width=80,order=210)
// public Integer getFilter(){
// return filter[channel];
// }
// public void setFilter(Integer value){
// filter[channel] = value;
// }
//
// }
//
//
//
//}

View File

@ -10,7 +10,6 @@ import javax.swing.border.EmptyBorder;
import org.hwo.datetime.DateTime;
import org.hwo.pulscounter.PulsCounterApplication;
import org.hwo.pulscounter.PulsCounterApplicationListener;
import org.hwo.pulscounter.SnapshotManager.Notification;
import org.hwo.servicelink.ServiceLinkException;
import java.awt.GridBagLayout;
@ -27,352 +26,352 @@ import javax.swing.JButton;
import javax.swing.JList;
import javax.swing.JScrollPane;
public class DeviceTestFrame extends JFrame implements PulsCounterApplicationListener {
public class DeviceTestFrame extends JFrame { //implements PulsCounterApplicationListener {
private JPanel contentPane;
private JTextField tfCommunication;
private JTextField tfEEPROM;
private JTextField tfIO;
private JTextField tfAD;
private JTextField tfSerial;
private Timer reconnectTimer;
private DeviceChecker deviceChecker;
private JList lMessages;
private DefaultListModel<String> messageListModel;
private PulsCounterApplication pulsCounterApplication;
/**
* Create the frame.
*/
public DeviceTestFrame(PulsCounterApplication pulsCounterApplication) {
this.pulsCounterApplication = pulsCounterApplication;
setTitle("Device Test Frame");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 701, 464);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
GridBagLayout gbl_contentPane = new GridBagLayout();
gbl_contentPane.columnWidths = new int[]{0, 0, 0};
gbl_contentPane.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0};
gbl_contentPane.columnWeights = new double[]{1.0, 1.0, Double.MIN_VALUE};
gbl_contentPane.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE};
contentPane.setLayout(gbl_contentPane);
JLabel lblKommunikation = new JLabel("Communication:");
GridBagConstraints gbc_lblKommunikation = new GridBagConstraints();
gbc_lblKommunikation.anchor = GridBagConstraints.EAST;
gbc_lblKommunikation.insets = new Insets(0, 0, 5, 5);
gbc_lblKommunikation.gridx = 0;
gbc_lblKommunikation.gridy = 0;
contentPane.add(lblKommunikation, gbc_lblKommunikation);
tfCommunication = new JTextField();
GridBagConstraints gbc_tfCommunication = new GridBagConstraints();
gbc_tfCommunication.insets = new Insets(0, 0, 5, 0);
gbc_tfCommunication.fill = GridBagConstraints.HORIZONTAL;
gbc_tfCommunication.gridx = 1;
gbc_tfCommunication.gridy = 0;
contentPane.add(tfCommunication, gbc_tfCommunication);
tfCommunication.setColumns(10);
JLabel lblLeds = new JLabel("LEDs:");
GridBagConstraints gbc_lblLeds = new GridBagConstraints();
gbc_lblLeds.insets = new Insets(0, 0, 5, 5);
gbc_lblLeds.gridx = 0;
gbc_lblLeds.gridy = 1;
contentPane.add(lblLeds, gbc_lblLeds);
JLabel lblEeprom = new JLabel("EEPROM:");
GridBagConstraints gbc_lblEeprom = new GridBagConstraints();
gbc_lblEeprom.anchor = GridBagConstraints.EAST;
gbc_lblEeprom.insets = new Insets(0, 0, 5, 5);
gbc_lblEeprom.gridx = 0;
gbc_lblEeprom.gridy = 2;
contentPane.add(lblEeprom, gbc_lblEeprom);
tfEEPROM = new JTextField();
GridBagConstraints gbc_tfEEPROM = new GridBagConstraints();
gbc_tfEEPROM.insets = new Insets(0, 0, 5, 0);
gbc_tfEEPROM.fill = GridBagConstraints.HORIZONTAL;
gbc_tfEEPROM.gridx = 1;
gbc_tfEEPROM.gridy = 2;
contentPane.add(tfEEPROM, gbc_tfEEPROM);
tfEEPROM.setColumns(10);
JLabel lblIoCircuit = new JLabel("I/O Circuit:");
GridBagConstraints gbc_lblIoCircuit = new GridBagConstraints();
gbc_lblIoCircuit.anchor = GridBagConstraints.EAST;
gbc_lblIoCircuit.insets = new Insets(0, 0, 5, 5);
gbc_lblIoCircuit.gridx = 0;
gbc_lblIoCircuit.gridy = 3;
contentPane.add(lblIoCircuit, gbc_lblIoCircuit);
tfIO = new JTextField();
GridBagConstraints gbc_tfIO = new GridBagConstraints();
gbc_tfIO.insets = new Insets(0, 0, 5, 0);
gbc_tfIO.fill = GridBagConstraints.HORIZONTAL;
gbc_tfIO.gridx = 1;
gbc_tfIO.gridy = 3;
contentPane.add(tfIO, gbc_tfIO);
tfIO.setColumns(10);
JLabel lblAdConverters = new JLabel("A/D Converters:");
GridBagConstraints gbc_lblAdConverters = new GridBagConstraints();
gbc_lblAdConverters.anchor = GridBagConstraints.EAST;
gbc_lblAdConverters.insets = new Insets(0, 0, 5, 5);
gbc_lblAdConverters.gridx = 0;
gbc_lblAdConverters.gridy = 4;
contentPane.add(lblAdConverters, gbc_lblAdConverters);
tfAD = new JTextField();
GridBagConstraints gbc_tfAD = new GridBagConstraints();
gbc_tfAD.insets = new Insets(0, 0, 5, 0);
gbc_tfAD.fill = GridBagConstraints.HORIZONTAL;
gbc_tfAD.gridx = 1;
gbc_tfAD.gridy = 4;
contentPane.add(tfAD, gbc_tfAD);
tfAD.setColumns(10);
JLabel lblSerial = new JLabel("Serial:");
GridBagConstraints gbc_lblSerial = new GridBagConstraints();
gbc_lblSerial.anchor = GridBagConstraints.EAST;
gbc_lblSerial.insets = new Insets(0, 0, 5, 5);
gbc_lblSerial.gridx = 0;
gbc_lblSerial.gridy = 5;
contentPane.add(lblSerial, gbc_lblSerial);
tfSerial = new JTextField();
GridBagConstraints gbc_tfSerial = new GridBagConstraints();
gbc_tfSerial.insets = new Insets(0, 0, 5, 0);
gbc_tfSerial.fill = GridBagConstraints.HORIZONTAL;
gbc_tfSerial.gridx = 1;
gbc_tfSerial.gridy = 5;
contentPane.add(tfSerial, gbc_tfSerial);
tfSerial.setColumns(10);
JButton btnSetDevice = new JButton("Confirm Device");
GridBagConstraints gbc_btnSetDevice = new GridBagConstraints();
gbc_btnSetDevice.insets = new Insets(0, 0, 5, 0);
gbc_btnSetDevice.gridx = 1;
gbc_btnSetDevice.gridy = 6;
contentPane.add(btnSetDevice, gbc_btnSetDevice);
JScrollPane scrollPane = new JScrollPane();
GridBagConstraints gbc_scrollPane = new GridBagConstraints();
gbc_scrollPane.fill = GridBagConstraints.BOTH;
gbc_scrollPane.gridwidth = 2;
gbc_scrollPane.insets = new Insets(0, 0, 0, 5);
gbc_scrollPane.gridx = 0;
gbc_scrollPane.gridy = 7;
contentPane.add(scrollPane, gbc_scrollPane);
lMessages = new JList();
scrollPane.setViewportView(lMessages);
this.initialize();
}
private PulsCounterApplication application(){
return this.pulsCounterApplication;
}
private void initialize(){
this.reconnectTimer = new Timer("Reconnection Timer");
messageListModel = new DefaultListModel<String>();
lMessages.setModel(messageListModel);
application().addPulsCounterApplicationListener(this);
setVisible(true);
}
/*
@Override
public void connectionStateChanged(Boolean connected) {
if (!connected){
tfCommunication.setText("NO CONNECTION");
if (this.deviceChecker != null){
this.deviceChecker.cancel();
}
reconnectTimer.schedule(new TimerTask() {
@Override
public void run() {
if (!application().getServiceLink().isOpen()){
try {
application().getServiceLink().open();
} catch (ServiceLinkException e) {
e.printStackTrace();
}
}
}
}, 3000);
} else {
if (this.deviceChecker != null){
while (this.deviceChecker.isAlive()){
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
this.deviceChecker = new DeviceChecker();
this.deviceChecker.start();
}
}
*/
@Override
public synchronized void messageArrived(String message) {
if (EventQueue.isDispatchThread()){
int pos = messageListModel.size();
String t = String.format("%s: %s",DateTime.NOW().getSQLDateTime(),message);
messageListModel.addElement(t);
lMessages.ensureIndexIsVisible(messageListModel.size()-1);
} else {
final String msg = message;
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
messageArrived(msg);
}
});
}
}
class DeviceChecker extends Thread {
private boolean cancel;
public DeviceChecker(){
cancel = false;
}
public void cancel(){
this.cancel = true;
}
@Override
public void run() {
checkCommunication();
checkEEPROM();
checkIO();
checkADC();
while (!cancel){
checkCommunication();
}
}
private void checkCommunication(){
if (!this.cancel){
Integer version = application().getServiceLink().getServiceRegisterCache().getCachedInteger(13, 0, 0x001A);
Integer uptime = application().getServiceLink().getServiceRegisterCache().getCachedInteger(13, 0, 0x0022);
if ((version != null)&&(uptime != null)){
tfCommunication.setText(String.format("OK (V: %d.%d.%d) Up: %d:%d:%d",version >> 16, (version >> 8) & 0xff, version & 0xff, uptime / 3600, (uptime / 60)%60, uptime % 60));
}
}
}
private void checkEEPROM(){
if (!this.cancel){
Integer eesize = application().getServiceLink().getServiceRegisterCache().getCachedInteger(13, 0, 0x9000);
if (eesize != null){
tfEEPROM.setText(String.format("EEPROM Size Detected: 0x%08x Bytes (%d kBytes)", eesize, (eesize >> 10)));
} else {
tfEEPROM.setText("EEPROM failed.");
}
}
}
private void checkIO(){
if (!this.cancel){
application().message("I/O test begins...");
application().message("I/O reset...");
try {
application().getServiceLink().writeInt(13, 0, 0x0682, 0);
application().getServiceLink().writeInt(13, 0, 0x0683, 0);
application().getServiceLink().writeInt(13, 0, 0x0684, 0);
application().getServiceLink().writeInt(13, 0, 0x0685, 0);
application().message("counter reset.");
for (int i=0;i<32;i++){
application().getServiceLink().writeInt(13, 0, 0x0600 + i, 0);
}
application().message("PullUP-Counter test.");
for (int i=0;i<12;i++){
Thread.sleep(250);
application().getServiceLink().writeInt(13, 0, 0x0683, -1);
Thread.sleep(250);
application().getServiceLink().writeInt(13, 0, 0x0683, 0);
}
for (int i=0;i<32;i++){
Thread.sleep(100);
Integer c = application().getServiceLink().readInt(13, 0, 0x0600 + i);
if ((c != null) && (c.equals(12))){
application().message(String.format("OK: Channel %d counted %d events.", i, c));
} else {
application().message(String.format("FAILED: Channel %d counted %d events.", i, c));
}
}
application().message("I/O test finished!");
} catch (IOException | ServiceLinkException e) {
e.printStackTrace();
application().message("I/O test FAILED!");
} catch (InterruptedException iex){
iex.printStackTrace();
application().message("I/O test FAILED!");
}
}
}
private void checkADC(){
if (!this.cancel){
}
}
}
@Override
public void interfaceClassesChanged(PulsCounterApplication pulsCounterApplication) {
// TODO Auto-generated method stub
}
@Override
public void interfacesChanged(PulsCounterApplication pulsCounterApplication) {
// TODO Auto-generated method stub
}
// private JPanel contentPane;
// private JTextField tfCommunication;
// private JTextField tfEEPROM;
// private JTextField tfIO;
// private JTextField tfAD;
// private JTextField tfSerial;
//
// private Timer reconnectTimer;
//
// private DeviceChecker deviceChecker;
// private JList lMessages;
// private DefaultListModel<String> messageListModel;
//
// private PulsCounterApplication pulsCounterApplication;
//
// /**
// * Create the frame.
// */
// public DeviceTestFrame(PulsCounterApplication pulsCounterApplication) {
// this.pulsCounterApplication = pulsCounterApplication;
//
// setTitle("Device Test Frame");
// setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// setBounds(100, 100, 701, 464);
// contentPane = new JPanel();
// contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
// setContentPane(contentPane);
// GridBagLayout gbl_contentPane = new GridBagLayout();
// gbl_contentPane.columnWidths = new int[]{0, 0, 0};
// gbl_contentPane.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0};
// gbl_contentPane.columnWeights = new double[]{1.0, 1.0, Double.MIN_VALUE};
// gbl_contentPane.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE};
// contentPane.setLayout(gbl_contentPane);
//
// JLabel lblKommunikation = new JLabel("Communication:");
// GridBagConstraints gbc_lblKommunikation = new GridBagConstraints();
// gbc_lblKommunikation.anchor = GridBagConstraints.EAST;
// gbc_lblKommunikation.insets = new Insets(0, 0, 5, 5);
// gbc_lblKommunikation.gridx = 0;
// gbc_lblKommunikation.gridy = 0;
// contentPane.add(lblKommunikation, gbc_lblKommunikation);
//
// tfCommunication = new JTextField();
// GridBagConstraints gbc_tfCommunication = new GridBagConstraints();
// gbc_tfCommunication.insets = new Insets(0, 0, 5, 0);
// gbc_tfCommunication.fill = GridBagConstraints.HORIZONTAL;
// gbc_tfCommunication.gridx = 1;
// gbc_tfCommunication.gridy = 0;
// contentPane.add(tfCommunication, gbc_tfCommunication);
// tfCommunication.setColumns(10);
//
// JLabel lblLeds = new JLabel("LEDs:");
// GridBagConstraints gbc_lblLeds = new GridBagConstraints();
// gbc_lblLeds.insets = new Insets(0, 0, 5, 5);
// gbc_lblLeds.gridx = 0;
// gbc_lblLeds.gridy = 1;
// contentPane.add(lblLeds, gbc_lblLeds);
//
// JLabel lblEeprom = new JLabel("EEPROM:");
// GridBagConstraints gbc_lblEeprom = new GridBagConstraints();
// gbc_lblEeprom.anchor = GridBagConstraints.EAST;
// gbc_lblEeprom.insets = new Insets(0, 0, 5, 5);
// gbc_lblEeprom.gridx = 0;
// gbc_lblEeprom.gridy = 2;
// contentPane.add(lblEeprom, gbc_lblEeprom);
//
// tfEEPROM = new JTextField();
// GridBagConstraints gbc_tfEEPROM = new GridBagConstraints();
// gbc_tfEEPROM.insets = new Insets(0, 0, 5, 0);
// gbc_tfEEPROM.fill = GridBagConstraints.HORIZONTAL;
// gbc_tfEEPROM.gridx = 1;
// gbc_tfEEPROM.gridy = 2;
// contentPane.add(tfEEPROM, gbc_tfEEPROM);
// tfEEPROM.setColumns(10);
//
// JLabel lblIoCircuit = new JLabel("I/O Circuit:");
// GridBagConstraints gbc_lblIoCircuit = new GridBagConstraints();
// gbc_lblIoCircuit.anchor = GridBagConstraints.EAST;
// gbc_lblIoCircuit.insets = new Insets(0, 0, 5, 5);
// gbc_lblIoCircuit.gridx = 0;
// gbc_lblIoCircuit.gridy = 3;
// contentPane.add(lblIoCircuit, gbc_lblIoCircuit);
//
// tfIO = new JTextField();
// GridBagConstraints gbc_tfIO = new GridBagConstraints();
// gbc_tfIO.insets = new Insets(0, 0, 5, 0);
// gbc_tfIO.fill = GridBagConstraints.HORIZONTAL;
// gbc_tfIO.gridx = 1;
// gbc_tfIO.gridy = 3;
// contentPane.add(tfIO, gbc_tfIO);
// tfIO.setColumns(10);
//
// JLabel lblAdConverters = new JLabel("A/D Converters:");
// GridBagConstraints gbc_lblAdConverters = new GridBagConstraints();
// gbc_lblAdConverters.anchor = GridBagConstraints.EAST;
// gbc_lblAdConverters.insets = new Insets(0, 0, 5, 5);
// gbc_lblAdConverters.gridx = 0;
// gbc_lblAdConverters.gridy = 4;
// contentPane.add(lblAdConverters, gbc_lblAdConverters);
//
// tfAD = new JTextField();
// GridBagConstraints gbc_tfAD = new GridBagConstraints();
// gbc_tfAD.insets = new Insets(0, 0, 5, 0);
// gbc_tfAD.fill = GridBagConstraints.HORIZONTAL;
// gbc_tfAD.gridx = 1;
// gbc_tfAD.gridy = 4;
// contentPane.add(tfAD, gbc_tfAD);
// tfAD.setColumns(10);
//
// JLabel lblSerial = new JLabel("Serial:");
// GridBagConstraints gbc_lblSerial = new GridBagConstraints();
// gbc_lblSerial.anchor = GridBagConstraints.EAST;
// gbc_lblSerial.insets = new Insets(0, 0, 5, 5);
// gbc_lblSerial.gridx = 0;
// gbc_lblSerial.gridy = 5;
// contentPane.add(lblSerial, gbc_lblSerial);
//
// tfSerial = new JTextField();
// GridBagConstraints gbc_tfSerial = new GridBagConstraints();
// gbc_tfSerial.insets = new Insets(0, 0, 5, 0);
// gbc_tfSerial.fill = GridBagConstraints.HORIZONTAL;
// gbc_tfSerial.gridx = 1;
// gbc_tfSerial.gridy = 5;
// contentPane.add(tfSerial, gbc_tfSerial);
// tfSerial.setColumns(10);
//
// JButton btnSetDevice = new JButton("Confirm Device");
// GridBagConstraints gbc_btnSetDevice = new GridBagConstraints();
// gbc_btnSetDevice.insets = new Insets(0, 0, 5, 0);
// gbc_btnSetDevice.gridx = 1;
// gbc_btnSetDevice.gridy = 6;
// contentPane.add(btnSetDevice, gbc_btnSetDevice);
//
// JScrollPane scrollPane = new JScrollPane();
// GridBagConstraints gbc_scrollPane = new GridBagConstraints();
// gbc_scrollPane.fill = GridBagConstraints.BOTH;
// gbc_scrollPane.gridwidth = 2;
// gbc_scrollPane.insets = new Insets(0, 0, 0, 5);
// gbc_scrollPane.gridx = 0;
// gbc_scrollPane.gridy = 7;
// contentPane.add(scrollPane, gbc_scrollPane);
//
// lMessages = new JList();
// scrollPane.setViewportView(lMessages);
//
// this.initialize();
// }
//
// private PulsCounterApplication application(){
// return this.pulsCounterApplication;
// }
//
// private void initialize(){
// this.reconnectTimer = new Timer("Reconnection Timer");
//
// messageListModel = new DefaultListModel<String>();
// lMessages.setModel(messageListModel);
//
// application().addPulsCounterApplicationListener(this);
//
// setVisible(true);
// }
//
// /*
// @Override
// public void connectionStateChanged(Boolean connected) {
//
// if (!connected){
// tfCommunication.setText("NO CONNECTION");
// if (this.deviceChecker != null){
// this.deviceChecker.cancel();
// }
// reconnectTimer.schedule(new TimerTask() {
//
// @Override
// public void run() {
// if (!application().getServiceLink().isOpen()){
// try {
// application().getServiceLink().open();
// } catch (ServiceLinkException e) {
// e.printStackTrace();
// }
// }
// }
// }, 3000);
//
// } else {
// if (this.deviceChecker != null){
// while (this.deviceChecker.isAlive()){
// try {
// Thread.sleep(100);
// } catch (InterruptedException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
// }
// this.deviceChecker = new DeviceChecker();
// this.deviceChecker.start();
// }
//
// }
// */
//
// @Override
// public synchronized void messageArrived(String message) {
// if (EventQueue.isDispatchThread()){
// int pos = messageListModel.size();
// String t = String.format("%s: %s",DateTime.NOW().getSQLDateTime(),message);
// messageListModel.addElement(t);
// lMessages.ensureIndexIsVisible(messageListModel.size()-1);
// } else {
// final String msg = message;
// EventQueue.invokeLater(new Runnable() {
//
// @Override
// public void run() {
// messageArrived(msg);
// }
// });
// }
// }
//
//
// class DeviceChecker extends Thread {
//
// private boolean cancel;
//
// public DeviceChecker(){
// cancel = false;
// }
//
// public void cancel(){
// this.cancel = true;
// }
//
// @Override
// public void run() {
//
// checkCommunication();
// checkEEPROM();
// checkIO();
// checkADC();
//
// while (!cancel){
// checkCommunication();
// }
//
// }
//
// private void checkCommunication(){
// if (!this.cancel){
// Integer version = application().getServiceLink().getServiceRegisterCache().getCachedInteger(13, 0, 0x001A);
// Integer uptime = application().getServiceLink().getServiceRegisterCache().getCachedInteger(13, 0, 0x0022);
//
// if ((version != null)&&(uptime != null)){
// tfCommunication.setText(String.format("OK (V: %d.%d.%d) Up: %d:%d:%d",version >> 16, (version >> 8) & 0xff, version & 0xff, uptime / 3600, (uptime / 60)%60, uptime % 60));
// }
// }
// }
//
// private void checkEEPROM(){
// if (!this.cancel){
// Integer eesize = application().getServiceLink().getServiceRegisterCache().getCachedInteger(13, 0, 0x9000);
// if (eesize != null){
// tfEEPROM.setText(String.format("EEPROM Size Detected: 0x%08x Bytes (%d kBytes)", eesize, (eesize >> 10)));
// } else {
// tfEEPROM.setText("EEPROM failed.");
// }
// }
// }
//
// private void checkIO(){
// if (!this.cancel){
//
// application().message("I/O test begins...");
// application().message("I/O reset...");
//
// try {
// application().getServiceLink().writeInt(13, 0, 0x0682, 0);
// application().getServiceLink().writeInt(13, 0, 0x0683, 0);
// application().getServiceLink().writeInt(13, 0, 0x0684, 0);
// application().getServiceLink().writeInt(13, 0, 0x0685, 0);
//
// application().message("counter reset.");
// for (int i=0;i<32;i++){
// application().getServiceLink().writeInt(13, 0, 0x0600 + i, 0);
// }
//
// application().message("PullUP-Counter test.");
// for (int i=0;i<12;i++){
// Thread.sleep(250);
// application().getServiceLink().writeInt(13, 0, 0x0683, -1);
// Thread.sleep(250);
// application().getServiceLink().writeInt(13, 0, 0x0683, 0);
// }
//
// for (int i=0;i<32;i++){
// Thread.sleep(100);
//
// Integer c = application().getServiceLink().readInt(13, 0, 0x0600 + i);
// if ((c != null) && (c.equals(12))){
// application().message(String.format("OK: Channel %d counted %d events.", i, c));
// } else {
// application().message(String.format("FAILED: Channel %d counted %d events.", i, c));
// }
// }
//
//
//
// application().message("I/O test finished!");
// } catch (IOException | ServiceLinkException e) {
// e.printStackTrace();
//
// application().message("I/O test FAILED!");
// } catch (InterruptedException iex){
// iex.printStackTrace();
//
// application().message("I/O test FAILED!");
// }
//
//
//
// }
// }
//
// private void checkADC(){
// if (!this.cancel){
// }
// }
//
// }
//
//
// @Override
// public void interfaceClassesChanged(PulsCounterApplication pulsCounterApplication) {
// // TODO Auto-generated method stub
//
// }
//
// @Override
// public void interfacesChanged(PulsCounterApplication pulsCounterApplication) {
// // TODO Auto-generated method stub
//
// }
}

View File

@ -148,7 +148,6 @@ public class ExportFilesFrame extends JFrame {
btnSchliessen.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setVisible(false);
PulsCounterApplication.getApplication().savePrefs();
}
});
GridBagConstraints gbc_btnSchliessen = new GridBagConstraints();

View File

@ -20,7 +20,6 @@ import org.hwo.models.FlexibleObjectListModel;
import org.hwo.platform.Platform;
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.pulscounter.device.ServiceLinkDeviceConnector;
@ -169,51 +168,21 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis
if (false){
this.connected = false;
knownTasklets = new DefaultListModel<Tasklet>();
lTasklets.setModel(knownTasklets);
TaskletManager.instance().addTaskletListener(this);
messageListModel = new DefaultListModel<String>();
lMessages.setModel(messageListModel);
timerReconnect = new Timer("ReconnectThread",true);
application().addPulsCounterApplicationListener(this);
application().message("Synololog Applikation wurde gestartet.");
timerReconnect.scheduleAtFixedRate(new TimerTask() {
this.connected = false;
@Override
public void run() {
updateChannelView();
}
}, 5000, 500);
timerReconnect.schedule(new TimerTask() {
knownTasklets = new DefaultListModel<Tasklet>();
lTasklets.setModel(knownTasklets);
TaskletManager.instance().addTaskletListener(this);
@Override
public void run() {
if (application().getServiceLink().isOpen()){
application().getSnapshotManager().notify(Notification.SYNC);
}
}
}, 15000, 15000);
timerReconnect.schedule(new TimerTask() {
messageListModel = new DefaultListModel<String>();
lMessages.setModel(messageListModel);
timerReconnect = new Timer("ReconnectThread",true);
application().addPulsCounterApplicationListener(this);
application().message("Synololog Applikation wurde gestartet.");
@Override
public void run() {
if (application().getServiceLink().isOpen()){
if (cbTrimDevice.isSelected()){
trimDevice();
}
syncClock();
}
}
}, 52000, 15000);
}
@ -284,7 +253,6 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis
}
});
channelDisplays[i].setDescriptionText( application().getChannelDescription(i));
pChannels.add(channelDisplays[i], gbc);
}
@ -313,8 +281,8 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis
AppSettingsFrame asf = new AppSettingsFrame();
asf.setModalityType(ModalityType.APPLICATION_MODAL);
if ((e.getModifiers() & ActionEvent.CTRL_MASK) != 0)
asf.debugging();
// if ((e.getModifiers() & ActionEvent.CTRL_MASK) != 0)
// asf.debugging();
asf.setVisible(true);
}
@ -436,7 +404,7 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis
public void actionPerformed(ActionEvent e) {
trimTicksOnConnect = null;
if (cbTrimDevice.isSelected()){
trimDevice();
// trimDevice();
}
}
});
@ -716,164 +684,92 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis
}
}
private void updateChannelView(){
Integer inputs,outputs,pullups;
if (application().getServiceLink().isOpen()){
inputs = application().getServiceLink().getServiceRegisterCache().getCachedInteger(13, 0, 0x0681 );
outputs = application().getServiceLink().getServiceRegisterCache().getCachedInteger(13, 0, 0x0682 );
pullups = application().getServiceLink().getServiceRegisterCache().getCachedInteger(13, 0, 0x0683 );
if (inputs == null)
inputs = 0;
if (outputs == null)
outputs = 0;
if (pullups == null)
pullups = 0;
Integer[] values = new Integer[32];
Float[] analog = new Float[8];
for (int i=0;i<32;i++){
if (i<8){
analog[i] = application().getServiceLink().getServiceRegisterCache().getCachedFloat(13, 0, 0x8000 + i ) * 10;
}
};
for (int i=0;i<32;i++){
channelDisplays[i].setInput( (inputs & 1<<i) != 0 );
channelDisplays[i].setOutput( (outputs & 1<<i) != 0);
channelDisplays[i].setPullup( (pullups & 1<<i) != 0);
channelDisplays[i].setCounter(values[i]);
if (i<8){
channelDisplays[i].setVoltage(new Double(analog[i]));
}
}
Calendar calendar = Calendar.getInstance();
try {
Integer deviceTime = application().getServiceLink().readInt(13, 0, 0x001C);
Long delta = deviceTime - (System.currentTimeMillis()/1000);
if ((delta < -1) || (delta > 1)){
application().message(String.format("Abweichung ist %d Sekunde(-n)",delta));
application().getServiceLink().writeInt((byte)13, (byte)0, 0x001C, (int)(calendar.getTimeInMillis() / 1000L));
application().message("Uhr der Elektronik wurde korrigiert.");
}
} catch (ServiceLinkRequestFailedException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ServiceLinkException e) {
e.printStackTrace();
}
checkForAssertions();
}
}
private Integer syncClock(){
return null;
}
private Integer trimDevice(){
try {
if (trimTicksOnConnect != null){
long s1,s2,T;
Integer device_us;
s1 = System.currentTimeMillis();
device_us = application().getServiceLink().readInt(13, 0, 0x1300);
s2 = System.currentTimeMillis();
T = (s1+s2)>>1;
if (device_us < 0){
trimTicksOnConnect = null;
} else {
long elapsed_us;
long diff_us;
long trim_ns_per_slice;
elapsed_us = (T - trimTimeOnConnect) * 1000;
diff_us = elapsed_us - device_us;
System.err.println(String.format("Device Triming: Elapsed us: Dev: %d PC %d Diff: %d", device_us,elapsed_us,diff_us));
trim_ns_per_slice = (diff_us * 1000) * trimDeviceTimeSlice / elapsed_us;
smoothTrim.cycle((int)trim_ns_per_slice);
System.err.println(String.format("Device Triming: Trim %dns / %dus",smoothTrim.getWert(),trimDeviceTimeSlice));
application().getServiceLink().writeInt(13, 0, 0x1002, smoothTrim.getWert());
application().message(String.format("Trimmung wurde korrigiert auf %dns / %dus",smoothTrim.getWert(),trimDeviceTimeSlice));
}
} else {
long s1,s2,T;
try {
trimTicksOnConnect = application().getServiceLink().getServiceRegisterCache().getCachedInteger(13, 0, 0x0027);
s1 = System.currentTimeMillis();
application().getServiceLink().writeInt(13, 0, 0x1301, 0);
s2 = System.currentTimeMillis();
trimTimeOnConnect = (s1+s2)>>1;
smoothTrim = new Smoother();
smoothTrim.setTn( 10 );
smoothTrim.setWert( application().getServiceLink().readInt(13, 0, 0x1002) );
} catch (Exception e){
System.err.println("trimDevice(): init failed");
e.printStackTrace();
trimTicksOnConnect = null;
}
}
} catch (Exception e){
e.printStackTrace();
}
return null;
}
private void checkForAssertions(){
Integer assert_error,assert_code;
try
{
assert_error = -1;
for (int i=0;i<8;i++){
assert_error = application().getServiceLink().readInt(13, 0, 0x0026);
assert_code = application().getServiceLink().readInt(13, 0, 0x0025);
if (assert_error >= 0)
break;
application().message(String.format("Assertion: Error: 0x%08x (%d) Position: 0x%04x Mark: %d", assert_error,assert_error, assert_code & 0xffff, (assert_code >> 16) & 0xffff));
application().getServiceLink().writeInt(13, 0, 0x0025, -1);
};
} catch (Exception ex){
System.err.println("Exception while checking for assertions...");
ex.printStackTrace();
}
}
// private Integer trimDevice(){
// try {
//
// if (trimTicksOnConnect != null){
// long s1,s2,T;
// Integer device_us;
//
//
// s1 = System.currentTimeMillis();
// device_us = application().getServiceLink().readInt(13, 0, 0x1300);
// s2 = System.currentTimeMillis();
// T = (s1+s2)>>1;
//
// if (device_us < 0){
// trimTicksOnConnect = null;
// } else {
// long elapsed_us;
// long diff_us;
// long trim_ns_per_slice;
//
// elapsed_us = (T - trimTimeOnConnect) * 1000;
// diff_us = elapsed_us - device_us;
//
// System.err.println(String.format("Device Triming: Elapsed us: Dev: %d PC %d Diff: %d", device_us,elapsed_us,diff_us));
//
// trim_ns_per_slice = (diff_us * 1000) * trimDeviceTimeSlice / elapsed_us;
//
// smoothTrim.cycle((int)trim_ns_per_slice);
//
// System.err.println(String.format("Device Triming: Trim %dns / %dus",smoothTrim.getWert(),trimDeviceTimeSlice));
//
// application().getServiceLink().writeInt(13, 0, 0x1002, smoothTrim.getWert());
//
// application().message(String.format("Trimmung wurde korrigiert auf %dns / %dus",smoothTrim.getWert(),trimDeviceTimeSlice));
//
// }
// } else {
// long s1,s2,T;
//
// try {
// trimTicksOnConnect = application().getServiceLink().getServiceRegisterCache().getCachedInteger(13, 0, 0x0027);
// s1 = System.currentTimeMillis();
// application().getServiceLink().writeInt(13, 0, 0x1301, 0);
// s2 = System.currentTimeMillis();
// trimTimeOnConnect = (s1+s2)>>1;
//
// smoothTrim = new Smoother();
// smoothTrim.setTn( 10 );
// smoothTrim.setWert( application().getServiceLink().readInt(13, 0, 0x1002) );
//
// } catch (Exception e){
// System.err.println("trimDevice(): init failed");
// e.printStackTrace();
// trimTicksOnConnect = null;
// }
// }
//
//
// } catch (Exception e){
// e.printStackTrace();
// }
// return null;
// }
//
//
// private void checkForAssertions(){
// Integer assert_error,assert_code;
//
// try
// {
// assert_error = -1;
// for (int i=0;i<8;i++){
// assert_error = application().getServiceLink().readInt(13, 0, 0x0026);
// assert_code = application().getServiceLink().readInt(13, 0, 0x0025);
//
// if (assert_error >= 0)
// break;
//
// application().message(String.format("Assertion: Error: 0x%08x (%d) Position: 0x%04x Mark: %d", assert_error,assert_error, assert_code & 0xffff, (assert_code >> 16) & 0xffff));
// application().getServiceLink().writeInt(13, 0, 0x0025, -1);
// };
// } catch (Exception ex){
// System.err.println("Exception while checking for assertions...");
// ex.printStackTrace();
// }
// }
@Override
public synchronized void taskletQueued(final TaskletManager manager, final Tasklet tasklet) {
@ -943,7 +839,7 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis
private void channelSetDescription(ChannelDisplay display){
for (int n=0;n<32;n++){
if (display == channelDisplays[n]){
application().setChannelDescription(n, display.getDescriptionText());
// application().setChannelDescription(n, display.getDescriptionText());
return;
}
}
@ -969,8 +865,11 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis
private int timeout;
private boolean exit;
private int checkTimeout;
public BackgroundThread(){
timeout = 500;
checkTimeout = 0;
exit = false;
}
@ -1005,6 +904,14 @@ public class NewMainWindow implements PulsCounterApplicationListener, TaskletLis
wait(timeout);
updateDeviceView();
if (checkTimeout > 0){
checkTimeout--;
} else {
checkTimeout = 10;
application().checkForSnapShots();
}
} catch (InterruptedException e){
}
}