Difference between revisions of "EIA-ASCII-ISO encoding"

From wiki.bastelbude.grade.de
Jump to: navigation, search
(conversion charts)
(hack encodings)
Line 141: Line 141:
 
* <pre>sudo cp usr/lip/python2.7/encodings/hp_roman8.py usr/lip/python2.7/encodings/iso_paper.py</pre>
 
* <pre>sudo cp usr/lip/python2.7/encodings/hp_roman8.py usr/lip/python2.7/encodings/iso_paper.py</pre>
 
* edit <b>iso_paper.py</b> as needed ...
 
* edit <b>iso_paper.py</b> as needed ...
 +
<code>
 +
""" 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)
 +
 +
</code>
  
 
=== run miniterm ===
 
=== run miniterm ===

Revision as of 13:11, 17 September 2019

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)
BS 2A 42 08 8 88 136 BACKSPACE
HT 33 51 09 9 09 9 HORIZONTAL TABULATION
LF 0A 10 0A 10 LINE FEED EOB in ASCII (ISO)
CR 80 128 0D 13 8D 141 CARRIAGE RETURN EOB in EIA
10 16 20 32 A0 160 SPACE
$ 80 128 24 36 24 36 DOLLAR SIGN EOB in EIA
% 5B 91 25 37 A5 165 PERCENT SIGN EOR – Rewind Stop in ASCII
& 0E 14 26 38 A6 166 AMPERSAND
( 7C 124 28 40 28 40 LEFT PARENTHESIS
) 71 113 29 41 A9 169 RIGHT PARENTHESIS
70 112 2B 43 2B 43 PLUS SIGN
, 3B 59 2C 44 COMMA
. 6B 107 2E 46 2E 46 FULL STOP
/ 31 49 2F 47 AF 175 SOLIDUS
0 20 32 30 48 30 48 DIGIT ZERO
1 01 1 31 49 B1 177 DIGIT ONE
2 02 2 32 50 B2 178 DIGIT TWO
3 13 19 33 51 33 51 DIGIT THREE
4 04 4 34 52 B4 180 DIGIT FOUR
5 15 21 35 53 35 53 DIGIT FIVE
6 16 22 36 54 36 54 DIGIT SIX
7 07 7 37 55 B7 183 DIGIT SEVEN
8 08 8 38 56 B8 184 DIGIT EIGHT
9 19 25 39 57 39 57 DIGIT NINE
: 10 16 3A 58 3A 58 COLON
= 0B 11 3D 61 BD 189 EQUALS SIGN
@ 6D 109 40 64 C0 192 COMMERCIAL AT
A 61 97 41 65 41 65 LATIN CAPITAL LETTER A
B 62 98 42 66 42 66 LATIN CAPITAL LETTER B
C 73 115 43 67 C3 195 LATIN CAPITAL LETTER C
D 64 100 44 68 44 68 LATIN CAPITAL LETTER D
E 75 117 45 69 C5 197 LATIN CAPITAL LETTER E
F 76 118 46 70 C6 198 LATIN CAPITAL LETTER F
G 67 103 47 71 47 71 LATIN CAPITAL LETTER G
H 68 104 48 72 48 72 LATIN CAPITAL LETTER H
I 79 121 49 73 C9 201 LATIN CAPITAL LETTER I
J 51 81 4A 74 CA 202 LATIN CAPITAL LETTER J
K 52 82 4B 75 4B 75 LATIN CAPITAL LETTER K
L 43 67 4C 76 CC 204 LATIN CAPITAL LETTER L
M 54 84 4D 77 4D 77 LATIN CAPITAL LETTER M
N 45 69 4E 78 4E 78 LATIN CAPITAL LETTER N
O 46 70 4F 79 CF 207 LATIN CAPITAL LETTER O
P 57 87 50 80 50 80 LATIN CAPITAL LETTER P
Q 58 88 51 81 D1 209 LATIN CAPITAL LETTER Q
R 49 73 52 82 D2 210 LATIN CAPITAL LETTER R
S 32 50 53 83 53 83 LATIN CAPITAL LETTER S
T 23 35 54 84 D4 212 LATIN CAPITAL LETTER T
U 34 52 55 85 55 85 LATIN CAPITAL LETTER U
V 25 37 56 86 56 86 LATIN CAPITAL LETTER V
W 26 38 57 87 D7 215 LATIN CAPITAL LETTER W
X 37 55 58 88 D8 216 LATIN CAPITAL LETTER X
Y 38 56 59 89 59 89 LATIN CAPITAL LETTER Y
Z 29 41 5A 90 5A 90 LATIN CAPITAL LETTER Z

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

      1. 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
      1. 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,
   )
      1. 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

})

      1. 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

  • ...