Hello Franklin,
Thank you for both emails and summary of changes you made. I admit, you have put a lot of effort into testing.

I think AF_PACKET will serve you well. Let us know how it goes with shorter cycle times. I haven't succeeded to have profinet emulator running locally before, so your comments are throwing new insights in what is possible now. I am also curious how off the shelf PLCs will interact with plc4go, it may be that you are opening completely new doors in IoT universe for go.

Few months ago I have ran into some strange errors with dropped (stuck UDP) packets which led me into investigation of Linux network interface settings. Turns out that there are various queues/strategies which you can configure for interface. They will influence send/recv operations called from user space. I am mentioning this only for future, maybe it will never be needed. If you will run into troubles, please have a look on possible options for sysctl net.core.default_qdisc. The AF_PACKET and mixed traffic on the interface (especially IP), may cause shifts in packets due to priority assigned by kernel, unless you call setsockopt SO_PRIORITY. While my issue was caused by application error, I found that changing qdisc made things only worse! :D

I will try to have a look on plc4go can driver over coming week. Given that it works with driver test suite we already have, I am genuinely fine to merge these once ASF registers your ICLA.
Thank you for your work.

Best,
Łukasz


On 11/28/26 22:54, Franklin Amador wrote:
Hello Łukasz,

A short follow-up with two corrections to my last mail, and the CAN fixes.

Profinet. I wrote that the raw Ethernet transport filters on the EtherType
and UDP. For Profinet it filters on the Profinet EtherType (0x8892) only:
cyclic data, alarms and DCP arrive on that socket. The connection
management (DCE/RPC) doesn't use it at all; it goes over an ordinary UDP
socket through the kernel.

On testing: the driver has been run against the open-source p-net device
in Docker, over a veth pair, for connect, parameter writes, process data
both ways, alarms, release and fragmented calls. I haven't yet run it for
hours at a short cycle time, so I can't say anything about long-term
jitter. That measurement is the next step, and it will tell whether an
AF_XDP transport is worth it.

CAN. The two fixes are now in #2893 (and carried into #2894):

    - A remote (RTR) frame carries its requested length. Before, it always
    went out with DLC 0, and an incoming one returned its padding as data.
    - The SocketCAN transport has an option, socketcan.error-mask, that sets
    CAN_RAW_ERR_FILTER, so error frames reach the driver when asked for.
    The default is off, so the CANopen driver behaves as before. A new
    test on a vcan interface checks that an error frame reaches a socket
    whose mask has its class, and not one with no mask or another class.

Best,

Franklin

On Sat, Nov 28, 2026 at 8:28 AM Franklin Amador <[email protected]>
wrote:

Hello Łukasz,

Thank you, this is very helpful, and no Go reading needed. Here is how the
PRs line up with your points.

*CAN transport.* The Go side follows the same design. All CAN transports
(SocketCAN, and an in-process virtual CAN used by the tests) exchange one
canonical frame, defined in plc4go/spi/transports/can: the Linux can_frame 
layout
with the identifier in network byte order. The driver never sees anything
OS- or adapter-specific. The frame keeps the extended-ID, RTR and
error-frame bits. The CANopen driver ignores those frames rather than
misparsing them, so other CAN protocols can reuse the transport. Your note
made me spot two gaps that I'll fix in the PR: RTR frames need their own
DLC, and SocketCAN only delivers error frames when CAN_RAW_ERR_FILTER is
set. As a follow-up I'd like to add an slcan (Lawicel serial) transport on
the same frame, which should show the abstraction holds for serial adapters
too. CAN FD isn't covered yet, and I'll note that in the description.

*Profinet transport.* The Go driver doesn't go through PCAP. It has its
own pure-Go raw Ethernet transport on Linux AF_PACKET sockets, with the
EtherType and UDP filter compiled into a kernel BPF program, so it skips
the IP stack and libpcap's block-based delivery. That said, I take your
point about jitter. I'll add a measurement of the cyclic send interval at
short cycle times and some low-cost socket tuning (qdisc bypass, priority).
If the numbers show the kernel path is the problem, AF_XDP looks very
doable in Go without cgo (x/sys/unix plus cilium/ebpf). It would be a
separate xdp:// transport delivering the same frame records, so the
driver itself wouldn't change. I'd propose that as a follow-up PR rather
than part of this one.

One more thing: the PRs are stacked. #2892 (generator fixes) comes first,
then #2893 (CANopen), then #2894 (Profinet), which also contains the #2893
commits.

Best, Franklin



On Fri, Nov 27, 2026 at 8:44 PM Łukasz Dywicki <[email protected]>
wrote:

Hello Franklin,
Since I can't read go without crying, I can't comment much about your
contributions, but can share some high level design decisions made with
CAN related drivers.

