Just a little suggestion ... all ADS versions support an ADS_READDEVICEINFO 
request that returns 
the device name (16 bytes) plus a version struct (major, minor, build) ... I 
would use that to 
find out if it's TC3 or TC2 instead of relying on a failure to detect.

Chris



Levent Sağıroğlu <[email protected]> schrieb am Mittwoch, 25. November 2026 
um 21:21:

> Hi Łukasz,
> 
> Thank you - this sent me to measure rather than guess. I have TwinCAT 2
> hardware
> here, so I ran plc4j 1.0.0 against one of the controllers. Reporting it in
> case
> it is useful to you or to anyone who picks this up.
> 
> Three things stand between plc4j and TwinCAT 2.
> 
> The online version is treated as mandatory, so the driver never finishes
> connecting:
> 
>   Error reading online version number. Got: ADSERR_DEVICE_SYMBOLNOTFOUND
>     at
> AdsTcpConnection.lambda$doConnectHandshake$2(AdsTcpConnection.java:215)
> 
> TwinCAT 2 has no TwinCAT_SystemInfoVarList._AppInfo.OnlineChangeCnt symbol.
> If
> that one place records the absence instead of failing - and the invalidation
> subscription then skips that symbol - the connection is established, both
> tables
> upload, and a symbolic read works.
> 
> Global variables are rejected before the request is sent:
> 
>   PlcInvalidTagException: .RSAYAC invalid
>     at AdsTagHandler.parseTag(AdsTagHandler.java:37)
> 
> SymbolicAdsTag's pattern requires a leading letter or underscore, and a
> TwinCAT 2
> global is addressed as ".RSAYAC". 32 of the 38 symbols on this controller
> look
> like that; the device is never contacted.
> 
> Symbol lookup is case sensitive. The device reports every identifier in
> upper
> case, whatever case it was declared in:
> 
>   MAIN.TN_SAYAC.Q -> code=OK            value=false
>   main.tn_sayac.q -> code=INVALID_ADDRESS
> 
> IEC 61131-3 makes identifiers case insensitive, and Beckhoff's own TE1200
> rule
> SA0029 says so explicitly. Case-insensitive resolution is the next change I
> have
> queued for plc4go, once #2891 is in.
> 
> On the missing primitive types that TwinCat2SymbolReader2 pre-seeds the
> table
> for: they did not block this read. MAIN.TN_SAYAC.Q is a BOOL member of a TON
> instance and resolved from the uploaded table without help. The controller
> is a
> small one, so I would not generalise from it. TwinCAT 2 does name its
> primitives
> differently - the table reports INT16 where TwinCAT 3 says INT - which is
> presumably why your reader special-cases it.
> 
> You said you have no hardware to confirm against, so rather than ask you to
> run
> anything, here is the run itself. The program walks the driver into each of
> the
> three obstacles and past the first one, and the log reads top to bottom:
> 
>   https://gist.github.com/LeventSA/70639bb02956b0b8ce72fd3007da88a7
> 
> The one-file patch is in there as well. It changes nothing unless a system
> property is set, so the first step in the log is the released behaviour.
> 
> I should be clear about what I am not offering: I work in Go, and my Java
> here
> went as far as running this against the released artifacts. I am not in a
> position to carry a TwinCAT 2 change through plc4j. But the hardware is
> here, so
> if someone takes it on, I am glad to test patches against real devices and
> report back.
> 
> Thank you also for the TC/BSD links. I only have TwinCAT 2 here, and showing
> that the change does not regress TwinCAT 3 is the one thing missing from the
> plc4go PR (#2891).
> 
> Best regards,
> Levent
> 
> Łukasz Dywicki <[email protected]>, 25 Kas 2026 Çar, 19:21 tarihinde şunu
> yazdı:
> 
> > Hello Levent,
> > I had some attempts to get java flavor of ADS driver working with TC2
> > devices. I can not confirm that with real hardware, but some of
> > workarounds [1] I attempted also involved pre-populating symbol table
> > with primitive types for TC2. The TC3 devices declare them, the TC2 omit
> > them.
> > I used for a bit an ancient CX9001 which worked with this code, but I
> > didn't really dive into complex types it could offer. Also, I noticed
> > that some old TC2 I/O modules been hanging connection with even an
> > attempt to retrieve symbol table.
> >  From brief look into your code I think you got it covered pretty well.
> > If you look for a TC3 compatible device, you can actually do most
> > trivial connection test with TC/BSD hosted within VM. I used it to test
> > lookup logic. Please follow first Jakob Sagatowski blog [3]. This makes
> > secure connection, I described how to disable firewall [4], in order to
> > have plain connection.
> > Good luck with further work!
> >
> > Best regards,
> > Łukasz
> >
> > [1]
> >
> > https://github.com/ConnectorIO/connectorio-addons/blob/master/bundles/org.connectorio.addons.binding.amsads/src/main/java/org/connectorio/addons/binding/amsads/internal/symbol/reader/TwinCat2SymbolReader2.java#L163L197
> > [2]
> >
> > https://github.com/ConnectorIO/connectorio-addons/blob/master/bundles/org.connectorio.addons.binding.amsads/src/main/java/org/connectorio/addons/binding/amsads/internal/symbol/reader/TwinCat2SymbolReader2.java#L66L71
> > [3] https://alltwincat.com/2021/12/13/tc-bsd-in-a-virtual-machine/
> > [4] https://dywicki.pl/2023/10/twincat-bsd-with-insecure-ads-connection/
> >
> >
> > On 11/24/26 14:45, Levent Sağıroğlu wrote:
> > > Hi Sebastian, thanks - that is the right question to ask, and it is the
> > one
> > > I
> > > was most careful about.
> > >
> > > On protocol compatibility: so far everything I have seen says the wire
> > > protocol is the same. The model generated from ads.mspec parses the
> > symbol
> > > table, the data type table and the upload-info of a TwinCAT 2.11
> > controller
> > > without a single change to the spec. What differs is not the format but
> > the
> > > content and the conventions around it:
> > >
> > > - the device names primitive types the way TcAdsDef.h does (INT16,
> > UINT32)
> > >    rather than the IEC names TwinCAT 3 reports (INT, UDINT)
> > > - it stores symbol and member names upper case, while the program
> > declares
> > >    them in mixed case, so a lookup that is exact fails
> > > - it answers the online-version read with an error result code and an
> > empty
> > >    payload instead of a version, and the driver parses the payload
> > without
> > >    looking at the result code, which is the EOF that ends the connection
> > >    before anything else is tried
> > >
> > > So nothing below the driver changes: no .mspec change, no regenerated
> > code,
> > > nothing outside plc4go/internal/ads. That also answers your second point
> > -
> > > plc4j, plc4c, plc4py and plc4net are not touched by any of this, and
> > cannot
> > > be, since the spec they are generated from is untouched.
> > >
> > > On not breaking TwinCAT 3, the honest answer first: I do not have a
> > TwinCAT
> > > 3
> > > device, so I cannot test that myself. What I can say is how each change
> > is
> > > shaped so TwinCAT 3 keeps its current path:
> > >
> > > - name lookup tries the exact name first and only falls back to a
> > >    case-insensitive match when that fails, so a TwinCAT 3 device, whose
> > names
> > >    already match exactly, never reaches the fallback
> > > - a primitive type is synthesised only when the name is absent from the
> > >    uploaded data type table; TwinCAT 3 uploads those entries, so the
> > table
> > >    wins and the synthesis is dead code there
> > > - the online-version handling only changes what happens when the device
> > >    answers with an error result, which today is not checked at all
> > >
> > > That is reasoning, not a measurement, and I would rather have the
> > > measurement. If someone on the list has a TwinCAT 3 device and can run
> > the
> > > third PR against it, I would be glad of it - and I am happy to prepare
> > > whatever makes that easy to do.
> > >
> > > The first PR is up: https://github.com/apache/plc4x/pull/2889 - a browse
> > > query without a dot panics the driver. One condition, with a test.
> > Nothing
> > > in
> > > it distinguishes TwinCAT versions; the query never reaches the device.
> > >
> > > Thanks,
> > > Levent
> > >
> > > Sebastian Rühl via dev <[email protected]>, 24 Kas 2026 Sal, 10:49
> > > tarihinde şunu yazdı:
> > >
> > >> Hi Levent,
> > >>
> > >> welcome to the list.
> > >>
> > >> One thing that jumps to my mind: We should carefully check if TwinCat 2
> > >> and TwinCat 3 are protocol compatible.
> > >> So as long as your changes don't break TwinCat3 is should be fine but we
> > >> should check that.
> > >> Luckly the spec is open and there should be Documentation by Beckhoff
> > >> which could help us judge such things.
> > >> Also keep in mind: the X stands for any language so that means a change
> > >> must not break any of the languages.
> > >>
> > >> Sebastian
> > >>
> > >> On 2026-11-23 23:10 UTC Levent Sağıroğlu wrote:
> > >>> Hi everyone, I'm Levent (LeventSA on GitHub) from NetYazilim in Turkey.
> > >> I've
> > >>> been writing software for over thirty years, and the part I enjoy most
> > >> has
> > >>> always been getting a computer to talk to a piece of hardware and
> > making
> > >>> something useful out of it. I'm building a data collection system for a
> > >>> factory, reading its Beckhoff controllers with plc4go.
> > >>>
> > >>> What drew me to PLC4X is how much it covers from one design: more than
> > a
> > >>> dozen protocols behind a single API, five language bindings, one .mspec
> > >> per
> > >>> protocol to generate them from. We read Siemens and Modbus in the same
> > >>> plant,
> > >>> so that one API is why I chose plc4go - and the model generated from
> > >>> ads.mspec parsed the TwinCAT 2 tables unchanged, so nothing below
> > touches
> > >>> the
> > >>> spec.
> > >>>
> > >>> The ADS driver assumes TwinCAT 3 and cannot connect to a TwinCAT 2
> > >> device at
> > >>> all. That is #1424, open since February 2024, and the three symptoms
> > >>> reported
> > >>> there are all accounted for in what I have: INT16 where the driver
> > >> expects
> > >>> INT, symbol names that only match in upper case, and a nil pointer
> > >> panic. I
> > >>> have it working against three TwinCAT 2.11 controllers, from a CX9020
> > >> with
> > >>> 38
> > >>> symbols to a plant PC with over 170,000 readable tags, and would like
> > to
> > >>> contribute that back. Introducing it here first, as the contributing
> > >> guide
> > >>> asks.
> > >>>
> > >>> It is not one change but three, so I would send three small PRs against
> > >>> develop, smallest first, each with its own measurements:
> > >>>
> > >>> - a browse query with no dot in it panics the driver (a one character
> > >> fix)
> > >>> - a reply larger than the peek buffer is classified as a fatal
> > transport
> > >>>    error, which kills the connection on any device with a large symbol
> > >> table
> > >>> - TwinCAT 2 support itself, in plc4go/internal/ads only, with no .mspec
> > >>>    change and no regenerated code
> > >>>
> > >>> There is a fourth change behind the tag count above: a browse of "*"
> > >> lists
> > >>> the symbols a device reports and "**" expands them into readable tags.
> > >> That
> > >>> one is a feature rather than a fix, so I'd rather offer it separately
> > >> once
> > >>> the three above are settled.
> > >>>
> > >>> Unless someone objects, I'll open the first one later this week and let
> > >> it
> > >>> be
> > >>> reviewed before sending the next.
> > >>>
> > >>> I can follow these through, and the controllers are in a running plant
> > I
> > >>> have
> > >>> access to. #1424 says TwinCAT 2 has gone uncovered mostly for lack of
> > >> such a
> > >>> device, so if anything else in the ADS driver needs checking against
> > real
> > >>> TwinCAT 2 hardware, I'm happy to run it.
> > >>>
> > >>> One note on process, as the contributing guide requires. English is not
> > >> my
> > >>> first language and I learned it mostly from reading technical
> > >> documentation,
> > >>> so I used Claude as an assistant here, for the language and for parts
> > of
> > >> the
> > >>> work, as I will also disclose in each PR. The design decisions, the
> > >>> measurements on real hardware and the validation against a reference
> > tool
> > >>> are
> > >>> mine, and I have reviewed every line I am proposing. Plain, direct
> > review
> > >>> comments are welcome. Indirect phrasing is harder for me to read
> > >> correctly,
> > >>> so please just say what needs to change.
> > >>>
> > >>> Thanks,
> > >>> Levent
> > >>>
> > >>
> > >
> >
> >
>

Reply via email to