Hi all,

I just wanted to inform you that I just merged something I was planning on 
doing for quite some time.
Support of external types.

This means that you can introduce types into your mspec, which are not defined 
inside the mspec itself.

This is particularly interesting for DataIo types as it allows supporting using 
our PlcValueTypes directly without the need to re-define them in the mspec and 
then to aquardly map them in the drvier, like I did in the ADS driver.

It’s not a huge change, but I think it will help model the DataIo parts in the 
future.

In order to keep things as simple as possible, I added an msped argument: 
“external”. You define the type just like you usually would, but leave the body 
empty and mark it as external:


[type AdsConstants
    [const          uint 16     adsTcpDefaultPort 48898]
]

////////////////////////////////////////////////////////////////
// External types
////////////////////////////////////////////////////////////////

[enum PlcValueType external='true']

////////////////////////////////////////////////////////////////
// AMS/TCP Packet
////////////////////////////////////////////////////////////////


Then in the maven plugin you can provide the type information according the 
programming language you are aiming for:

Java:

<executions>
  <execution>
    <id>generate-ams-structs</id>
    <phase>generate-sources</phase>
    <goals>
      <goal>generate-driver</goal>
    </goals>
    <configuration>
      <protocolName>ads</protocolName>
      <languageName>java</languageName>
      <outputFlavor>read-write</outputFlavor>
      <outputDir>src/main/generated</outputDir>
      <options>
        <externalTypes>
          
<PlcValueType>org.apache.plc4x.java.api.types.PlcValueType</PlcValueType>
        </externalTypes>
      </options>
    </configuration>
  </execution>

Go:

<execution>
  <id>generate-driver-ads</id>
  <phase>generate-sources</phase>
  <goals>
    <goal>generate-driver</goal>
  </goals>
  <configuration>
    <protocolName>ads</protocolName>
    <languageName>go</languageName>
    <outputFlavor>read-write</outputFlavor>
    <outputDir>${project.basedir}/protocols</outputDir>
    <options>
      <externalTypes>
        <PlcValueType>api 
"github.com/apache/plc4x/plc4go/pkg/api/values"</PlcValueType>
      </externalTypes>
    </options>
  </configuration>
</execution>

Have fun playing with this new feature. Right now, the only difference should 
be in the ADS driver and this should be minimal.

I also updated the maven plugin to allow not only string arguments, but almost 
any type of structs. Hopefully that will reduce the number of times we have to 
release this little tool.

Chris

Reply via email to