You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@plc4x.apache.org by Etienne Robinet <43...@etu.he2b.be> on 2020/02/25 13:25:48 UTC
S7 Writing
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
Re: S7 Writing
Posted by Etienne Robinet <43...@etu.he2b.be>.
Hi,
I managed to get BIT, BYTE, WORD and DWORD working, seems like there was a problem in the generated source file DataItemIO.java. This file is generated with a template and a .mspec file, so I don't know how to modify it really well. I modified the generated sources locally (yikes) because the writing to the ByteBuffer wasn't really implemented for other types (always creating an empty buffer except for BOOL)
Here are my modifications for the StaticSerialize() method:
public static WriteBuffer staticSerialize(PlcValue _value, Short dataProtocolId) throws ParseException {
if(EvaluationHelper.equals(dataProtocolId, 01)) { // Boolean
WriteBuffer io = new WriteBuffer(8 / 8 );
// Reserved Field
io.writeUnsignedShort(7, ((Number) (short) 0x00).shortValue());
// Simple Field (value)
boolean value = (boolean) _value.getBoolean();
io.writeBit((boolean) (value));
return io;
} else if(EvaluationHelper.equals(dataProtocolId, 11)) { // BYTE
WriteBuffer io = new WriteBuffer((8 * 1) + 0 / 8 );
io.writeByte(8,_value.getByte());
return io;
} else if(EvaluationHelper.equals(dataProtocolId, 12)) { // WORD
WriteBuffer io = new WriteBuffer((16 * 1) + 0 / 8 );
io.writeShort(16,_value.getShort());
return io;
} else if(EvaluationHelper.equals(dataProtocolId, 13)) { // DWORD
WriteBuffer io = new WriteBuffer((32 * 1) + 0 / 8 );
io.writeInt(32,_value.getInteger());
return io;
} else if(EvaluationHelper.equals(dataProtocolId, 14)) { // List
WriteBuffer io = new WriteBuffer((64 * 1) + 0 / 8 );
return io;
} else if(EvaluationHelper.equals(dataProtocolId, 21)) { // Integer
WriteBuffer io = new WriteBuffer((32 * 1) + 0 / 8 );
// Simple Field (value)
byte value = (byte) _value.getInteger();
io.writeByte(8, ((Number) (value)).byteValue());
return io;
} else if(EvaluationHelper.equals(dataProtocolId, 22)) { // Integer
WriteBuffer io = new WriteBuffer(8 / 8 );
// Simple Field (value)
short value = (short) _value.getInteger();
io.writeUnsignedShort(8, ((Number) (value)).shortValue());
return io;
} else if(EvaluationHelper.equals(dataProtocolId, 23)) { // Integer
//DATA_TRANSPORT_ERROR_CODE 7 : SIZE MISMATCH
//Although same size as word
WriteBuffer io = new WriteBuffer((16 * 1) + 0 / 8 );
io.writeShort(16,_value.getShort());
return io;
} else if(EvaluationHelper.equals(dataProtocolId, 24)) { // Integer
WriteBuffer io = new WriteBuffer((16 * 1) + 0 / 8 );
// Simple Field (value)
int value = (int) _value.getInteger();
io.writeUnsignedInt(16, ((Number) (value)).intValue());
return io;
} else if(EvaluationHelper.equals(dataProtocolId, 25)) { // Integer
WriteBuffer io = new WriteBuffer(32 / 8 );
// Simple Field (value)
int value = (int) _value.getInteger();
io.writeInt(32, ((Number) (value)).intValue());
return io;
} else if(EvaluationHelper.equals(dataProtocolId, 26)) { // Long
WriteBuffer io = new WriteBuffer(32 / 8 );
// Simple Field (value)
long value = (long) _value.getLong();
io.writeUnsignedLong(32, ((Number) (value)).longValue());
return io;
} else if(EvaluationHelper.equals(dataProtocolId, 27)) { // Long
WriteBuffer io = new WriteBuffer(64 / 8 );
// Simple Field (value)
long value = (long) _value.getLong();
io.writeLong(64, ((Number) (value)).longValue());
return io;
} else if(EvaluationHelper.equals(dataProtocolId, 28)) { // BigInteger
WriteBuffer io = new WriteBuffer(64 / 8 );
// Simple Field (value)
BigInteger value = (BigInteger) _value.getBigInteger();
io.writeUnsignedBigInteger(64, (BigInteger) (value));
return io;
} else if(EvaluationHelper.equals(dataProtocolId, 31)) { // Float
WriteBuffer io = new WriteBuffer(32 / 8 );
// Simple Field (value)
float value = (float) _value.getFloat();
boolean negative = value < 0;
io.writeBit(negative);
final int exponent = Math.getExponent(value);
final double mantissa = value / Math.pow(2, exponent);
io.writeInt(8, exponent);
io.writeDouble(23, mantissa);
return io;
} else if(EvaluationHelper.equals(dataProtocolId, 32)) { // Double
WriteBuffer io = new WriteBuffer(64 / 8 );
// Simple Field (value)
double value = (double) _value.getDouble();
boolean negative = value < 0;
io.writeBit(negative);
final int exponent = Math.getExponent(value);
final double mantissa = value / Math.pow(2, exponent);
io.writeInt(11, exponent);
io.writeDouble(52, mantissa);
return io;
} else if(EvaluationHelper.equals(dataProtocolId, 41)) { // CHAR
WriteBuffer io = new WriteBuffer((8 * 1) + 0 / 8 );
io.writeByte(8,_value.getByte());
return io;
} else if(EvaluationHelper.equals(dataProtocolId, 42)) { // String
WriteBuffer io = new WriteBuffer(0 / 8 );
return io;
} else if(EvaluationHelper.equals(dataProtocolId, 43)) { // String
WriteBuffer io = new WriteBuffer(0 / 8 );
return io;
} else if(EvaluationHelper.equals(dataProtocolId, 44)) { // String
WriteBuffer io = new WriteBuffer(0 / 8 );
return io;
} else if(EvaluationHelper.equals(dataProtocolId, 51)) { // Time
WriteBuffer io = new WriteBuffer((4) + 0 / 8 );
// Manual Field (value)
org.apache.plc4x.java.s7.utils.StaticHelper.serializeTiaTime(io, _value);
return io;
} else if(EvaluationHelper.equals(dataProtocolId, 52)) { // Time
WriteBuffer io = new WriteBuffer((8) + 0 / 8 );
// Manual Field (value)
org.apache.plc4x.java.s7.utils.StaticHelper.serializeTiaLTime(io, _value);
return io;
} else if(EvaluationHelper.equals(dataProtocolId, 53)) { // Date
WriteBuffer io = new WriteBuffer((2) + 0 / 8 );
// Manual Field (value)
org.apache.plc4x.java.s7.utils.StaticHelper.serializeTiaDate(io, _value);
return io;
} else if(EvaluationHelper.equals(dataProtocolId, 54)) { // Time
WriteBuffer io = new WriteBuffer((4) + 0 / 8 );
// Manual Field (value)
org.apache.plc4x.java.s7.utils.StaticHelper.serializeTiaTimeOfDay(io, _value);
return io;
} else if(EvaluationHelper.equals(dataProtocolId, 55)) { // DateTime
WriteBuffer io = new WriteBuffer((8) + 0 / 8 );
// Manual Field (value)
org.apache.plc4x.java.s7.utils.StaticHelper.serializeTiaDateTime(io, _value);
return io;
}
return null;
}
If anyone could help on tweaking the .mpec or .ftlh file ?
Cesar I will test your branch
On 2020/02/26 12:20:14, Cesar Garcia <ce...@ceos.com.ve> wrote:
> Hi,
>
> The original version only handled the binary types correctly (BYTE, WORD,
> DWORD), for the rest it generates the problems that you point out.
>
> I am working on the writing of CHAR and TIME types, etc. I indicate when
> you finish these modifications.
>
> On my fork of GitHub and mount the modification, I leave the link
>
> https://github.com/glcj/plc4x/tree/s7alarm
>
> Can you help me test these modifications? For me it is important that the
> writing functions work 100%.
>
> I don't know if this code could be part of the main branch, since it is
> planned to be removed for the next release.
>
> Chris, will it be possible to work with the modifications in the main
> branch? Can it be a 0.6.X version, or something similar?
>
> Best regards,
>
>
> El mié., 26 feb. 2020 a las 4:12, Robinet, Etienne (<43...@etu.he2b.be>)
> escribió:
>
> > Hi all,
> > Chris your solution worked for writing BOOL, that's the only thing I
> > managed to do yesterday, but that's a start.
> >
> > Cesar, the BOOL also worked of course but I got some issues:
> > -BYTE, WORD, DWORD: packet is sent but no data in it (Checked the log, the
> > app is sending packet with correct size but data is {0},{0},... (but
> > response code is OK and 0 is written to the PLC)
> > -INT: Got error response code 7 (Data Size Mismatch), but the packet
> > contains the correct data (from the log) at the right address. This is the
> > query: builder.addItem("006","%MW10:INT", (short) 0x0210);
> > -Other type: I get the message that the Transfert size code does not match
> > the data type
> > ( e.g.: Transfer size code '68' doesn't match specified data type
> > 'TIME_OF_DAY' invalid)
> >
> > Etienne
> >
> >
> > Le mer. 26 févr. 2020 à 04:22, Cesar Garcia <ce...@ceos.com.ve> a
> > écrit :
> >
> > > 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.dutz@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.automation@siemens.com
> > > <su...@siemens.com>*
> > >
> >
>
>
> --
> *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.automation@siemens.com
> <su...@siemens.com>*
>
Re: S7 Writing
Posted by Cesar Garcia <ce...@ceos.com.ve>.
Hi,
The original version only handled the binary types correctly (BYTE, WORD,
DWORD), for the rest it generates the problems that you point out.
I am working on the writing of CHAR and TIME types, etc. I indicate when
you finish these modifications.
On my fork of GitHub and mount the modification, I leave the link
https://github.com/glcj/plc4x/tree/s7alarm
Can you help me test these modifications? For me it is important that the
writing functions work 100%.
I don't know if this code could be part of the main branch, since it is
planned to be removed for the next release.
Chris, will it be possible to work with the modifications in the main
branch? Can it be a 0.6.X version, or something similar?
Best regards,
El mié., 26 feb. 2020 a las 4:12, Robinet, Etienne (<43...@etu.he2b.be>)
escribió:
> Hi all,
> Chris your solution worked for writing BOOL, that's the only thing I
> managed to do yesterday, but that's a start.
>
> Cesar, the BOOL also worked of course but I got some issues:
> -BYTE, WORD, DWORD: packet is sent but no data in it (Checked the log, the
> app is sending packet with correct size but data is {0},{0},... (but
> response code is OK and 0 is written to the PLC)
> -INT: Got error response code 7 (Data Size Mismatch), but the packet
> contains the correct data (from the log) at the right address. This is the
> query: builder.addItem("006","%MW10:INT", (short) 0x0210);
> -Other type: I get the message that the Transfert size code does not match
> the data type
> ( e.g.: Transfer size code '68' doesn't match specified data type
> 'TIME_OF_DAY' invalid)
>
> Etienne
>
>
> Le mer. 26 févr. 2020 à 04:22, Cesar Garcia <ce...@ceos.com.ve> a
> écrit :
>
> > 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.dutz@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.automation@siemens.com
> > <su...@siemens.com>*
> >
>
--
*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.automation@siemens.com
<su...@siemens.com>*
Re: S7 Writing
Posted by "Robinet, Etienne" <43...@etu.he2b.be>.
Hi all,
Chris your solution worked for writing BOOL, that's the only thing I
managed to do yesterday, but that's a start.
Cesar, the BOOL also worked of course but I got some issues:
-BYTE, WORD, DWORD: packet is sent but no data in it (Checked the log, the
app is sending packet with correct size but data is {0},{0},... (but
response code is OK and 0 is written to the PLC)
-INT: Got error response code 7 (Data Size Mismatch), but the packet
contains the correct data (from the log) at the right address. This is the
query: builder.addItem("006","%MW10:INT", (short) 0x0210);
-Other type: I get the message that the Transfert size code does not match
the data type
( e.g.: Transfer size code '68' doesn't match specified data type
'TIME_OF_DAY' invalid)
Etienne
Le mer. 26 févr. 2020 à 04:22, Cesar Garcia <ce...@ceos.com.ve> a
écrit :
> 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.dutz@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.automation@siemens.com
> <su...@siemens.com>*
>
Re: S7 Writing
Posted by Cesar Garcia <ce...@ceos.com.ve>.
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.dutz@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.automation@siemens.com
<su...@siemens.com>*
Re: S7 Writing
Posted by Christofer Dutz <ch...@c-ware.de>.
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