Class: ToyopucDevice

ToyopucDevice

Provides methods and properties for connecting to a Toyopuc PLC and mapping a memory 'block' that can be written or read.

Members


host :string

Gets/sets the server name of the Toyopuc PLC. Changes made to this property when connected will not take affect until the next open.

Type:
  • string
Since:
  • 0.1 (WAT 1.4)

<readonly> isConnected :bool

Returns if there is currently an active connection to a Toyopuc PLC.

Type:
  • bool
Since:
  • 0.1 (WAT 1.4)

port :number

Gets/sets the port to connect to on the Toyopuc PLC. Typically does not need to be changed from the default. Changes made to this property when connected will not take affect until the next open.

Type:
  • number
Since:
  • 0.1 (WAT 1.4)

Methods


close()

Closes an open connection to a device.

Since:
  • 0.1 (WAT 1.4)

createBlock(id, addr, len)

Creates a map to a block of memory in the Toyopuc PLC. Functions can be performed on the block to read and/or write data.

Parameters:
Name Type Description
id string

The name of the area to map the block from. See toyopuc.ToyopucBlock#area.

addr number

The starting address of the block in the area.

len number

The size of the block.

Since:
  • 0.1 (WAT 1.4)
Returns:

An object to interface with the memory block

Type
toyopuc.ToyopucBlock

createGroup(registers [, name])

Creates a group of registers from arbitrary locations in memory in the Toyopuc PLC. The group is used to efficiently read all registers at the same time. Typically, related registers (e.g. those used on one application page) would be grouped together since they would typically be read at the same time.

Parameters:
Name Type Argument Default Description
registers Object

An object where the property names are the names that will be assigned to the each register. The value of each property can either be a string, which is the address of the value in the PLC, or an object that provides the address and the type of the data (plus any extra type-specific options). The string variant will automatically choose a type based on the address, whereas the object variant allows finer control over how the value will be interpreted.

Properties
Name Type Description
regName string | Object

The address, or description object for the register

Properties
Name Type Argument Default Description
address string

The address of the register, in the form: [program]{areaID}{address}[.bit]. E.g.: 1K200, 2D501, 2D501.5, U600C, GX,GYF123, EB18ABC

Properties
Name Type Description
program string

Must be either 1, 2, or 3 when the areaID is one of K, V, T,C, L, X,Y, M, S, N, R, D, or B. Should not be present for other areas.

areaID string

One of K, V, T,C, L, X,Y, M, S, N, R, D, B, EK, EV, ET,EC, EL, EX,EY, EM, ES, H, U, GX,GY, GM, or EB

address string

The 1-5 digit index inside the area

bit string

The bit address inside the word. Can only be specified when the area contains word registers (S, N, R, D, B, ES, EN, H, U, EB)

type string <optional>
UINT

When the address refers to a word, this specifies how the bytes will be interpreted (all values are little-endian). Valid values are: UINT - A 2-byte unsigned value, INT - A 2-byte signed value, UDINT - A 4-byte unsigned value, DINT - A 4-byte signed value, REAL - A 4-byte IEEE floating point number, BCD - A binary coded decimal value.

bcd Object

When the type is BCD, this provides fine control over how the value is coded

Properties
Name Type Argument Default Description
size number <optional>
1

The number of words used, must be either 1 or 2.

sign string <optional>
None

How to decode the sign. Either None (N) - No sign, Bit (B) - The most significant bit is used as the sign, Nibble (F) - The most significant nibble is used (0 for + and F for -).

name string <optional>
""

An optional name to assign to the group. If specified, the group will be available as a property of the device with the given name.

Since:
  • 1.0 (WAT 2.3)
Returns:

An object to interface with the group of registers

Type
toyopuc.ToyopucGroup
Example
var tp = $wat.load('toyopuc')[0];
var dev = tp.createDevice('192.168.0.100');
var myGroup = dev.createGroup({
  bitReg: '1K200',
  wordReg: '2DC80',
  bitInWord: '2D500.1',
  bcdValue: {
    address: '2D701',
    type: 'BCD',
    bcd: {
      size: 2,
      sign: 'F'
    }
  },
  signedValue: {
    address: 'U7FF0',
    type: 'INT'
  },
  floatValue: {
    address: 'EB18010',
    type: 'REAL'
  }
});
dev.connected.connect(function() {
  myGroup.read();
});
myGroup.readSuccess.connect(function() {
  console.log('Word reg is: ' + myGroup.regs.wordReg.value);
});
myGroup.regs.floatValue.valueChanged.connect(function(val) {
  console.log('Float value changed to: ' + val);
});
dev.open();

deleteBlock(block)

Deletes a previously created block. Blocks are deleted automatically when the device is deleted. However, if blocks are dynamically created without deleting the device, they must also be deleted using this function when they are no longer required to prevent a memory leak.

Parameters:
Name Type Description
block toyopuc.ToyopucBlock

The block to delete.

Since:
  • 0.1 (WAT 1.4)

deleteGroup(group)

Deletes a previously created group. Groups are deleted automatically when the device is deleted. However, if groups are dynamically created without deleting the device, they must also be deleted using this function when they are no longer required to prevent a memory leak.

Parameters:
Name Type Description
group toyopuc.ToyopucGroup

The group to delete.

Since:
  • 1.0 (WAT 2.3)

open()

Starts establishing a connection to a device.

Since:
  • 0.1 (WAT 1.4)
Returns:

True if the connection attempt was successfully started. Does not indicate if a connection has been established. Use connected to determine when the connection is established.

Type
bool

Events


connected

Emitted when a connection to a device has been successfully established.

Since:
  • 0.1 (WAT 1.4)

disconnected

Emitted when a connection to a device has been lost.

Since:
  • 0.1 (WAT 1.4)

error

Emitted when an error occurs while connecting to a device.

Parameters:
Name Type Description
error string

A string describing the error that occurred.

Since:
  • 0.1 (WAT 1.4)

isConnectedChanged

Emitted when the value of isConnected changes.

Since:
  • 1.0 (WAT 2.3)