Home Contents | # magstripe.encode | Magstripe | Core4 Lua Event System

## SYNOPSIS

rawdata = magstripe.encode(tracknr, data)

## DESCRIPTION

This function takes an ASCII encoded string and turns it into raw magstripe data bitsthe raw magnetic stripe bits according to the ISO standard encoding for track tracknr.

The encoder checks if the passed string already includes the start, stop and checksum characters. If not, these characters are calculated and automatically added to the result data.

The function fails (returns nil) if the resulting binary data would exceed 256 bytes. It also fails if one of the characters in the source string is not encodable to the requested standard.

This is the reverse function of magstripe.decode().

## RETURN VALUE

On success, returns a string with the encoded data, including the start, end and checksum bits. On failure, returns nil.

## SEE ALSO

magstripe.decode