107 lines
1.9 KiB
Java
107 lines
1.9 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;
|
|
|
|
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));
|
|
}
|
|
|
|
}
|
|
|
|
public void update()
|
|
{
|
|
if (serialPort == null)
|
|
return;
|
|
|
|
if (!serialPort.open())
|
|
{
|
|
System.err.println("Fehler: Port konnte nicht gešffnet werden!");
|
|
}
|
|
|
|
try
|
|
{
|
|
DeviceControlChannel channel = new DeviceControlChannel(serialPort.getInputStream(), serialPort.getOutputStream());
|
|
|
|
channel.noop();
|
|
|
|
|
|
for (int i=0;i<32;i++)
|
|
{
|
|
int inc = random.nextInt(15);
|
|
if (inc > 4)
|
|
inc = 0;
|
|
|
|
channels.get(i).setValue(channels.get(i).getValue() + inc);
|
|
}
|
|
} 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;
|
|
}
|
|
|
|
|
|
}
|