Re: Connection time out
Hi Anup, the snapshots are not available at Maven-Central. Only released versions are available there. We deploy our snapshots to the Apache repository at "repository.apache.org". You can add them to your project, by adding this repo to your main pom. apache-snapshots https://repository.apache.org/content/repositories/snapshots false true apache-snapshots https://repository.apache.org/content/repositories/snapshots false true Hope that helps. Chris Am 06.10.20, 09:26 schrieb "Anup K M" : Hi Christofer Dutz, As mentioned earlier, I have tried to use 0.8.0-SNAPSHOT but its showing "org.apache.plc4x:plc4j-api:0.8.0-SNAPSHOT" not found. And I have checked on the maven repository there was dependency upto 0.7.0. version. How to use the 0.8.0-SNAPSHOT version. Thanks & regards, Anup On Thu, Oct 1, 2020 at 5:26 PM Christofer Dutz wrote: > Hi Anup, > > please make sure you are using the 0.8.0-SNAPSHOT version ... we're > currently working hard on releasing it soon. > But there were some issues with the Modbus driver before that. > > Chris > > > Am 01.10.20, 13:44 schrieb "Anup K M" : > > Hello everyone, > > I am using PLC4X java api to connect some devices through modbus tcp > protocol on my windows device. After every 50 minutes of execution the > connection fails with the every devices even after making the > reconnection > at the same instance , it is not getting connected it throws the > PlcConnectionException. How to make it connected for 24*7 and access > the > data 24*7. > > Thanks and regards, > Anup K M > > -- > > > > > > > > IMPORTANT: The contents of this email and any attachments are > confidential. They are intended for the named recipient(s) only. If > you > have received this email by mistake, please notify the sender > immediately > and do not disclose the contents to anyone or make copies thereof. > > Please, > consider your environmental responsibility. Before printing this > e-mail ask > yourself: "Do I need a hard copy?" > > -- IMPORTANT: The contents of this email and any attachments are confidential. They are intended for the named recipient(s) only. If you have received this email by mistake, please notify the sender immediately and do not disclose the contents to anyone or make copies thereof. Please, consider your environmental responsibility. Before printing this e-mail ask yourself: "Do I need a hard copy?"
[GitHub] [plc4x] hutcheb commented on a change in pull request #192: Refactor Field Handler Classes
hutcheb commented on a change in pull request #192: URL: https://github.com/apache/plc4x/pull/192#discussion_r500144795 ## File path: plc4j/api/src/main/java/org/apache/plc4x/java/api/value/PlcBYTE.java ## @@ -181,6 +205,90 @@ public short getShort() { return value; } +@Override +@JsonIgnore +public boolean isInteger() { +return true; +} + +@Override +@JsonIgnore +public int getInteger() { +return value.intValue(); +} + Review comment: I think there a at least two use cases for these methods. To use them when parsing the value within the dataio classes. The other is by the user when they need to parse the value to a specific type. A generic function to be used when parsing like getValue() would be good. For the user the getInteger, getByte, etc.. might be good as I can't think of an easy way to pass a type to the function and have it return the data type requested without just putting the existing functions within a switch statement. This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Cost of Exceptions [was: chrisdutz commented on a change in pull request #192: Refactor Field Handler Classes]
On Tue, Oct 6, 2020 at 9:33 AM GitBox wrote: >One thing I've learnt recently, is that exceptions are extremely > expensive, as creating the stack trace is expensive. is this code that is > likely to produce any of "InstantiationException | IllegalAccessException | > InvocationTargetException | NoSuchMethodException" in normal execution? If > yes, we should probably change this and other parts where we use similar > patterns to check first instead of silently catching exceptions. > Chris is right; Exceptions are incredibly expensive and I have seen instances where a few PLCs are put offline, and the supervisory system goes into a snail pace, either due to excessive exceptions, aggressive retries (without back-off), or both and sometimes with other "oh, didn't think of that" ooopsies. In general, all faults in "real world" should not throw exceptions, and should be viewed as "normality". And unfortunately, Java programmers (even those in this field) tend to not think in "error scenarios" and only in "sunny day paths". Personally, I got over the "exception craze" about 20 years ago, and try to be exception-free. A few tricks to get there; 1. Event driven systems doesn't need "return values", hence a lot less exceptions. Error conditions are different events and subscribers can specialize in the handling. Making a system event driven instead of the request/response type, takes a fair amount of unlearning and mind bending, but worth it. 2. Try to figure out ahead of time if exceptions may be thrown by code I don't control. 3. Don't create nor rethrow exceptions. If in dev/test mode, log an error report containing all possible states that could affect the outcome and then System.exit() as to indicate that there is a serious problem that should not be ignored. In production, the error report is sent to "operations" (containing info to forward to developers if needed) and tries to recover. // Niclas
[GitHub] [plc4x] hutcheb commented on a change in pull request #192: Refactor Field Handler Classes
hutcheb commented on a change in pull request #192: URL: https://github.com/apache/plc4x/pull/192#discussion_r500139132 ## File path: plc4j/api/src/main/java/org/apache/plc4x/java/api/value/PlcBYTE.java ## @@ -169,6 +169,30 @@ public PlcBYTE(@JsonProperty("value") short value) { } } +@Override +@JsonIgnore +public boolean isBoolean() { +return true; +} + +@Override +@JsonIgnore +public boolean getBoolean() { +return (value != null) && !value.equals(0); +} Review comment: I was having trouble with how we would do this. I was initially thinking that if we request to read a WORD we should parse the return value as a PlcList of PlcBOOLs instead of a PlcWORD but wasn't sure how to implement this easily. But your idea of returning a list from a getBoolean method seems reasonable. This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [plc4x] hutcheb commented on a change in pull request #192: Refactor Field Handler Classes
hutcheb commented on a change in pull request #192: URL: https://github.com/apache/plc4x/pull/192#discussion_r500131203 ## File path: plc4j/api/src/main/java/org/apache/plc4x/java/api/value/PlcValues.java ## @@ -355,6 +356,28 @@ public static PlcValue of(Map map) { return new PlcStruct(map); } +private static PlcValue constructorHelper(Constructor constructor, Object value) { +try { +return (PlcValue) constructor.newInstance(value); +} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { +throw new PlcIncompatibleDatatypeException(value.getClass()); +} +} + +public static PlcValue of(Object[] values, Class clazz) { +//Encode values to the type defined in clazz +try { +Constructor constructor = clazz.getDeclaredConstructor(values[0].getClass()); +if(values.length == 1) { +return ((PlcValue) constructor.newInstance(values[0])); +} else { +return PlcValues.of(Arrays.stream(values).map(value -> (constructorHelper(constructor, value))).collect(Collectors.toList())); +} Review comment: The exception would be raised if there wasn't a class (PlcBYTE, PlcINT, etc..) that matched the datatype that was passed. It shouldn't be raised in normal operation. This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [plc4x] hutcheb commented on a change in pull request #192: Refactor Field Handler Classes
hutcheb commented on a change in pull request #192: URL: https://github.com/apache/plc4x/pull/192#discussion_r500123620 ## File path: plc4j/api/src/main/java/org/apache/plc4x/java/api/value/PlcBYTE.java ## @@ -169,6 +169,30 @@ public PlcBYTE(@JsonProperty("value") short value) { } } +@Override +@JsonIgnore +public boolean isBoolean() { +return true; +} + +@Override +@JsonIgnore +public boolean getBoolean() { +return (value != null) && !value.equals(0); +} + +@Override +@JsonIgnore +public boolean isByte() { +return (value != null) && (value <= Byte.MAX_VALUE) && (value >= Byte.MIN_VALUE); +} + +@Override +@JsonIgnore +public byte getByte() { +return value.byteValue(); +} + Review comment: There's no reason to have the getBYTE,getINT,getREAL,etc... they don't get used anymore. I added these in the previous PR so we can customize the method that gets called in the data-io template by using the case name. This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [plc4x] chrisdutz commented on a change in pull request #192: Refactor Field Handler Classes
chrisdutz commented on a change in pull request #192: URL: https://github.com/apache/plc4x/pull/192#discussion_r500057457 ## File path: plc4j/api/src/main/java/org/apache/plc4x/java/api/value/PlcBYTE.java ## @@ -169,6 +169,30 @@ public PlcBYTE(@JsonProperty("value") short value) { } } +@Override +@JsonIgnore +public boolean isBoolean() { +return true; +} + +@Override +@JsonIgnore +public boolean getBoolean() { +return (value != null) && !value.equals(0); +} + +@Override +@JsonIgnore +public boolean isByte() { +return (value != null) && (value <= Byte.MAX_VALUE) && (value >= Byte.MIN_VALUE); +} + +@Override +@JsonIgnore +public byte getByte() { +return value.byteValue(); +} + Review comment: We now have a "byte getByte()" and a "short getBYTE()" method, I think it should only be the one or the other ... I would like to opt for the "byte getByte()". But right now I'm unsure which implications that would have. ## File path: plc4j/api/src/main/java/org/apache/plc4x/java/api/value/PlcBYTE.java ## @@ -169,6 +169,30 @@ public PlcBYTE(@JsonProperty("value") short value) { } } +@Override +@JsonIgnore +public boolean isBoolean() { +return true; +} + +@Override +@JsonIgnore +public boolean getBoolean() { +return (value != null) && !value.equals(0); +} Review comment: In general a bit-string (at least in my perception of it, represents an array of booleans. So if for example I read one byte, from the point of the API it should be a list of 8 boolean values ... I think we need to allow this somehow. Right now the only way would be to get the "byte" value and to pick that appart. ## File path: plc4j/api/src/main/java/org/apache/plc4x/java/api/value/PlcBYTE.java ## @@ -181,6 +205,90 @@ public short getShort() { return value; } +@Override +@JsonIgnore +public boolean isInteger() { +return true; +} + +@Override +@JsonIgnore +public int getInteger() { +return value.intValue(); +} + Review comment: Instead of adding these for every type, wouldn't it make sense to have something like a "PlcIECBitStringValue", "PlcIECIntegerValue", ...? ## File path: plc4j/api/src/main/java/org/apache/plc4x/java/api/value/PlcBYTE.java ## @@ -181,6 +205,90 @@ public short getShort() { return value; } +@Override +@JsonIgnore +public boolean isInteger() { +return true; +} + +@Override +@JsonIgnore +public int getInteger() { +return value.intValue(); +} + Review comment: But thinking of it ... perhaps making it generic and passing in the type would help ... ## File path: plc4j/api/src/main/java/org/apache/plc4x/java/api/value/PlcValues.java ## @@ -355,6 +356,28 @@ public static PlcValue of(Map map) { return new PlcStruct(map); } +private static PlcValue constructorHelper(Constructor constructor, Object value) { +try { +return (PlcValue) constructor.newInstance(value); +} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { +throw new PlcIncompatibleDatatypeException(value.getClass()); +} +} + +public static PlcValue of(Object[] values, Class clazz) { +//Encode values to the type defined in clazz +try { +Constructor constructor = clazz.getDeclaredConstructor(values[0].getClass()); +if(values.length == 1) { +return ((PlcValue) constructor.newInstance(values[0])); +} else { +return PlcValues.of(Arrays.stream(values).map(value -> (constructorHelper(constructor, value))).collect(Collectors.toList())); +} Review comment: One thing I've learnt recently, is that exceptions are extremely expensive, as creating the stack trace is expensive. is this code that is likely to produce any of "InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException" in normal execution? If yes, we should probably change this and other parts where we use similar patterns to check first instead of silently catching exceptions. This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: Connection time out
Hi Christofer Dutz, As mentioned earlier, I have tried to use 0.8.0-SNAPSHOT but its showing "org.apache.plc4x:plc4j-api:0.8.0-SNAPSHOT" not found. And I have checked on the maven repository there was dependency upto 0.7.0. version. How to use the 0.8.0-SNAPSHOT version. Thanks & regards, Anup On Thu, Oct 1, 2020 at 5:26 PM Christofer Dutz wrote: > Hi Anup, > > please make sure you are using the 0.8.0-SNAPSHOT version ... we're > currently working hard on releasing it soon. > But there were some issues with the Modbus driver before that. > > Chris > > > Am 01.10.20, 13:44 schrieb "Anup K M" : > > Hello everyone, > > I am using PLC4X java api to connect some devices through modbus tcp > protocol on my windows device. After every 50 minutes of execution the > connection fails with the every devices even after making the > reconnection > at the same instance , it is not getting connected it throws the > PlcConnectionException. How to make it connected for 24*7 and access > the > data 24*7. > > Thanks and regards, > Anup K M > > -- > > > > > > > > IMPORTANT: The contents of this email and any attachments are > confidential. They are intended for the named recipient(s) only. If > you > have received this email by mistake, please notify the sender > immediately > and do not disclose the contents to anyone or make copies thereof. > > Please, > consider your environmental responsibility. Before printing this > e-mail ask > yourself: "Do I need a hard copy?" > > -- IMPORTANT: The contents of this email and any attachments are confidential. They are intended for the named recipient(s) only. If you have received this email by mistake, please notify the sender immediately and do not disclose the contents to anyone or make copies thereof. Please, consider your environmental responsibility. Before printing this e-mail ask yourself: "Do I need a hard copy?"