org.hwo.pulscounter/src/org/hwo/pulscounter/PulsCounterDevice.java

142 lines
2.6 KiB
Java

package org.hwo.pulscounter;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;
import org.hwo.io.SerialPort;
import org.hwo.io.servicelink.ServiceLink;
public class PulsCounterDevice {
private List<CounterChannel> channels; // Aktuelle ZŠhlerstŠnde
private List<TimeBarrier> timeBarriers; // TageszeitabhŠngige Wertespeicher
private Random random;
private SerialPort serialPort;
public PulsCounterDevice()
{
random = new Random();
channels = new ArrayList<CounterChannel>();
timeBarriers = new ArrayList<TimeBarrier>();
for (int n=0;n<32;n++)
{
channels.add(new CounterChannel(n + 1));
}
for (int n=0;n<10;n++)
{
timeBarriers.add(new TimeBarrier(0));
}
}
synchronized public void reset(int ch)
{
if (serialPort == null)
return;
try
{
ServiceLink sl = new ServiceLink(serialPort);
sl.writeInt((byte)0, (byte)0, (short)(0x1000 + ch), 0);
} catch (Exception e)
{
System.err.println("Exception: " + e);
e.printStackTrace();
}
if (serialPort.isOpen())
serialPort.close();
}
synchronized public void reset()
{
if (serialPort == null)
return;
try
{
ServiceLink sl = new ServiceLink(serialPort);
for (int i=0;i<32;i++)
sl.writeInt((byte)0, (byte)0, (short)(0x1000 + i), 0);
} catch (Exception e)
{
System.err.println("Exception: " + e);
e.printStackTrace();
}
if (serialPort.isOpen())
serialPort.close();
}
synchronized public void update()
{
if (serialPort == null)
return;
try
{
ServiceLink sl = new ServiceLink(serialPort);
System.err.println(String.format("BRKVAL: 0x%04x", sl.readInt((byte)0, (byte)0, (short)0x200)));
System.err.println(String.format("SPLIM : 0x%04x", sl.readInt((byte)0, (byte)0, (short)0x201)));
for (int i=0;i<32;i++)
{
channels.get(i).setValue( sl.readInt((byte)0x0D, (byte)0, (short)(0x1000 + i)) );
}
} catch (Exception e)
{
System.err.println("Exception: " + e);
e.printStackTrace();
}
if (serialPort.isOpen())
serialPort.close();
}
public String getDeviceName()
{
return "PulsCounter Board";
}
public Date getDeviceTime()
{
return new Date();
}
public List<CounterChannel> getChannels()
{
return channels;
}
public List<TimeBarrier> getTimeBarriers()
{
return timeBarriers;
}
public SerialPort getSerialPort() {
return serialPort;
}
public void setSerialPort(SerialPort serialPort) {
this.serialPort = serialPort;
}
}