Skip to content

Commit

Permalink
Check S7 driver for USR & ALRM fault.
Browse files Browse the repository at this point in the history
  • Loading branch information
ceos01 committed Apr 30, 2023
1 parent fd4bf09 commit 000455b
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1628,9 +1628,6 @@ public enum BACnetVendorId {
OLYMPIA_ELECTRONICS((int) 1416, (int) 1416, (String) "Olympia Electronics"),
NORMAL_SOFTWARE_INC((int) 1417, (int) 1417, (String) "Normal Software, Inc."),
ST_ENGINEERING_SOLUTIONJSC((int) 1418, (int) 1418, (String) "ST Engineering Solution JSC"),
TECHKNAVE((int) 1407, (int) 1407, (String) "Techknave"),
ELSNER_ELEKTRONIK((int) 1408, (int) 1408, (String) "Elsner Elektronik"),

UNKNOWN_VENDOR((int) 0xFFFF, (int) 0xFFFF, (String) "Unknown");
private static final Map<Integer, BACnetVendorId> map;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void serialize(WriteBuffer writeBuffer) throws SerializationException {
// Padding Field (padding)
writePaddingField(
"padding",
(int) ((((!(_lastItem))) ? ((COUNT(data)) % (2)) : 0)),
(int) ((((!(_lastItem))) ? ((COUNT(data)) % (2)) : 0)),
(short) 0x00,
writeUnsignedShort(writeBuffer, 8));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.plc4x.java.s7.readwrite.protocol;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext;
Expand Down Expand Up @@ -117,7 +118,7 @@ public class S7HMuxImpl extends MessageToMessageCodec<ByteBuf, ByteBuf> implemen
*/
@Override
protected void encode(ChannelHandlerContext ctx, ByteBuf outbb, List<Object> list) throws Exception {
System.out.println("Llego aqui: " + outbb);
//System.out.println("Llego aqui: " + ByteBufUtil.hexDump(outbb));
if ((embed_ctx == null) && (ctx.channel() instanceof EmbeddedChannel)) embed_ctx = ctx;
if ((tcp_channel != null) && (embed_ctx == ctx)){
tcp_channel.writeAndFlush(outbb.copy());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,25 @@ public static void main(String[] args) throws Exception {
try (PlcConnection connection = new DefaultPlcDriverManager().getConnection("s7://10.10.1.33?remote-rack=0&remote-slot=3&controller-type=S7_400")) {
final PlcSubscriptionRequest.Builder subscription = connection.subscriptionRequestBuilder();

subscription.addEventTagAddress("myMODE", "MODE");
// subscription.addEventTagAddress("myMODE", "MODE");
// subscription.addEventTagAddress("mySYS", "SYS");
// subscription.addEventTagAddress("myUSR", "USR");
subscription.addEventTagAddress("myUSR", "USR");
// subscription.addEventTagAddress("myALM", "ALM");

final PlcSubscriptionRequest sub = subscription.build();
final PlcSubscriptionResponse subresponse = sub.execute().get();

//Si todo va bien con la subscripción puedo
subresponse
.getSubscriptionHandle("myMODE")
.register(msg -> {
System.out.println("******** S7ModeEvent ********");
Map<String, Object> map = ((S7ModeEvent) msg).getMap();
map.forEach((x, y) -> {
System.out.println(x + " : " + y);
});
System.out.println("****************************");
});
// subresponse
// .getSubscriptionHandle("myMODE")
// .register(msg -> {
// System.out.println("******** S7ModeEvent ********");
// Map<String, Object> map = ((S7ModeEvent) msg).getMap();
// map.forEach((x, y) -> {
// System.out.println(x + " : " + y);
// });
// System.out.println("****************************");
// });
//
// subresponse
// .getSubscriptionHandle("mySYS")
Expand Down Expand Up @@ -112,7 +112,7 @@ public static void main(String[] args) throws Exception {

System.out.println("Waiting for events");

Thread.sleep(5000);
Thread.sleep(30000);

System.out.println("Bye...");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static void main(String[] args) throws Exception {
System.out.println("Chapter 34 System Status Lists (SSL).");
System.out.println("URL: https://cache.industry.siemens.com/dl/files/604/44240604/att_67003/v1/s7sfc_en-EN.pdf");
System.out.println("******************************************************************************************");

Thread.sleep(10000);
try (PlcConnection connection = new DefaultPlcDriverManager().getConnection("s7://10.10.1.33?remote-rack=0&remote-slot=3&controller-type=S7_400")) { //(01)

final PlcReadRequest.Builder readrequest = connection.readRequestBuilder(); //(02)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,18 @@ public Button[] createButtonsForButtonBar(Composite parent) {

Button wbTest = new Button(parent, SWT.PUSH | SWT.CENTER);
props.setLook(wbTest);
wbTest.setText("Test");
wbTest.addListener(SWT.Selection, e -> test());
wbTest.setText("Test connection");
wbTest.addListener(SWT.Selection, e -> test_connection());

return new Button[] {wbTest};
}

public void test() {
public void test_connection() {
PlcConnection plcConnection;
try {
Plc4xConnection meta = getMetadata();
plcConnection = new DefaultPlcDriverManager().getConnection(meta.getUrl());
plcConnection.connect();

Thread.sleep(100);
plcConnection.close();
MessageBox box = new MessageBox(parent.getShell(), SWT.ICON_INFORMATION | SWT.OK);
Expand Down
12 changes: 6 additions & 6 deletions plc4j/integrations/apache-hop/plc4x-hop-transformer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
<ignoredDependencies>
<dependency>io.netty:netty-common:jar:4.1.89.Final</dependency>
<dependency>io.netty:netty-all:jar:4.1.89.Final</dependency>
<dependency>io.netty:netty-common:jar:${netty.version}</dependency>
<dependency>io.netty:netty-all:jar:${netty.version}</dependency>
<dependency>commons-lang:commons-lang:jar:2.6</dependency>
<dependency>xml-apis:xml-apis:jar:1.4.01</dependency>
<dependency>org.apache.plc4x:plc4j-spi:jar:${project.version}</dependency>
<dependency>com.fasterxml.jackson.core:jackson-annotations:jar:2.14.2</dependency>
<dependency>com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.14.2</dependency>
<dependency>com.fasterxml.jackson.core:jackson-annotations:jar:${jackson.version}</dependency>
<dependency>com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:${jackson.version}</dependency>
</ignoredDependencies>
</configuration>
</plugin>
Expand Down Expand Up @@ -138,7 +138,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
<version>${commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
Expand All @@ -153,7 +153,7 @@
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.14.2</version>
<version>${jackson.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,16 @@ public boolean processRow() throws HopException {

data.outputRowMeta = getInputRowMeta();


first = true;
if (first) {
index.clear();
plcfields.clear();
meta.getFields().forEach((f) ->{
Integer i = getInputRowMeta().indexOfValue(f.getName()); //(01)
if (i>=0) {
logDebug(">> i: " + i + " : " + f.getName() + " : " + f.getItem());
index.put(f.getName(), i);
plcfields.put(f.getName(),Plc4xPlcTag.of(f.getItem()));
plcfields.put(f.getName(), Plc4xPlcTag.of(f.getItem()));
}
});
first = false;
Expand Down Expand Up @@ -310,25 +311,39 @@ public boolean processRow() throws HopException {

if ((connmeta != null) && (connwrapper != null)){
if (connwrapper.getConnection().isConnected()){

logDebug(">>>> Paso por aqui!");
builder = null;
builder = connwrapper.getConnection().writeRequestBuilder(); //(05)
Integer i;
for (Plc4xGeneratorField field: meta.getFields()){

logDebug(">>>> Paso por aqui! 22");
i = index.get(field.getName());
if (i != null) {
//From Input Type
logDebug(">>>> Paso por aqui! 33: " + inputRowMeta.getValueMeta(i).getTypeDesc() + " : " + field.getType());
if (inputRowMeta.getValueMeta(i).getTypeDesc().
equalsIgnoreCase(field.getType()))
switch(inputRowMeta.getValueMeta(i).getType()) {
case IValueMeta.TYPE_BOOLEAN:
case IValueMeta.TYPE_INTEGER:
case IValueMeta.TYPE_NUMBER:
case IValueMeta.TYPE_BIGNUMBER:
Object value= null;
switch(plcfields.get(field.getName()).getDataType()) {
case BOOL:
case BYTE:
case WORD:
value = Short.parseShort(r[i].toString());
break;
case REAL:
value = Float.parseFloat(r[i].toString());
break;
}

logDebug(">>>> " + field.getName() + " : " + field.getItem() + " : " + r[i] + " : " + plcfields.get(field.getName()).getDataType().name());
builder.addTagAddress(field.getName(),
field.getItem(),
r[i]);
value);
break;
case IValueMeta.TYPE_DATE:
builder.addTagAddress(field.getName(),
Expand Down Expand Up @@ -401,6 +416,7 @@ public boolean processRow() throws HopException {

@Override
public boolean init() {

try {
if(super.init()){
// Determine the number of rows to generate...
Expand Down Expand Up @@ -435,6 +451,7 @@ public boolean init() {
logError("Error initializing transform", ex);
return false;
}

}

/*
Expand Down
2 changes: 1 addition & 1 deletion plc4j/integrations/apache-hop/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

<properties>
<!-- Set this to the Hop version you want to debug against-->
<hop.version>2.3.0</hop.version>
<hop.version>2.4.0</hop.version>
<!-- Path You will be using to debug the application -->
<hop.debug.path>/home/hans/Documents/test</hop.debug.path>
<!-- Third-party dependencies-->
Expand Down
19 changes: 10 additions & 9 deletions src/site/asciidoc/users/integrations/apache-hop.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
:imagesdir: ../../images/
:icons: font

image::integrations/plc4x_hop_banner.jpg[]


image::plc4x_hop_banner.jpg[banner,512,167]

== Apache Hop

Expand All @@ -26,16 +28,15 @@ image::integrations/plc4x_hop_banner.jpg[]
"__Hop aims to be the future of data integration. Visual development enables developers to be more productive than they can be through code. Our Design once, run anywhere workflows and pipelines can be designed in the Hop Gui and run on the Hop native engine (local or remote), or on Spark, Flink, Google Dataflow or AWS EMR through Beam. Lifecycle Management enables developers and administrators to switch between projects, environments and purposes without leaving your train of thought__."


.Version control
=== Record of revisions

[cols="1, 2,2a,5a"]
|===
|Rev |Release |Date |Description of the change

|0 |0.10.0 |2022/10/04 |Stable release.


.Version control
[width="100%",options="header,footer"]
|====================
| Date | Plc4x | Comments
| 10/03/2023 |0.11.0-SNAPSHOT | xxx
| | |
|====================
|===


0 comments on commit 000455b

Please sign in to comment.