Class: ToyopucBlock

ToyopucBlock

Provides methods reading and writing to a mapped block of memory in a Toyopuc PLC.

The mapped block from the PLC is stored in a local cache. All data operations operate on the cache rather than directly on the PLC memory. The cache can be updated by calling read and flushed back to the PLC by calling write. This allows the application to determine when to interact directly with the PLC since these operations can be expensive.

Members


<readonly> addr :number

Gets the starting address of the mapped block.

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

<readonly> area :string

Gets the area that the block is mapped from.

Valid values are:

  • K (not yet supported)
  • V (not yet supported)
  • TC (not yet supported)
  • L (not yet supported)
  • XY (not yet supported)
  • M (not yet supported)
  • S (not yet supported)
  • N (not yet supported)
  • R (not yet supported)
  • D (not yet supported)
  • B (not yet supported)
  • EK (not yet supported)
  • EV (not yet supported)
  • ETEC (not yet supported)
  • EL (not yet supported)
  • EXEY (not yet supported)
  • EM (not yet supported)
  • ES
  • EN
  • H
  • U
  • GXGY (not yet supported)
  • GM (not yet supported)
  • EB0
  • EB1
Type:
  • string
Since:
  • 0.1 (WAT 1.4)

<readonly> size :number

Gets the size of the mapped block.

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

Methods


at(index)

Returns a 'word' from the specified index. The size of 'word' is depended upon the type of area the mapping is in. For example, in area EB0, the word size is defined as 16-bits. This function reads the cache of the mapped memory block and so may not represent what is currently set in the PLC. In order to update the cache, call read.

Parameters:
Name Type Description
index number

The offset from the start of the block, in words, to return the word from.

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

read( [index] [, len])

Attempts to read a portion of the mapped block from the PLC to update the local cache.

Parameters:
Name Type Argument Default Description
index number <optional>
0

The offset from the start of the block, in bytes, to read.

len number <optional>
0

The length of the portion to read, in bytes. If 0, everything up to the end of the block is read.

Since:
  • 0.1 (WAT 1.4)
Returns:

Indicates if the read attempt was successfully started. Does not indicate if the local cache has been updated, use updated for that.

Type
bool

setString(str, index)

Writes a string to the specified offset in the block (encoded as ASCII). This function writes to the cache of the mapped memory block and does not write directly to the PLC. In order to flush the cache back to the PLC call write.

Parameters:
Name Type Description
str string

The string to write.

index number

The offset from the start of the block, in bytes, to start writing the string at.

Since:
  • 0.1 (WAT 1.4)

toString(index, len)

Returns a portion of the block as a string (decoded as ASCII). This function reads the cache of the mapped memory block and so may not represent what is currently set in the PLC. In order to update the cache, call read.

Parameters:
Name Type Description
index number

The offset from the start of the block, in bytes, to start reading the string from.

len number

The length of the string the read, in bytes.

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

write( [index] [, len])

Attempts to write a portion of the local cache to the PLC.

Parameters:
Name Type Argument Default Description
index number <optional>
0

The offset from the start of the block, in bytes, to write.

len number <optional>
0

The length of the portion to write, in bytes. If 0, everything up to the end of the block is written.

Since:
  • 0.1 (WAT 1.4)
Returns:

Indicates if the write attempt was successfully started. Does not indicate that the PLC has been successfully updated.

Type
bool

Events


error

Emitted when an error occurs when attempting a read or write operation.

Parameters:
Name Type Description
error string

A string describing the error that occurred.

Since:
  • 0.1 (WAT 1.4)

updated

Emitted when a portion of the block has been updated.

Parameters:
Name Type Description
addr number

The offset of the updated portion.

len number

The length of the updated portion.

Since:
  • 0.1 (WAT 1.4)