ADS.Codepage (yaads v0.1.0)

Copy Markdown View Source

The code page of the strings of one byte to a character a TwinCAT system has: its PLC's STRINGs, the names and comments of its symbols and types, and the strings of its system service and router, such as its host name, routes and adapters. Windows-1252 unless told otherwise, with codepage: to ADS.Client, ADS.Discovery and the mix tasks, as Beckhoff's own libraries read them on Western Windows; a system on Windows of another language has that one's.

Codepagex converts them. yaads has these compiled in: :ascii, :iso_8859_1, and Windows' code pages of one byte to a character, :windows_874 and :windows_1250 to :windows_1258. The application adds others in its config, by Codepagex's aliases or names, and recompiles yaads (mix deps.compile yaads --force):

# config/config.exs
config :yaads, :codepages, [:windows_932, "VENDORS/MICSFT/WINDOWS/CP949"]

An encoding Codepagex itself has, as configured for the application, is taken too.

What comes out is UTF-8, always: a byte the code page has no character for is "\uFFFD".

Summary

Types

t()

An alias of Codepagex's, such as :windows_1251, or a full name.

Functions

The code pages compiled into yaads, by Codepagex's full names.

The code page, if yaads or Codepagex has it; else an ArgumentError that says how to add it.

A string from the code page, in UTF-8.

Windows-1252.

A string in the code page; ArgumentError for one with characters it doesn't have.

Types

t()

@type t() :: atom() | String.t()

An alias of Codepagex's, such as :windows_1251, or a full name.

Functions

available()

@spec available() :: [String.t()]

The code pages compiled into yaads, by Codepagex's full names.

check!(codepage)

@spec check!(t()) :: t()

The code page, if yaads or Codepagex has it; else an ArgumentError that says how to add it.

iex> ADS.Codepage.check!(:windows_1251)
:windows_1251

decode(bytes, codepage \\ :windows_1252)

@spec decode(binary(), t()) :: String.t()

A string from the code page, in UTF-8.

iex> ADS.Codepage.decode(<<"Gr", 0xFC, 0xDF, "e ", 0x80>>)
"Grüße €"
iex> ADS.Codepage.decode(<<0xC0, 0xE1, 0x98>>, :windows_1251)
"Аб�"

default()

@spec default() :: t()

Windows-1252.

encode!(string, codepage \\ :windows_1252)

@spec encode!(String.t(), t()) :: binary()

A string in the code page; ArgumentError for one with characters it doesn't have.

iex> ADS.Codepage.encode!("Grüße €")
<<"Gr", 0xFC, 0xDF, "e ", 0x80>>