PeterZerlauth/TwinCAT
Beckhoff TwinCAT ads server for zig
A lightweight ADS (Automation Device Specification) server written in Zig, capable of communicating with Beckhoff TwinCAT systems over the AMS/TCP protocol.
This project is perfect for:
ReadDeviceInfo
Read
Write
ReadWrite
ReadState
WriteControl
AddDeviceNotification
/ DeleteDeviceNotification
48898
OnRead
OnWrite
OnReadWrite
Here’s a simple example of how to start the ADS server using Zig:
const std = @import("std");
const Server = @import("server.zig").Server;
const ads = @import("ads.zig");
pub fn main() !void {
var allocator = std.heap.page_allocator;
var server = Server.init(allocator, 10000);
// Override the OnRead callback here:
server.OnRead = customOnRead;
try server.start();
defer server.stop();
}
fn OnRead(IndexGroup: u32, IndexOffset: u32, readData: []u8) !ads.ErrorCode {
std.log.info("Custom OnRead: IndexGroup={}, IndexOffset={}, len={}", .{IndexGroup, IndexOffset, readData.len});
if (IndexGroup == 0x4020 and IndexOffset == 0) {
if (readData.len >= 4) {
const value: u32 = 0x12345678;
std.mem.writeIntLittle(u32, readData[0..4], value);
return ads.ErrorCode.NoError;
} else {
return ads.ErrorCode.DeviceInvalidSize;
}
}
These features may be added in future releases. Contributions and feature requests are welcome!
return ads.ErrorCode.DeviceInvalidParameter;