EIA-ASCII-ISO encoding

From wiki.bastelbude.grade.de
Revision as of 16:04, 17 September 2019 by Kannix (talk | contribs) (conversion charts)
Jump to: navigation, search

trivia

  • old NC-maschines might use EIA or ISO 'paper-tape' encoding on serial-communication

links

conversion charts

char EIA ASCII ISO remark
(hex) (dec) (hex) (dec) (hex) (dec)

pySerial

ubuntu

prerequisites

  • sudo apt-get install socat
  • sudo apt install python-pip
  • pip install pyserial

virtual null-modem

  • terminal[1]
    • sudo socat PTY,link=/dev/ttyS10 PTY,link=/dev/ttyS11

hack encodings

  • sudo cp usr/lip/python2.7/encodings/hp_roman8.py usr/lip/python2.7/encodings/iso_paper.py
  • edit iso_paper.py as needed ...
""" Python Character Mapping Codec 'ISO_paper tape'
    see https://bastelbude.grade.de/mediawiki/index.php?title=EIA-ASCII-ISO_encoding for details
    valid: 
    [BACKSPACE] [HORIZONTAL TABULATION] [LINE FEED] [CARRIAGE RETURN] [SPACE]
    $ % & ( ) + - . / 
    0 1 2 3 4 5 6 7 8 9 
    : = @ 
    A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
"""#"

import codecs

### Codec APIs

class Codec(codecs.Codec):

    def encode(self,input,errors='strict'):
        return codecs.charmap_encode(input,errors,encoding_map)

    def decode(self,input,errors='strict'):
        return codecs.charmap_decode(input,errors,decoding_map)

class IncrementalEncoder(codecs.IncrementalEncoder):
    def encode(self, input, final=False):
        return codecs.charmap_encode(input,self.errors,encoding_map)[0]

class IncrementalDecoder(codecs.IncrementalDecoder):
    def decode(self, input, final=False):
        return codecs.charmap_decode(input,self.errors,decoding_map)[0]

class StreamWriter(Codec,codecs.StreamWriter):
    pass

class StreamReader(Codec,codecs.StreamReader):
    pass

### encodings module API

def getregentry():
    return codecs.CodecInfo(
        name='iso-paper',
        encode=Codec().encode,
        decode=Codec().decode,
        incrementalencoder=IncrementalEncoder,
        incrementaldecoder=IncrementalDecoder,
        streamwriter=StreamWriter,
        streamreader=StreamReader,
    )

### Decoding Map

