You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@plc4x.apache.org by "sang jiexun (Jira)" <ji...@apache.org> on 2022/06/23 07:08:00 UTC
[jira] [Comment Edited] (PLC4X-347) org.apache.plc4x.java.s7.readwrite.field.S7Field cannot be cast to org.apache.plc4x.java.s7.readwrite.field.S7SubscriptionField
[ https://issues.apache.org/jira/browse/PLC4X-347?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17557852#comment-17557852 ]
sang jiexun edited comment on PLC4X-347 at 6/23/22 7:07 AM:
------------------------------------------------------------
!image-2022-06-23-15-03-23-623.png!
I have solved the above problem, but the background will find that globaleventexecutor threads will be added every time a method is requested to be written. How do you close these threads to free system resources. {color:#ff8b00}*MY CODE:*{color}
{code:java}
public void writePLC(String dbName, String dbValue) {
// PooledPlcDriverManager.PoolCreator poolCreator;
PlcDriverManager driverManager = new PlcDriverManager();
// PlcDriverManager driverManager = new PooledPlcDriverManager(poolKeyFactory);
try {
//
/**
* 在多个服务之间共享连接时,请确保共享 的实例,否则将导致具有多个池。
*/
//
// driverManage = new PlcDriverManager(this.getClass().getClassLoader());
plcConnection = driverManager.getConnection(connectionIp);
if (!plcConnection.isConnected()) {
// writePLC(dbName, dbValue);
return;
} else {
// plcConnection.connect();
PlcWriteRequest.Builder writeRequestBuilder = plcConnection.writeRequestBuilder();
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
writeRequestBuilder.addItem(dbName, dbName, dbValue);
// System.out.println(var);
System.out.println("开始写入");
/*-------------- 异步方式 ------------------------*/
PlcWriteRequest writeRequest = writeRequestBuilder.build();
// PlcWriteResponse response = writeRequest.execute().get(10, TimeUnit.SECONDS);
CompletableFuture<? extends PlcWriteResponse> asyncResponse = writeRequest.execute();
asyncResponse.whenComplete((response, throwable) -> {
System.out.println("写入成功");
for (String fieldName : response.getFieldNames()) {
if (response.getResponseCode(fieldName) == PlcResponseCode.OK) {
log.info("Value[" + fieldName + "]: updated");
System.out.println("Value[" + fieldName + "]: updated ->" + S7DTO.getPlcMap().get(fieldName));
}
// Something went wrong, to output an error message instead.
else {
log.error("Error[" + fieldName + "]: " + response.getResponseCode(fieldName).name());
}
}
});
/*--------------- 同步方式 -----------------*/
// PlcWriteRequest writeRequest = writeRequestBuilder.build();
// PlcWriteResponse response = writeRequest.execute().get(10, TimeUnit.SECONDS);
//
// for (String fieldName : response.getFieldNames()) {
// if (response.getResponseCode(fieldName) == PlcResponseCode.OK) {
// log.info("Value[" + fieldName + "]: updated");
// System.out.println("Value[" + fieldName + "]: updated ->" + S7DTO.getPlcMap().get(fieldName));
// }
// // Something went wrong, to output an error message instead.
// else {
// log.error("Error[" + fieldName + "]: " + response.getResponseCode(fieldName).name());
// }
// }
// System.out.println("写入成功");
// Thread.sleep(2000);
// plcConnection.close();
// }
}
} catch (Throwable throwable) {
log.error(throwable.getMessage());
}
} {code}
was (Author: JIRAUSER291307):
!image-2022-06-23-15-03-23-623.png!
I have solved the above problem, but the background will find that globaleventexecutor threads will be added every time a method is requested to be written. How do you close these threads to free system resources.
> org.apache.plc4x.java.s7.readwrite.field.S7Field cannot be cast to org.apache.plc4x.java.s7.readwrite.field.S7SubscriptionField
> -------------------------------------------------------------------------------------------------------------------------------
>
> Key: PLC4X-347
> URL: https://issues.apache.org/jira/browse/PLC4X-347
> Project: Apache PLC4X
> Issue Type: Bug
> Components: PLC4J
> Affects Versions: 0.9.1
> Reporter: sang jiexun
> Priority: Major
> Labels: plc4x
> Fix For: 0.9.1
>
> Attachments: image-2022-06-22-08-42-41-699.png, image-2022-06-22-08-43-54-671.png, image-2022-06-22-08-44-30-817.png, image-2022-06-22-08-47-05-461.png, image-2022-06-22-13-26-55-807.png, image-2022-06-23-15-03-23-623.png
>
>
>
>
> !image-2022-06-22-08-43-54-671.png|width=767,height=598!
> !image-2022-06-22-08-44-30-817.png|width=638,height=134!
> !image-2022-06-22-08-47-05-461.png|width=1369,height=633!
>
> !image-2022-06-22-08-42-41-699.png!
> h1.
> h1. {color:#ff8b00}*Dear developer, how can I fix this problem?*{color}
--
This message was sent by Atlassian Jira
(v8.20.7#820007)