-
Notifications
You must be signed in to change notification settings - Fork 3
Fix IllegalArgumentException #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8f1141b
c352e3c
b802934
4fefda0
bd12151
d1f89d5
e295920
e93dcd8
994c3ce
7d6a41b
c72cfba
576c305
2c5ab6f
acb5624
d1a7baa
d6c02f9
a55ab83
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -101,9 +101,11 @@ public abstract class AbstractSerialConnection { | |
| public abstract void close(); | ||
|
|
||
| /** | ||
| * Returns current baud rate | ||
| * Returns current baud rate. | ||
| * <p> | ||
| * For UART interfaces (RS-232 / RS-485), this is equal to the line bit rate in bits/s. | ||
| * | ||
| * @return Baud rate | ||
| * @return Baud rate (bits/s) | ||
| */ | ||
| public abstract int getBaudRate(); | ||
|
|
||
|
|
@@ -115,12 +117,34 @@ public abstract class AbstractSerialConnection { | |
| public abstract int getNumDataBits(); | ||
|
|
||
| /** | ||
| * Returns current stop bits | ||
| * Returns current stop bits configuration constant. | ||
| * <p> | ||
| * Use {@link #getStopBits()} to get the actual stop bits in bit times. | ||
| * | ||
| * @return Number of stop bits | ||
| * @return Stop-bit configuration constant. | ||
| */ | ||
| public abstract int getNumStopBits(); | ||
|
|
||
| /** | ||
| * Returns current stop bits as actual bit times. | ||
| * <p> | ||
| * Use {@link #getNumStopBits()} to get the stop bits configuration constant. | ||
| * | ||
| * @return Stop-bit length in bit times. | ||
| */ | ||
| public float getStopBits() { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Das Naming passt nicht. Es werden nicht die StopBits zurückgegeben, sondern die Bit Times.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ich hätte es so gelassen. In der Modbus Serial Specification wird auch nicht zwischen Stop Bits und Stop Bit Times unterschieden. |
||
| switch (getNumStopBits()) { | ||
| case ONE_STOP_BIT: | ||
| return 1.0f; | ||
| case ONE_POINT_FIVE_STOP_BITS: | ||
| return 1.5f; | ||
| case TWO_STOP_BITS: | ||
| return 2.0f; | ||
| default: | ||
| return 1.0f; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Returns current parity | ||
| * | ||
|
|
@@ -179,4 +203,20 @@ public abstract class AbstractSerialConnection { | |
| */ | ||
| public abstract Set<String> getCommPorts(); | ||
|
|
||
| /** | ||
| * Returns the total number of serial bit-times required to transmit | ||
| * a single character with the current port configuration. | ||
| * | ||
| * @return Total bit-times per character. | ||
| */ | ||
| public double getBitsPerCharacter() { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Das Naming ist nicht gut. Bei
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Es sind ja die Bits, die ein Character für die Übertragung braucht. Da es ja um Datenübertragung geht, würde ich
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Es geht nicht um den Kommentar, sondern um den Funktionsnamen. Weil es eben um die Übertragung geht, würde ich die Funktion
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ich verstehe, das Clean-Code möglichst präzise namen bevorzugt. Ich würde aber Argumentieren, dass es im Kontext von Gleichzeitig wäre es mir aber auch nicht besonders wichtig. @michaelgrill als unparteiischer Dritter? |
||
| final double startBit = 1.0; | ||
| final int numDataBits = getNumDataBits(); | ||
| final int dataBits = numDataBits == 0 ? 8 : numDataBits; | ||
| final double stopBits = getStopBits(); | ||
| final double parityBits = getParity() == NO_PARITY ? 0 : 1; | ||
|
|
||
| return startBit + dataBits + stopBits + parityBits; | ||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Das verursacht 100% CPU Auslastung auf einem Kern, solange es läuft. Sollte man, wie früher, davor und danach die Thread Priorität auf LOW stellen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wenn überhaupt, würde ich eher Thread.yield() verwenden. Aber damit nimmt man sich die Genauigkeit.
Auf der anderen Seite hat die aktuelle implementierung die factoren x1,3 bzw. x1,7 drin. Also ist das Timing sowieso nicht exakt.
Leider ist im Code nirgends dokumentiert, wofür diese Fudge-Faktoren gedacht sind oder wie sie ermittelt wurden.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aber wo ruft man Thread.yield() auf? Thread.yield() in jedem while Durchlauf auszuführen ist auch nicht gut. Macht es vllt. Sinn j2mod auf Java 21 upzudaten und die neue Thread.sleep() Implementierung mit dem nanoseconds Übergabeparameter zu nutzen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thread.sleep(millis, nanos)gibt es auch in Java 8 schon. Einsleep()schickt den Thread aber immer an den OS-Scheduler und ist deshalb oft um mehrere Millisekunden ungenau, egal was man an Nanos übergibt. Java nutzt die Nanos eher zum Runden.Für echte nano- oder mikrosekunden-Genauigkeit kommen wir um ein busy-wait nicht herum.
Zum entlasten im busy-wait sehe ich zwei möglichkeiten:
Thread.yield(): Da gibt es aber keine Garantie, was das OS daraus macht. Es könnte Compute freigeben, oder sich wie ein reiner Busy-Wait verhalten. Ist wieder völlig OS abhängig.Thread.onSpinWait(): Dafür müssten wir auf Java 9 Upgraden. Damit kann man innerhalb des busy-wait der CPU signalisieren, dass sie compute freigeben kann.Du kannst hier gerne was ergänzen, falls du mehr weißt, aber das ist, was ich mir bisher schon zusammen gereimt habe.