Hi Chris,

I understand that the priority of the drivers in PLC4X is the reading
process, so writing to the PLC has not worked much.

I have already made several corrections in the legacy driver for the S7,
which corrects the writing process, however there are still many types
(characters, strings and time) that are not written.

I hope to upload the code tomorrow in such a way that it helps in the new
version of the driver for S7.

Attach the test code.

try (PlcConnection plcConnection = new
PlcDriverManager().getConnection("s7://192.168.1.23/0/2")){
            System.out.println("Write to MW200..2003, values 0x0001,
0x0002, 0x0003...");
            PlcWriteRequest.Builder builder =
plcConnection.writeRequestBuilder();

            /**
             * Test for S7300/S7400
             * Elementary Data Types
             * Bit Data Types
            **/
            builder.addItem("001","%MX200.0:BOOL", true);
            builder.addItem("002","%MB201:BYTE", (byte) 0x12);
            builder.addItem("003","%MW202:WORD", (short) 0x4321);
            builder.addItem("004","%MD204:DWORD", (int) 0x87654321);

            /*
             * Character Types
             * TODO: Fail S7PlcFieldHandler, line 247
            */
            //builder.addItem("005","%MB208:CHAR", (byte) 0x32);

            /*
             * Numeric Types
            */
            builder.addItem("006","%MW210:INT", (short) 0x0210);
            builder.addItem("007","%MD212:DINT", (int) 0x21200212);
            builder.addItem("008","%MD216:REAL", (float) 3.141516);

            /*
             * Time Types
            */
            //builder.addItem("009","%MD220:TIME",
LocalDateTime.now().toLocalTime());
            //builder.addItem("010","%MW224:DATE",
LocalDateTime.now().toLocalDate());
            //builder.addItem("011","%MD226:TIME_OF_DAY",
LocalDateTime.now().toLocalTime());

            /**
             * Test for S7300/S7400
             * Complex Data Types
            **/
            //builder.addItem("012","%MD230:DT", LocalDateTime.now());
            //builder.addItem("013","%MD234:DATE_AND_TIME",
LocalDateTime.now());
            //builder.addItem("014","%MD234:STRING", "VENEZUELA");
            //builder.addItem("015","%MB234:ARRAY",
(byte)[]({0x01,0x02,0x03}));

            PlcWriteRequest request = builder.build();

            PlcWriteResponse response = request.execute().get(2,
TimeUnit.SECONDS);

            Collection<String> names = response.getFieldNames();

            for (String name:names){
                System.out.println("Index: " + name +
                        " Response code: " +
response.getResponseCode(name));
            }

            plcConnection.close();
        } catch (Exception ex){
            LOGGER.info("Fail connection. Check IP address, rack, slot: " +
ex);
        }

Best regards,

El mar., 25 feb. 2020 a las 16:34, Christofer Dutz (<
christofer.d...@c-ware.de>) escribió:

> Hi Etienne,
>
> yes indeed. The thing is none ever asked for writing even if we've
> implemented that.
> Try this code:
>
>             PlcWriteRequest.Builder writeBuilder =
> plcConnection.writeRequestBuilder();
>             writeBuilder.addItem("value-1", "%Q0.0:BOOL", true);
>             writeBuilder.addItem("value-2", "%Q0.1:BOOL", true);
>             writeBuilder.addItem("value-3", "%Q0.2:BOOL", true);
>             writeBuilder.addItem("value-4", "%Q0.3:BOOL", true);
>             final PlcWriteRequest writeRequest = writeBuilder.build();
>
>             final PlcWriteResponse plcWriteResponse =
> writeRequest.execute().get();
>             System.out.println(plcWriteResponse);
>
> At least that's the code I've used for testing the new write features of
> the new S7 driver.
>
> Chris
>
>
>
> Am 25.02.20, 14:25 schrieb "Etienne Robinet" <43...@etu.he2b.be>:
>
>     Hi all,
>     are there any example of writing to a S7 PLC? All the examples in the
> library are about READING from a PLC. Is the writing also implemented yet
> (seems like it).
>
>     I had some quick tries but nothing precise for now.
>
>     Regards,
>
>     Etienne
>
>
>

-- 
*CEOS Automatización, C.A.*
*GALPON SERVICIO INDUSTRIALES Y NAVALES FA, C.A.,*
*PISO 1, OFICINA 2, AV. RAUL LEONI, SECTOR GUAMACHITO,*

*FRENTE A LA ASOCIACION DE GANADEROS,BARCELONA,EDO. ANZOATEGUI*
*Ing. César García*
*Cel: 0416-681.03.99*

*Cel: 0414-760.98.95*

*Hotline Técnica SIEMENS: 0800 1005080*

*Email: support.aan.automat...@siemens.com
<support.aan.automat...@siemens.com>*

Reply via email to