It does not create nor launch more than one thread.
I tried to make the poller class to implement runnable and invoke it with run(). Also made it extend from thread and invoke it with start(). I added System.out.println(i) within the caller function pollRows() and it just prints "1".
public void pollRows() throws InterruptedException {
for (int i = 1; i < 17; i++) {
System.out.println(i);
Poller rowPollerThread = new Poller(port, rows[i]);
rowPollerThread.start();
}
}
public class Poller extends Thread {
private static byte[] pollerBytes = {
(byte) 0x01, (byte) 0x03, (byte) 0x00, (byte) 0x10, (byte) 0x00, (byte) 0x08, (byte) 0x45, (byte) 0xc9
};
private static byte[] polledBytes;
private static com.fazecast.jSerialComm.SerialPort serialPort;
private static Row row;
public Poller(com.fazecast.jSerialComm.SerialPort serialPort, Row row) {
this.serialPort = serialPort;
this.row = row;
}
@Override
public void start() {
try {
while (true) {
getHelioStates();
}
} catch (InterruptedException ex) {
Logger.getLogger(Poller.class.getName()).log(Level.SEVERE, null, ex);
}
}
private static void getHelioStates() throws InterruptedException {
for (int i = 0; i < row.getHeliostats().length; i++) {
writeFrame(i);
readByteFrame();
setHelioStates(row.getHeliostats()[i]);
Thread.sleep(1000);
}
}
private static void writeFrame(int i) {
pollerBytes[0] = (byte) row.getAddresses()[i];
serialPort.writeBytes(pollerBytes, 8);
}
private static void readByteFrame() {
polledBytes = new byte[serialPort.bytesAvailable()];
serialPort.readBytes(polledBytes, polledBytes.length);
}
private static void setHelioStates(Heliostat heliostat) {
for (int i = 0; i < polledBytes.length; i++) {
Byte b = polledBytes[i];
heliostat.bytePosition(i, b);
}
}
}
It only creates and launch the first thread, the output from the launched thread is as expected.