package module
Version: v4.0.8 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Feb 8, 2022 License: MIT Imports: 19 Imported by: 0



Twincat ADS Communication using just native go, works on windows and linux




View Source
const ReturnCodeErrorOffset = 0x0700

ReturnCodeErrorOffset Errors begin at this offset


This section is empty.


func ParseUploadSymbolInfoDataTypes

func ParseUploadSymbolInfoDataTypes(data []byte) (datatypes map[string]*SymbolDataType, err error)

func ParseUploadSymbolInfoSymbols

func ParseUploadSymbolInfoSymbols(data []byte, datatypes map[string]*SymbolDataType) (symbols map[string]*Symbol, err error)


type AdsHeaderFlag added in v4.0.8

type AdsHeaderFlag uint16
const (
	AmsTCPPortAmsCmd     AdsHeaderFlag = 0    //0x0000 - Used for ADS commands
	AmsTCPPortClose      AdsHeaderFlag = 1    //0x0001
	AmsTCPPortConnect    AdsHeaderFlag = 4096 // 0x1000
	AmsTcpPortRouterNote AdsHeaderFlag = 4097 // 0x1001
	GetLocalNetID        AdsHeaderFlag = 4098 // 0x1002

type AdsState

type AdsState uint16
const (
	AdsStateInvalid      AdsState = 0
	AdsStateIdle         AdsState = 1
	AdsStateReset        AdsState = 2
	AdsStateInit         AdsState = 3
	AdsStateStart        AdsState = 4
	AdsStateRun          AdsState = 5
	AdsStateStop         AdsState = 6
	AdsStateSaveCfg      AdsState = 7
	AdsStateLoadCfg      AdsState = 8
	AdsStatePowerFailure AdsState = 9
	AdsStatePowerGood    AdsState = 10
	AdsStateError        AdsState = 11
	AdsStateShutdown     AdsState = 12
	AdsStateSuspend      AdsState = 13
	AdsStateResume       AdsState = 14
	AdsStateConfig       AdsState = 15 // System Is In Config Mode
	AdsStateReconfig     AdsState = 16 // System Should Restart In Config Mode
	AdsStateMaxStates    AdsState = 255

type AmsAddress

type AmsAddress struct {
	NetID [6]byte
	Port  uint16

AMSAddress netid and port of device

type CommandID

type CommandID uint16

CommandID Ads Command IDS

const (
	CommandIDInValueID CommandID = iota

type Connection

type Connection struct {
	// contains filtered or unexported fields

func NewConnection

func NewConnection(ctx context.Context, ip string, port int, netid string, amsPort int, localNetID string, localPort int) (conn *Connection, err error)

NewConnection blah blah blah

func (*Connection) AddDeviceNotification

func (conn *Connection) AddDeviceNotification(
	group uint32,
	offset uint32,
	length uint32,
	transmissionMode TransMode,
	maxDelay time.Duration,
	cycleTime time.Duration) (handle uint32, err error)

func (*Connection) AddSymbolNotification

func (conn *Connection) AddSymbolNotification(symbolName string, updateReceiver chan *Update) error

func (*Connection) Close

func (conn *Connection) Close()

Close closes connection and waits for completion

func (*Connection) Connect

func (conn *Connection) Connect(local bool) error

func (*Connection) DeleteDeviceNotification

func (conn *Connection) DeleteDeviceNotification(handle uint32) error

DeleteDeviceNotification does stuff

func (*Connection) DeviceNotification

func (conn *Connection) DeviceNotification(ctx context.Context, in []byte) error

DeviceNotification - ADS command id: 8

func (*Connection) GetHandleByName

func (conn *Connection) GetHandleByName(symbolName string) (handle uint32, err error)

func (*Connection) GetSymbol

func (conn *Connection) GetSymbol(symbolName string) (*Symbol, error)

func (*Connection) GetSymbolUploadInfo

func (conn *Connection) GetSymbolUploadInfo() (uploadInfo SymbolUploadInfo, err error)

func (*Connection) GetUploadSymbolInfoDataTypes

func (conn *Connection) GetUploadSymbolInfoDataTypes(length uint32) (data []byte, err error)

func (*Connection) GetUploadSymbolInfoSymbols

func (conn *Connection) GetUploadSymbolInfoSymbols(length uint32) (data []byte, err error)

func (*Connection) OpenPort added in v4.0.8

func (conn *Connection) OpenPort(port uint16) (*AmsAddress, error)

func (*Connection) Read

func (conn *Connection) Read(group uint32, offset uint32, length uint32) (data []byte, err error)

func (*Connection) ReadDeviceInfo

func (conn *Connection) ReadDeviceInfo() (response DeviceInfo, err error)

func (*Connection) ReadFromSymbol

func (conn *Connection) ReadFromSymbol(symbolName string) (string, error)

func (*Connection) ReadState

func (conn *Connection) ReadState() (response states, err error)

func (*Connection) Write

func (conn *Connection) Write(group uint32, offset uint32, data []byte) error

Write - ADS command id: 3

func (*Connection) WriteRead

func (conn *Connection) WriteRead(group uint32, offset uint32, readLength uint32, send []byte) (data []byte, err error)

func (*Connection) WriteToSymbol

func (conn *Connection) WriteToSymbol(symbolName string, value string) error

type DataType added in v4.0.8

type DataType uint32
const (
	ADST_VOID DataType = 0
	/// <summary>Integer 16 Bit</summary>
	ADST_INT16 DataType = 2
	/// <summary>Integer 32 Bit</summary>
	ADST_INT32 DataType = 3
	/// <summary>Real (32 Bit)</summary>
	ADST_REAL32 DataType = 4
	/// <summary>Real 64 Bit</summary>
	ADST_REAL64 DataType = 5
	/// <summary>Integer 8 Bit</summary>
	ADST_INT8 DataType = 16 // 0x00000010
	/// <summary>Unsigned integer 8 Bit</summary>
	ADST_UINT8 DataType = 17 // 0x00000011
	/// <summary>Unsigned integer 16 Bit</summary>
	ADST_UINT16 DataType = 18 // 0x00000012
	/// <summary>Unsigned Integer 32 Bit</summary>
	ADST_UINT32 DataType = 19 // 0x00000013
	/// <summary>LONG Integer 64 Bit</summary>
	ADST_INT64 DataType = 20 // 0x00000014
	/// <summary>Unsigned Long integer 64 Bit</summary>
	ADST_UINT64 DataType = 21 // 0x00000015
	/// <summary>STRING</summary>
	ADST_STRING DataType = 30 // 0x0000001E
	/// <summary>WSTRING</summary>
	ADST_WSTRING DataType = 31 // 0x0000001F
	/// <summary>ADS REAL80</summary>
	ADST_REAL80 DataType = 32 // 0x00000020
	/// <summary>ADS BIT</summary>
	ADST_BIT DataType = 33 // 0x00000021
	/// <summary>Internal Only</summary>
	ADST_MAXTYPES DataType = 34 // 0x00000022
	/// <summary>Blob</summary>
	ADST_BIGTYPE DataType = 65 // 0x00000041

type DataTypeAttribute added in v4.0.8

type DataTypeAttribute struct {
	Name  string
	Value string
	// contains filtered or unexported fields

type DataTypeFlag added in v4.0.8

type DataTypeFlag uint32

func (DataTypeFlag) HasAligned added in v4.0.8

func (flagsValue DataTypeFlag) HasAligned() bool

func (DataTypeFlag) HasAnySizeArray added in v4.0.8

func (flagsValue DataTypeFlag) HasAnySizeArray() bool

func (DataTypeFlag) HasAttributes added in v4.0.8

func (flagsValue DataTypeFlag) HasAttributes() bool

func (DataTypeFlag) HasBitValues added in v4.0.8

func (flagsValue DataTypeFlag) HasBitValues() bool

func (DataTypeFlag) HasCopyMask added in v4.0.8

func (flagsValue DataTypeFlag) HasCopyMask() bool

func (DataTypeFlag) HasDataItem added in v4.0.8

func (flagsValue DataTypeFlag) HasDataItem() bool

func (DataTypeFlag) HasDataType added in v4.0.8

func (flagsValue DataTypeFlag) HasDataType() bool

func (DataTypeFlag) HasEnumInfos added in v4.0.8

func (flagsValue DataTypeFlag) HasEnumInfos() bool

func (DataTypeFlag) HasIgnorePersist added in v4.0.8

func (flagsValue DataTypeFlag) HasIgnorePersist() bool

func (DataTypeFlag) HasInitOnReset added in v4.0.8

func (flagsValue DataTypeFlag) HasInitOnReset() bool

func (DataTypeFlag) HasMethodDeref added in v4.0.8

func (flagsValue DataTypeFlag) HasMethodDeref() bool

func (DataTypeFlag) HasMethodInfos added in v4.0.8

func (flagsValue DataTypeFlag) HasMethodInfos() bool

func (DataTypeFlag) HasOversample added in v4.0.8

func (flagsValue DataTypeFlag) HasOversample() bool

func (DataTypeFlag) HasPersistent added in v4.0.8

func (flagsValue DataTypeFlag) HasPersistent() bool

func (DataTypeFlag) HasPersistentDataType added in v4.0.8

func (flagsValue DataTypeFlag) HasPersistentDataType() bool

func (DataTypeFlag) HasPropItem added in v4.0.8

func (flagsValue DataTypeFlag) HasPropItem() bool

func (DataTypeFlag) HasReferenceTo added in v4.0.8

func (flagsValue DataTypeFlag) HasReferenceTo() bool

func (DataTypeFlag) HasSpLevels added in v4.0.8

func (flagsValue DataTypeFlag) HasSpLevels() bool

func (DataTypeFlag) HasSpare1 added in v4.0.8

func (flagsValue DataTypeFlag) HasSpare1() bool

func (DataTypeFlag) HasSpare2 added in v4.0.8

func (flagsValue DataTypeFlag) HasSpare2() bool

func (DataTypeFlag) HasStatic added in v4.0.8

func (flagsValue DataTypeFlag) HasStatic() bool

func (DataTypeFlag) HasTComInterfacePtr added in v4.0.8

func (flagsValue DataTypeFlag) HasTComInterfacePtr() bool

func (DataTypeFlag) HasTypeGuid added in v4.0.8

func (flagsValue DataTypeFlag) HasTypeGuid() bool

type DeviceInfo

type DeviceInfo struct {
	Major      uint8
	Minor      uint8
	Version    uint16
	DeviceName [16]byte

DeviceInfo connected device info

type EnumInfo added in v4.0.8

type EnumInfo struct {
	Name  string
	Value []byte
	// contains filtered or unexported fields

type Group

type Group uint32

Group reserved index groups

const (
	GroupSymbolTab   Group = 0xf000
	GroupSymbolName  Group = 0xf001
	GroupSymbolValue Group = 0xf002

	GroupSymbolHandleByName  Group = 0xF003
	GroupSymbolValueByName   Group = 0xF004
	GroupSymbolValueByHandle Group = 0xF005
	GroupSymbolReleaseHandle Group = 0xF006
	GroupSymbolInfoByName    Group = 0xF007
	GroupSymbolVersion       Group = 0xF008
	GroupSymbolInfoByNameEx  Group = 0xF009

	GroupSymbolDownload       Group = 0xF00A
	GroupSymbolUpload         Group = 0xF00B
	GroupSymbolUploadInfo     Group = 0xF00C
	GroupSymbolDownload2      Group = 0xF00D
	GroupSymbolDataTypeUpload Group = 0xF00E
	GroupSymbolUploadInfo2    Group = 0xF00F

	GroupSymbolNotification Group = 0xf010 // notification of named handle

	GroupSumupRead                     Group = 0xF080
	GroupSumupWrite                    Group = 0xF081
	GroupSumupReadWrite                Group = 0xF082
	GroupSumupReadEx                   Group = 0xF083
	GroupSumupReadEx2                  Group = 0xF084
	GroupSumupAddDeviceNotification    Group = 0xF085
	GroupSumupDeleteDeviceNotification Group = 0xF086

	GroupIoImageRwib   Group = 0xF020 // read/write input byte(s)
	GroupIoImageRwix   Group = 0xF021 // read/write input bit
	GroupIoImageRisize Group = 0xF025 // read input size (in byte)
	GroupIoImageRwob   Group = 0xF030 // read/write output byte(s)
	GroupIoImageRwox   Group = 0xF031 // read/write output bit
	GroupIoImageCleari Group = 0xF040 // write inputs to null
	GroupIoImageClearo Group = 0xF050 // write outputs to null
	GroupIoImageRwiob  Group = 0xF060 // read input and write output byte(s)

	GroupDeviceData Group = 0xF100 // state, name, etc...

type NotificationSample added in v4.0.8

type NotificationSample struct {
	Handle uint32
	Size   uint32

type NotificationStream added in v4.0.8

type NotificationStream struct {
	Length uint32
	Stamps uint32

type Offset

type Offset uint32
const (
	OffsetDeviceDataAdsState    Offset = 0x0000 // ads state of device
	OffsetDeviceDataDeviceState Offset = 0x0002 // device state

type Port

type Port uint32

Port default twincat ports

const (
	PortLogger    Port = 100
	PortR0Rtime   Port = 200
	PortR0Trace   Port = (PortR0Rtime + 90)
	PortR0Io      Port = 300
	PortR0Sps     Port = 400
	PortR0Nc      Port = 500
	PortR0Isg     Port = 550
	PortR0Pcs     Port = 600
	PortR0Plc     Port = 801
	PortR0PlcRts1 Port = 801
	PortR0PlcRts2 Port = 811
	PortR0PlcRts3 Port = 821
	PortR0PlcRts4 Port = 831
	PortR0PlcTc3  Port = 851

type ReturnCode

type ReturnCode uint32

ReturnCode ADS Return codes

const (
	ReturnCodeNoErrors ReturnCode = 0x00

	ReturnCodeDeviceError                 ReturnCode = (0x00 + ReturnCodeErrorOffset) //Error Class < Device Error >
	ReturnCodeDeviceServiceNotSupported   ReturnCode = (0x01 + ReturnCodeErrorOffset) //Service Is Not Supported By Server
	ReturnCodeDeviceInvalidGroup          ReturnCode = (0x02 + ReturnCodeErrorOffset) //Invalid Indexgroup
	ReturnCodeDeviceInvalidOffset         ReturnCode = (0x03 + ReturnCodeErrorOffset) //Invalid Indexoffset
	ReturnCodeDeviceInvalidAccess         ReturnCode = (0x04 + ReturnCodeErrorOffset) //Reading/Writing Not Permitted
	ReturnCodeDeviceInvalidSize           ReturnCode = (0x05 + ReturnCodeErrorOffset) //Parameter Size Not Correct
	ReturnCodeDeviceInvalidData           ReturnCode = (0x06 + ReturnCodeErrorOffset) //Invalid Parameter Value(S)
	ReturnCodeDeviceNotReady              ReturnCode = (0x07 + ReturnCodeErrorOffset) //Device Is Not In A Ready State
	ReturnCodeDeviceBusy                  ReturnCode = (0x08 + ReturnCodeErrorOffset) //DeviceIs Busy
	ReturnCodeDeviceInvalidContext        ReturnCode = (0x09 + ReturnCodeErrorOffset) //InvalidContext (Must Be Inwindows)
	ReturnCodeDeviceNoMemory              ReturnCode = (0x0a + ReturnCodeErrorOffset) //OutOf Memory
	ReturnCodeDeviceInvalidParam          ReturnCode = (0x0b + ReturnCodeErrorOffset) //InvalidParameter Value(S)
	ReturnCodeDeviceNotFound              ReturnCode = (0x0c + ReturnCodeErrorOffset) //NotFound (Files, ...)
	ReturnCodeDeviceSyntax                ReturnCode = (0x0d + ReturnCodeErrorOffset) //SyntaxError In Comand Or File
	ReturnCodeDeviceIncompatible          ReturnCode = (0x0e + ReturnCodeErrorOffset) //ObjectsDo Not Match
	ReturnCodeDeviceExists                ReturnCode = (0x0f + ReturnCodeErrorOffset) //ObjectAlready Exists
	ReturnCodeDeviceSymbolNoFound         ReturnCode = (0x10 + ReturnCodeErrorOffset) //SymbolNot Found
	ReturnCodeDeviceSymbolVersionInvalid  ReturnCode = (0x11 + ReturnCodeErrorOffset) //SymbolVersion Invalid
	ReturnCodeDeviceInvalidState          ReturnCode = (0x12 + ReturnCodeErrorOffset) //ServerIs In Invalid State
	ReturnCodeDeviceTransModeNotSupported ReturnCode = (0x13 + ReturnCodeErrorOffset) //AdstransmodeNot Supported
	ReturnCodeDeviceNotifyHandleInvalid   ReturnCode = (0x14 + ReturnCodeErrorOffset) //NotificationHandle Is Invalid
	ReturnCodeDeviceClientUnknown         ReturnCode = (0x15 + ReturnCodeErrorOffset) //NotificationClient Not Registered
	ReturnCodeDeviceNoMoreHandles         ReturnCode = (0x16 + ReturnCodeErrorOffset) //NoMore Notification Handles
	ReturnCodeDeviceInvalidWatchSize      ReturnCode = (0x17 + ReturnCodeErrorOffset) //SizeFor Watch To Big
	ReturnCodeDeviceNotInitialized        ReturnCode = (0x18 + ReturnCodeErrorOffset) //DeviceNot Initialized
	ReturnCodeDeviceTimeout               ReturnCode = (0x19 + ReturnCodeErrorOffset) //DeviceHas A Timeout
	ReturnCodeDeviceNoInterface           ReturnCode = (0x1a + ReturnCodeErrorOffset) //QueryInterface Failed
	ReturnCodeDeviceInvalidInterface      ReturnCode = (0x1b + ReturnCodeErrorOffset) //WrongInterface Required
	ReturnCodeDeviceInvalidClsID          ReturnCode = (0x1c + ReturnCodeErrorOffset) //ClassId Is Invalid
	ReturnCodeDeviceInvalidObjID          ReturnCode = (0x1d + ReturnCodeErrorOffset) //ObjectId Is Invalid
	ReturnCodeDevicePending               ReturnCode = (0x1e + ReturnCodeErrorOffset) //RequestIs Pending
	ReturnCodeDeviceAborted               ReturnCode = (0x1f + ReturnCodeErrorOffset) //RequestIs Aborted
	ReturnCodeDeviceWarning               ReturnCode = (0x20 + ReturnCodeErrorOffset) //SignalWarning
	ReturnCodeDeviceInvalidArrayIndex     ReturnCode = (0x21 + ReturnCodeErrorOffset) //InvalidArray Index
	ReturnCodeDeviceSymbolNotActive       ReturnCode = (0x22 + ReturnCodeErrorOffset) //SymbolNot Active -> Release Handle And Try Again
	ReturnCodeDeviceAccessDenied          ReturnCode = (0x23 + ReturnCodeErrorOffset) //AccessDenied
	ReturnCodeDeviceLicenseNotFound       ReturnCode = (0x24 + ReturnCodeErrorOffset) //NoLicense Found
	ReturnCodeDeviceLicenseExpired        ReturnCode = (0x25 + ReturnCodeErrorOffset) //LicenseExpired
	ReturnCodeDeviceLicenseExceeded       ReturnCode = (0x26 + ReturnCodeErrorOffset) //LicenseExceeded
	ReturnCodeDeviceLicenseInvalid        ReturnCode = (0x27 + ReturnCodeErrorOffset) //LicenseInvalid
	ReturnCodeDeviceLicenseSystemID       ReturnCode = (0x28 + ReturnCodeErrorOffset) //LicenseInvalid System Id
	ReturnCodeDeviceLicenseNoTimeLimit    ReturnCode = (0x29 + ReturnCodeErrorOffset) //LicenseNot Time Limited
	ReturnCodeDeviceLicenseFutureIssue    ReturnCode = (0x2a + ReturnCodeErrorOffset) //LicenseIssue Time In The Future
	ReturnCodeDeviceLicenseTimeToLong     ReturnCode = (0x2b + ReturnCodeErrorOffset) //LicenseTime Period To Long
	ReturnCodeDeviceException             ReturnCode = (0x2c + ReturnCodeErrorOffset) //ExceptionIn Device Specific Code
	ReturnCodeDeviceLicenseDuplicated     ReturnCode = (0x2d + ReturnCodeErrorOffset) //LicenseFile Read Twice
	ReturnCodeDeviceSignatureInvalid      ReturnCode = (0x2e + ReturnCodeErrorOffset) //InvalidSignature
	ReturnCodeDeviceCertificateInvalid    ReturnCode = (0x2f + ReturnCodeErrorOffset) //PublicKey Certificate
	ReturnCodeClientError                 ReturnCode = (0x40 + ReturnCodeErrorOffset) //ErrorClass < Client Error >
	ReturnCodeClientInvalidParameter      ReturnCode = (0x41 + ReturnCodeErrorOffset) //InvalidParameter At Service Call
	ReturnCodeClientListEmpty             ReturnCode = (0x42 + ReturnCodeErrorOffset) //PollingList	Is Empty
	ReturnCodeClientVarUsed               ReturnCode = (0x43 + ReturnCodeErrorOffset) //VarConnection Already In Use
	ReturnCodeClientDuplicateInvokeID     ReturnCode = (0x44 + ReturnCodeErrorOffset) //InvokeId In Use
	ReturnCodeClientSyncTimeout           ReturnCode = (0x45 + ReturnCodeErrorOffset) //TimeoutElapsed
	ReturnCodeClientW32Error              ReturnCode = (0x46 + ReturnCodeErrorOffset) //ErrorIn Win32 Subsystem
	ReturnCodeClientTimeoutInvalid        ReturnCode = (0x47 + ReturnCodeErrorOffset) //? ReturnCodeClientPortNot Open ReturnCode = (0x48 + ReturnCodeErrorOffset)          //AdsDll
	ReturnCodeClientNoAmsAddress          ReturnCode = (0x49 + ReturnCodeErrorOffset) //AdsDll
	ReturnCodeClientSyncInternal          ReturnCode = (0x50 + ReturnCodeErrorOffset) //InternalError In Ads Sync
	ReturnCodeClientAddHash               ReturnCode = (0x51 + ReturnCodeErrorOffset) //HashTable Overflow
	ReturnCodeClientRemoveHash            ReturnCode = (0x52 + ReturnCodeErrorOffset) //KeyNot Found In Hash Table
	ReturnCodeClientNoMoreSymbols         ReturnCode = (0x53 + ReturnCodeErrorOffset) //NoMore Symbols In Cache
	ReturnCodeClientSyncResponseInvalid   ReturnCode = (0x54 + ReturnCodeErrorOffset) //InvalidResponse Received
	ReturnCodeClientSyncPortLocked        ReturnCode = (0x55 + ReturnCodeErrorOffset) //SyncPort Is Locked

type StampHeader added in v4.0.8

type StampHeader struct {
	Timestamp uint64
	Samples   uint32

type Symbol

type Symbol struct {
	FullName          string
	LastUpdateTime    time.Time
	MinUpdateInterval time.Duration
	Name              string
	DataType          *SymbolDataType
	Comment           string
	Handle            uint32
	Changed           bool

	Value string
	Valid bool

	Notification chan<- *Update

	Parent   *Symbol
	Children map[string]*Symbol
	// contains filtered or unexported fields

func (*Symbol) GetJSON

func (symbol *Symbol) GetJSON(onlyChanged bool) string

GetJSON (onlyChanged bool) string

type SymbolDataType added in v4.0.8

type SymbolDataType struct {
	Name    string
	Comment string
	Type    string

	GUID       string
	Attributes []DataTypeAttribute
	EnumInfos  []EnumInfo
	Children   map[string]*SymbolDataType
	// contains filtered or unexported fields

type SymbolUploadInfo

type SymbolUploadInfo struct {
	SymbolCount    uint32
	SymbolLength   uint32
	DataTypeCount  uint32
	DataTypeLength uint32
	ExtraCount     uint32
	ExtraLength    uint32

type TransMode

type TransMode uint32

TransMode transmission mode for notifications

const (
	TransModeNoTransmission TransMode = iota

type Update added in v4.0.6

type Update struct {
	Variable  string
	Value     string
	TimeStamp time.Time

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL