Options
All
  • Public
  • Public/Protected
  • All
Menu

Class TcContext

Class responsible for creating the connection, mapping the types and symbols over the TwinCAT's ADS layer. Its purpose is to serve as the entry point for the tc-context Library.

Creation of a context is done through the TcContext.create() static method, due to the asynchronous nature of creation.

const { TcContext } = require('tc-context');

TcContext.create().then(context => {
    //.....
    await context.kill();
})

Hierarchy

Index

Constructors

Private constructor

  • new TcContext(settings: TcComSettings, onSourceChange?: undefined | (() => void), debug?: boolean): TcContext
  • Internal constructor, which creates and binds all the Components of TcContext, used by TcContext.create()

    Parameters

    • settings: TcComSettings

      Settings used for communicating over ADS. Definition of connection settings can be found at ads-client library

    • Optional onSourceChange: undefined | (() => void)

      Callback which is issued when Code Change is detected. If none is specified, the the TcContext.reinitialize function is bound to it

    • Default value debug: boolean = false

      If enabled, all components of TcContext will produce debug information

    Returns TcContext

Events

on

Accessors

$

  • get $(): {}

COM

symbols

  • Access to the Registry, which stores the Symbol Map, generated based on the TwinCAT PLC Data and the Type data gathered by the TcContext.types Component

    Returns TcSymbolRegistry

types

  • Access to the Registry, which stores all the TwinCAT Type Data, pulled from the PLC, and which is used for Symbol generation

    Returns TcTypeRegistry

Methods

Private __initialize

addListener

  • addListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

emit

  • emit(eventName: string | symbol, e: TcEvent): boolean
  • Emits an event of eventName with data e and if parent is present will propagated that event to it, unless stopped

    Parameters

    • eventName: string | symbol

      The event name to emit

    • e: TcEvent

      The Data associated with this event

    Returns boolean

    • True if the event had listeners, false otherwise.

eventNames

  • eventNames(): Array<string | symbol>
  • Returns Array<string | symbol>

getMaxListeners

  • getMaxListeners(): number

kill

  • Function responsible for explicitly killing TcContext, rendering it unusable, unless TcContext.reinitialize() is called afterwards, which will reconnect and rebuild a new TcContext with previously passed settings

    const { TcContext } = require('tc-context');
    
    TcContext.create().then(context => {
    
        await context.kill()
        //context is no longer usable afterwards
    
    })

    NOTE: Even if the function throws an exception, the context will still be rendered unusable

    throws

    TcComUnsubscribeException - Failure unsubscribing from TwinCAT Symbol

    throws

    TcComDisconnectException - Failure disconnecting from ADS Target

    Returns Promise<TcContext>

    • The killed TcContext, which is no longer usable

listenerCount

  • listenerCount(type: string | symbol): number
  • Parameters

    • type: string | symbol

    Returns number

listeners

  • listeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

off

  • off(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

once

  • once(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

prependListener

  • prependListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

prependOnceListener

  • prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

rawListeners

  • rawListeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

reinitialize

removeAllListeners

  • removeAllListeners(event?: string | symbol): this
  • Parameters

    • Optional event: string | symbol

    Returns this

removeListener

  • removeListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

setMaxListeners

  • setMaxListeners(n: number): this
  • Parameters

    • n: number

    Returns this

Static create

  • create(settings: TcComSettings, onSourceChange?: undefined | (() => void), debug?: boolean): Promise<TcContext>
  • Function responsible for the creation of TcContext, as well as initializing all of its components

    const { TcContext } = require('tc-context');
    
    TcContext.create().then(context => {
        //.....
    })
    throws

    TcComBusyException - Connection is already created and TcCom is busy

    throws

    TcComConnectException - Failure establishing ADS Communication

    throws

    TcComChangeDetectionException - Failure enabling Code Change monitoring

    throws

    TcComTypeQueryException - Failure querying Type Data from TwinCAT

    throws

    TcComSymbolQueryException - Failure querying Symbol Data from TwinCAT

    throws

    TcComIsInvalidException - Attempting to use an Invalidated TcCom Object

    Parameters

    • settings: TcComSettings

      Settings used for communicating over ADS. Definition of connection settings can be found at ads-client library

    • Optional onSourceChange: undefined | (() => void)

      Callback which is issued when Code Change is detected. If none is specified, the the TcContext.reinitialize function is bound to it

    • Default value debug: boolean = false

      If enabled, all components of TcContext will produce debug information

    Returns Promise<TcContext>

    • The newly created, connected and mapped TcContext

Generated using TypeDoc