[
https://issues.apache.org/jira/browse/PLC4X-181?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17055069#comment-17055069
]
César García commented on PLC4X-181:
------------------------------------
[^Test002_Write_Read_TimesDates_S7300.pcapng]
^Hi,^
^It corrects and includes the following types indicated,
S5TIME
TIME
DATE
TIME_OF_DAY
TOD
DATE_AND_TIME
DT^
^I incorporated Java types as Lukasz pointed out. I think it was the most
consistent.
Best regards,^
^***************************^
Duration ms = Duration.ofMillis(50);
Duration segundos = Duration.ofSeconds(10);
Duration horas = Duration.ofHours(2);
builder.addItem("001","%DB111.DBW0:S5TIME", ms);
builder.addItem("002","%DB111.DBW2:S5TIME", segundos);
builder.addItem("003","%DB111.DBW4:S5TIME", horas);
Duration[] durations = new Duration[]\{ms,segundos,horas};
builder.addItem("004","%DB111.DBW6:S5TIME[3]", durations);
Duration time = Duration.parse("P24DT20H31M");
builder.addItem("005","%DB105.DBD20:TIME", time);
Duration[] times = new Duration[]{Duration.parse("P23DT19H30M"),
Duration.parse("P22DT18H29M"),
Duration.parse("P21DT17H28M")};
builder.addItem("006","%DB105.DBD28:TIME[3]", times);
LocalDate date = LocalDate.of(2003, 4, 17);
builder.addItem("007","%DB106.DBW14:DATE", date);
LocalDate[] dates = new LocalDate[]{LocalDate.of(2003, 4, 17),
LocalDate.of(2010, 1, 1),
LocalDate.of(2020, 3, 8)};
builder.addItem("008","%DB106.DBW30:DATE[3]", dates);
LocalTime time01 = LocalTime.of(12, 30);
LocalTime time02 = LocalTime.of(22,59,15);
builder.addItem("009","%DB107.DBD60:TIME_OF_DAY", time01);
builder.addItem("010","%DB107.DBD64:TOD", time02);
LocalTime[] tods = new LocalTime[]\{LocalTime.of(16, 16),time01,time02};
builder.addItem("011","%DB107.DBD68:TOD[3]", tods);
LocalDateTime ldt01 = LocalDateTime.now();
System.out.println("LocalDateTime: " + ldt01 );
LocalDateTime ldt02 = LocalDateTime.of(2020, Month.MARCH, 9, 00,
54,49,123000000);
builder.addItem("012","%DB108.DBX48.0:DATE_AND_TIME", ldt01);
builder.addItem("013","%DB108.DBX56.0:DT", ldt02);
LocalDateTime[] dts = new LocalDateTime[]\{ldt01,ldt02,ldt01,ldt02};
builder.addItem("014","%DB108.DBX64.0:DT[4]", dts);
PlcWriteRequest writeRequest = builder.build();
StopWatch watch = new StopWatch();
watch.start();
PlcWriteResponse response = writeRequest.execute().get(1, TimeUnit.SECONDS);
watch.stop();
System.out.println("Duration: " + watch.getTime() +" (msec)");
//System.out.println("Response: " + response.getResponseCode("001"));
//System.out.println("Response %MX200.0:BOOL: " +
response.getAllBooleans("001"));
Collection<String> names = response.getFieldNames();
for (String name:names){
System.out.println("Index: " + name +
" Response code: " + response.getResponseCode(name));
}
/***********************************************************
* Now read
***********************************************************/
PlcReadRequest.Builder readBuilder = plcConnection.readRequestBuilder();
readBuilder.addItem("101","%DB111.DBW0:S5TIME");
readBuilder.addItem("102","%DB111.DBW2:S5TIME");
readBuilder.addItem("103","%DB111.DBW4:S5TIME");
readBuilder.addItem("104","%DB111.DBW6:S5TIME[3]");
readBuilder.addItem("105","%DB105.DBD20:TIME");
readBuilder.addItem("106","%DB105.DBD28:TIME[3]");
readBuilder.addItem("107","%DB106.DBW14:DATE");
readBuilder.addItem("108","%DB106.DBW30:DATE[3]");
readBuilder.addItem("109","%DB107.DBD60:TIME_OF_DAY");
readBuilder.addItem("110","%DB107.DBD68:TOD[3]");
readBuilder.addItem("112","%DB108.DBX48.0:DATE_AND_TIME");
readBuilder.addItem("113","%DB108.DBX56.0:DT");
readBuilder.addItem("114","%DB108.DBX64.0:DT[4]");
PlcReadRequest readRequest = readBuilder.build();
PlcReadResponse readResponse = readRequest.execute().get(1, TimeUnit.SECONDS);
Collection<String> namesResponse = readResponse.getFieldNames();
System.out.println("***********");
for (String name:namesResponse){
System.out.println("Index: " + name +
" Read Response code: " + readResponse.getResponseCode(name));
}
System.out.println("***********");
System.out.println("101: " + readResponse.getDuration("101"));
System.out.println("102: " + readResponse.getDuration("102"));
System.out.println("103: " + readResponse.getDuration("103"));
System.out.println("104: " + readResponse.getDuration("104",0));
System.out.println("104: " + readResponse.getDuration("104",1));
System.out.println("104: " + readResponse.getDuration("104",2));
System.out.println("***********");
System.out.println("105: " + readResponse.getDuration("105"));
System.out.println("106: " + readResponse.getDuration("106",0));
System.out.println("106: " + readResponse.getDuration("106",1));
System.out.println("106: " + readResponse.getDuration("106",2));
System.out.println("***********");
System.out.println("107: " + readResponse.getDate("107"));
System.out.println("108: " + readResponse.getDate("108",0));
System.out.println("108: " + readResponse.getDate("108",1));
System.out.println("108: " + readResponse.getDate("108",2));
System.out.println("***********");
System.out.println("109: " + readResponse.getTime("109"));
System.out.println("110: " + readResponse.getTime("110",0));
System.out.println("110: " + readResponse.getTime("110",1));
System.out.println("110: " + readResponse.getTime("110",2));
System.out.println("***********");
System.out.println("112: " + readResponse.getDateTime("112"));
System.out.println("113: " + readResponse.getDateTime("113"));
System.out.println("114: " + readResponse.getDateTime("114",0));
System.out.println("114: " + readResponse.getDateTime("114",1));
System.out.println("114: " + readResponse.getDateTime("114",2));
System.out.println("114: " + readResponse.getDateTime("114",3));
System.out.println("***********");
> Reading / Writing of basic types PLC S7.
> ----------------------------------------
>
> Key: PLC4X-181
> URL: https://issues.apache.org/jira/browse/PLC4X-181
> Project: Apache PLC4X
> Issue Type: Improvement
> Components: Driver-S7
> Reporter: César García
> Assignee: César García
> Priority: Major
> Fix For: 0.6.1
>
> Attachments: Test001_Write_Simple_Types_S7300_S7400.pcapng,
> Test002_Write_Read_TimesDates_S7300.pcapng
>
>
> The reading / writing of the basic S7 data types is corrected. In this
> version it focuses on the S7-300 and S7-400 devices.
> It also corrects the handling of arrangements associated with the basic types.
> In the case of complex variables of type time (DATE, TIME, TIME__OF_DAY,
> etc.), since there is no direct equivalence in Java, its conversion is left
> at the user application level.
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)