decoding_map = codecs.make_identity_dict(range(256))
decoding_map.update({
        0x0008: None, #        needs to be set for encoding_map
        0x000d: None, #        needs to be set for encoding_map
        0x0020: None, #        needs to be set for encoding_map
        0x0025: None, #        needs to be set for encoding_map
        0x0026: None, #        needs to be set for encoding_map
        0x0029: None, #        needs to be set for encoding_map
        0x002c: None, #        needs to be set for encoding_map
        0x002f: None, #        needs to be set for encoding_map
        0x0031: None, #        needs to be set for encoding_map
        0x0032: None, #        needs to be set for encoding_map
        0x0034: None, #        needs to be set for encoding_map
        0x0037: None, #        needs to be set for encoding_map
        0x0038: None, #        needs to be set for encoding_map
        0x003d: None, #        needs to be set for encoding_map
        0x0040: None, #        needs to be set for encoding_map
        0x0043: None, #        needs to be set for encoding_map
        0x0045: None, #        needs to be set for encoding_map
        0x0046: None, #        needs to be set for encoding_map
        0x0049: None, #        needs to be set for encoding_map
        0x004a: None, #        needs to be set for encoding_map
        0x004c: None, #        needs to be set for encoding_map
        0x004f: None, #        needs to be set for encoding_map
        0x0051: None, #        needs to be set for encoding_map
        0x0052: None, #        needs to be set for encoding_map
        0x0054: None, #        needs to be set for encoding_map
        0x0057: None, #        needs to be set for encoding_map
        0x0058: None, #        needs to be set for encoding_map
        0x0088: 0x0008, #        BACKSPACE
        0x0009: 0x0009, #        HORIZONTAL TABULATION
        0x000A: 0x000A, #        LINE FEED
        0x008D: 0x000D, #        CARRIAGE RETURN
        0x00A0: 0x0020, #        SPACE
        0x0024: 0x0024, #        DOLLAR SIGN
        0x00A5: 0x0025, #        PERCENT SIGN
        0x00A6: 0x0026, #        AMPERSAND
        0x0028: 0x0028, #        LEFT PARENTHESIS
        0x00A9: 0x0029, #        RIGHT PARENTHESIS
        0x002B: 0x002B, #        PLUS SIGN
        0x002D: 0x002D, #        HYPHEN-MINUS
        0x002E: 0x002E, #        FULL STOP
        0x00AF: 0x002F, #        SOLIDUS
        0x0030: 0x0030, #        DIGIT ZERO
        0x00B1: 0x0031, #        DIGIT ONE
        0x00B2: 0x0032, #        DIGIT TWO
        0x0033: 0x0033, #        DIGIT THREE
        0x00B4: 0x0034, #        DIGIT FOUR
        0x0035: 0x0035, #        DIGIT FIVE
        0x0036: 0x0036, #        DIGIT SIX
        0x00B7: 0x0037, #        DIGIT SEVEN
        0x00B8: 0x0038, #        DIGIT EIGHT
        0x0039: 0x0039, #        DIGIT NINE
        0x003A: 0x003A, #        COLON
        0x00BD: 0x003D, #        EQUALS SIGN
        0x00C0: 0x0040, #        COMMERCIAL AT
        0x0041: 0x0041, #        LATIN CAPITAL LETTER A
        0x0042: 0x0042, #        LATIN CAPITAL LETTER B
        0x00C3: 0x0043, #        LATIN CAPITAL LETTER C
        0x0044: 0x0044, #        LATIN CAPITAL LETTER D
        0x00C5: 0x0045, #        LATIN CAPITAL LETTER E
        0x00C6: 0x0046, #        LATIN CAPITAL LETTER F
        0x0047: 0x0047, #        LATIN CAPITAL LETTER G
        0x0048: 0x0048, #        LATIN CAPITAL LETTER H
        0x00C9: 0x0049, #        LATIN CAPITAL LETTER I
        0x00CA: 0x004A, #        LATIN CAPITAL LETTER J
        0x004B: 0x004B, #        LATIN CAPITAL LETTER K
        0x00CC: 0x004C, #        LATIN CAPITAL LETTER L
        0x004D: 0x004D, #        LATIN CAPITAL LETTER M
        0x004E: 0x004E, #        LATIN CAPITAL LETTER N
        0x00CF: 0x004F, #        LATIN CAPITAL LETTER O
        0x0050: 0x0050, #        LATIN CAPITAL LETTER P
        0x00D1: 0x0051, #        LATIN CAPITAL LETTER Q
        0x00D2: 0x0052, #        LATIN CAPITAL LETTER R
        0x0053: 0x0053, #        LATIN CAPITAL LETTER S
        0x00D4: 0x0054, #        LATIN CAPITAL LETTER T
        0x0055: 0x0055, #        LATIN CAPITAL LETTER U
        0x0056: 0x0056, #        LATIN CAPITAL LETTER V
        0x00D7: 0x0057, #        LATIN CAPITAL LETTER W
        0x00D8: 0x0058, #        LATIN CAPITAL LETTER X
        0x0059: 0x0059, #        LATIN CAPITAL LETTER Y
        0x005A: 0x005A, #        LATIN CAPITAL LETTER Z
})

### Encoding Map

encoding_map = codecs.make_encoding_map(decoding_map)

run miniterm

  • terminal[2]
    • sudo python -m serial.tools.miniterm --echo --encoding hexlify
  • terminal[3]
    • sudo python -m serial.tools.miniterm --encoding iso-paper

windows

prerequisites

  • ...

virtual null-modem

reference

hack encodings

  • ...

run miniterm

  • ...