Because access to CAN bus is not standardized across operating systems
and some adapters offer their own ways (i.e serial protocols), there is
concept of CAN transport which masks this and forms a "canonical" form
of CAN frame. This frame form must be returned from and accepted by
transport. Probably you already have this with virtual can which you
used for testing. On Java side frame missed control bits, which were not
required by CANopen, but may be needed in other use cases.

For Profinet part, in case you run into instabilities with Profinet
driver under go, please consider using other transport than PCAP. Given
that tcpdump is involving linux kernel network stack it introduces
latency which may accumulate over time and lead to jitter beyond device
can tolerate. If you can, and most likely you can do it with go easily,
try then using linux AF_XDP sockets which will let you skip kernel
network stack. It should be fine, as PLC4X already parses whole packet
and have all necessary logic to deal with it.

Best,
Łukasz

On 11/26/26 08:09, Franklin Amador wrote:
Hi everyone,

I'm Franklin Amador from Apiarytech (https://github.com/apiarytech),
from
Honolulu, HI. I opened #2892, #2893 and #2894 two days ago. I sent an
introduction then too, but I wasn't subscribed and it never reached the
list, so here it is again. Sorry for the PRs arriving before the mail.

Who I am. I'm a licensed Electrical Engineer (P.E. in Hawaii and
California, Degree from Cal Poly San Luis Obispo) with over 24 years in
electrical engineering and systems work. Much of it is SCADA: I hold
Ignition and Wonderware Application Server certifications, and
experience
in development and deployment of FactoryTalkView SE & ME editions.  I'm
currently building my own SCADA series of dual licensed products.

What I build, and where plc4go fits. I write industrial automation
software
in Go under the name ApiaryTech. plc4go is how all of it talks to field
devices:

     - *honeycomb *(https://github.com/apiarytech/honeycomb), an IEC
61131-3
     style tag database. Its PLC4X connector binds tags to device
addresses,
     polled or subscribed, maps PLC4X response codes to tag quality, and
     reconnects with backoff. beehive and drone reach devices through it.
     - *beeguard* (https://github.com/apiarytech/beeguard), an ISA-18.2
alarm
     server on honeycomb.
     - *beedance *(https://github.com/apiarytech/beedance), an IEC
61131-3
     toolchain: ST, IL, SFC, LD and FBD, with an interpreter, a bytecode
VM and
     a transpiler to Go.
     - *royaljelly* (https://github.com/apiarytech/royaljelly), the IEC
     61131-3 runtime model in Go, and beebread (
     https://github.com/apiarytech/beebread), the OSCAT libraries
ported to
     Go.
     - On these sit two private repository products: *beehive*, a SCADA
     system and soft PLC built as Go services with an edge node by the
machines,
     and *drone,* a small alarm dialer/data concentrator that reads PLCs
and
     remote I/O and calls people out by SMS and e-mail.

*beehive* and *drone* need Profinet and CANopen devices, and OPC UA with
security, so we built them in plc4go rather than beside it. We'd much
rather they live upstream, tested and maintained with the other drivers,
than in a fork.

The PRs.

     - #2892: fixes to the Go code generator (byte order chosen at run
time,
     optional string lengths, null strings, grandparent links) and two
spi
     fixes. CANopen and Profinet need them; the regenerated EIP, IEC 104
and OPC
     UA code changes only where it had the same shape.
     - #2893: a CANopen driver ported from plc4j, with a pure-Go
SocketCAN
     transport and a virtual CAN one for tests. plc4j's SDO and NMT
driver
     suites run against it. About 3,400 hand-written lines; the rest is
     generated.
     - #2894: a Profinet IO controller: DCP discovery, a GSDML reader,
the
     application relation with cyclic data, alarms, release and DCE/RPC
     fragmentation. It is tested against the open-source p-net device in
Docker.
     About 6,000 hand-written lines; the rest is generated code and the
test
     suite.

Each builds on the one before. I know they are big. If smaller pieces
are
easier to review, tell me how you'd like them cut and I'll split them.

Next, if it's welcome: the OPC UA work in our fork (
https://github.com/apiarytech/plc4x): signed and encrypted secure
channels,
browsing, chunked messages, and fixes to subscriptions and writes. I'd
introduce it here first and send it in small PRs.

How the code was written. I used an AI coding assistant, as each PR
says. I
directed the design, and I reviewed and tested every change against the
suites and the simulated and real devices listed in the PRs. I read your
contribution guide's section on this, and I take the point about review
time; that's why I offer to split and to explain.

Staying. Yes. These drivers run in our products, so we will keep
maintaining them here: answering issues, fixing bugs, and keeping them
in
step with plc4j.

Thanks for reading, and for PLC4X.

Franklin D. Amador ApiaryTech, https://github.com/apiarytech




Reply via email to