Skip to content

Commit

Permalink
Merge pull request #10 from ATNF/master
Browse files Browse the repository at this point in the history
Merge 1.2.7 changes to ice_3_7 branch
  • Loading branch information
sahoyle authored Jan 19, 2021
2 parents 8646d10 + 3b0d183 commit d92c82b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/atnf/atoms/mon/externalsystem/ModbusInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ private static void usage() {
System.err.println("where:");
System.err.println(" Hostname: Modbus host IP address");
System.err.println(" Port: Modbus port (usually 502)");
System.err.println(" ID: Modbus ID (1-125)");
System.err.println(" ID: Modbus ID (1-255)");
System.err.println(" Type: 1:ReadCoils, 2:ReadDiscreteInputs, 3:ReadHoldingRegisters, 4:ReadInputRegisters");
System.err.println(" Start: Modbus Start Address (0-65535)");
System.err.println(" Count: Number of points to read (optional). Default:1 (1-125)");
Expand All @@ -588,7 +588,7 @@ public static void main(String[] args) {
}

int UnitID = Integer.parseInt(args[2]);
if (UnitID < 1 || UnitID > 125)
if (UnitID < 1 || UnitID > 255)
usage();
int FCode = Integer.parseInt(args[3]);
if (FCode < 1 || FCode > 4)
Expand Down
30 changes: 23 additions & 7 deletions src/atnf/atoms/mon/translation/TranslationBytesToString.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
* Requires three arguments:
* <ol>
* <li><b>Order:</b> Determines the byte order (current ignored, set to "0").
* <li><b>Order:</b> Determines the order to read in characters from each array element ("0" = right to left, "1" = left to right).
* <li><b>Start Index:</b> The start index of the string in the input array of modbus registers.
* <li><b>Length:</b> The number of consecutive modbus registers which contain the string data.
* </ol>
Expand All @@ -23,6 +23,7 @@
**/
public class TranslationBytesToString extends Translation {

private int itsOrder;
private int itsStartIndex;
private int itsLength;

Expand All @@ -32,6 +33,7 @@ public TranslationBytesToString(PointDescription parent, String[] init) {
if (init.length != 3) {
throw new IllegalArgumentException("TranslationBytesToString: Requires three arguments");
} else {
itsOrder = Integer.parseInt(init[0]);
itsStartIndex = Integer.parseInt(init[1]);
itsLength = Integer.parseInt(init[2]);
}
Expand All @@ -58,13 +60,27 @@ public PointData translate(PointData data) {
String strval = "";
for (int i = 0; i < itsLength && itsStartIndex + i < array.length; i++) {
Long thisreg = ((Number) array[itsStartIndex + i]).longValue();
for (int j = 0; j < 64; j += 8) {
// Convert this byte into a string character
byte thisbyte = (byte) ((thisreg >> j) & 0xFF);
if (thisbyte != 0) {
strval += (char) thisbyte;
}

switch (itsOrder) {
case 0: // Contents of each array element are read right to left
for (int j = 0; j < 64; j += 8) {
// Convert this byte into a string character
byte thisbyte = (byte) ((thisreg >> j) & 0xFF);
if (thisbyte != 0) {
strval += (char) thisbyte;
}
}
case 1: // Contents of each array element are read left to right
for (int j = 56; j >= 0; j -= 8) {
// Convert this byte into a string character
byte thisbyte = (byte) ((thisreg >> j) & 0xFF);
if (thisbyte != 0) {
strval += (char) thisbyte;
}
}
default: // invalid order value
}

}
// Convert to double and set point to return
res.setData(strval);
Expand Down

0 comments on commit d92c82b

Please sign in to comment.