rusEfi console: try another serial connector #819

preparations
This commit is contained in:
rusefi 2019-06-03 22:35:29 -04:00
parent aa407e48b7
commit 54565d0a43
4 changed files with 78 additions and 1 deletions

View File

@ -13,7 +13,7 @@
<target name="compile">
<mkdir dir="build/classes"/>
<javac debug="yes" destdir="build/classes"
classpath="lib/jcip-annotations-1.0.jar:lib/jlatexmath-1.0.6.jar:lib/swing-layout-1.0.jar:lib/jep.jar:lib/log4j.jar:lib/junit.jar:lib/jssc.jar:lib/SteelSeries-3.9.30.jar:lib/annotations.jar:lib/miglayout-4.0.jar:lib/surfaceplotter-2.0.1.jar">
classpath="lib/jSerialComm.jar:lib/jcip-annotations-1.0.jar:lib/jlatexmath-1.0.6.jar:lib/swing-layout-1.0.jar:lib/jep.jar:lib/log4j.jar:lib/junit.jar:lib/jssc.jar:lib/SteelSeries-3.9.30.jar:lib/annotations.jar:lib/miglayout-4.0.jar:lib/surfaceplotter-2.0.1.jar">
<src path="autotest/src"/>
<src path="io/src"/>
<src path="models/src"/>
@ -76,6 +76,7 @@
<zipfileset src="lib/log4j.jar" includes="**/*.class"/>
<zipfileset src="lib/jep.jar" includes="**/*.class"/>
<zipfileset src="lib/jssc.jar" includes="**/*.class **/*.so **/*.dll **/*.jnilib"/>
<zipfileset src="lib/jSerialComm.jar" includes="**/*.class **/*.so **/*.dll **/*.jnilib"/>
<zipfileset src="lib/annotations.jar" includes="**/*.class"/>
<zipfileset src="lib/miglayout-4.0.jar" includes="**/*.class"/>
<zipfileset src="lib/surfaceplotter-2.0.1.jar" includes="**/*.class **/*.properties"/>

View File

@ -13,5 +13,6 @@
<orderEntry type="module" module-name="models" />
<orderEntry type="module" module-name="logging" exported="" />
<orderEntry type="library" exported="" name="jcip-annotations" level="project" />
<orderEntry type="library" name="jSerialComm" level="project" />
</component>
</module>

View File

@ -0,0 +1,75 @@
package com.rusefi.io.serial;
import com.fazecast.jSerialComm.SerialPort;
import com.fazecast.jSerialComm.SerialPortDataListener;
import com.fazecast.jSerialComm.SerialPortEvent;
import com.opensr5.Logger;
import com.opensr5.io.DataListener;
import com.rusefi.io.IoStream;
import java.io.IOException;
/**
* https://github.com/Fazecast/jSerialComm looks to be alive as of 2019
* <p>
* (c) Andrey Belomutskiy
* 06/03/2019
*/
public class SerialIoStreamJSerialComm implements IoStream {
private boolean isClosed;
private SerialPort sp;
SerialIoStreamJSerialComm(SerialPort sp) {
this.sp = sp;
}
@Override
public void setInputListener(DataListener listener) {
sp.addDataListener(new SerialPortDataListener() {
@Override
public int getListeningEvents() { return SerialPort.LISTENING_EVENT_DATA_AVAILABLE; }
@Override
public void serialEvent(SerialPortEvent event)
{
if (event.getEventType() != SerialPort.LISTENING_EVENT_DATA_AVAILABLE)
return;
byte[] newData = new byte[sp.bytesAvailable()];
int numRead = sp.readBytes(newData, newData.length);
byte[] data = new byte[numRead];
System.arraycopy(newData, 0, data, 0, numRead);
listener.onDataArrived(data);
//System.out.println("Read " + numRead + " bytes.");
}
});
}
@Override
public boolean isClosed() {
return isClosed;
}
@Override
public void close() {
isClosed = true;
}
@Override
public void purge() {
}
@Override
public void write(byte[] bytes) {
sp.writeBytes(bytes, bytes.length);
}
public static IoStream open(String port, int baudRate, Logger logger) {
SerialPort sp = SerialPort.getCommPort(port);
sp.setBaudRate(baudRate);
sp.openPort();
return new SerialIoStreamJSerialComm(sp);
}
}

Binary file not shown.