root/juggler/branches/2.2/modules/gadgeteer/tools/elexol/Command.py

Revision 18481, 9.6 kB (checked in by aronb, 3 years ago)

- Adding Elexol Ether24 I/O Qt test GUI.

  • Property svn:eol-style set to native
Line 
1 import struct
2
3 # Write Values
4 WritePortA = 'A'
5 WritePortB = 'B'
6 WritePortC = 'C'
7 # Read Values
8 ReadPortA = ('a',  2, '1cB')
9 ReadPortB = ('b',  2, '1cB')
10 ReadPortC = ('c',  2, '1cB')
11 # Write Direction Register
12 WriteDirectionA = '!A'
13 WriteDirectionB = '!B'
14 WriteDirectionC = '!C'
15 # Identify IO24 Units
16 Find = ('IO24', 12, '4c8B')
17 ReadDirectionA = ('!a', 3, "2cB")
18 ReadDirectionB = ('!b', 3, "2cB")
19 ReadDirectionC = ('!c', 3, "2cB")
20 # Write Pull Up Register
21 WritePullUpA = '@A'
22 WritePullUpB = '@B'
23 WritePullUpC = '@C'
24 # Write Threshold Register
25 WriteThresholdA = '#A'
26 WriteThresholdB = '#B'
27 WriteThresholdC = '#C'
28 # Write Schmitt Trigger Register
29 WriteSchmittTriggerA = '$A'
30 WriteSchmittTriggerB = '$B'
31 WriteSchmittTriggerC = '$C'
32 # Read Pull Up Register
33 ReadPullUpA = ('@a', 3, '2cB')
34 ReadPullUpB = ('@b', 3, '2cB')
35 ReadPullUpC = ('@c', 3, '2cB')
36 # Read Threshold Register
37 ReadThresholdA = ('#a', 3, '2cB')
38 ReadThresholdB = ('#b', 3, '2cB')
39 ReadThresholdC = ('#c', 3, '2cB')
40 # Read Schmitt Trigger Register
41 ReadSchmittTriggerA = ('$a', 3, '2cB')
42 ReadSchmittTriggerB = ('$b', 3, '2cB')
43 ReadSchmittTriggerC = ('$c', 3, '2cB')
44
45 def ReadEEPROMWord(address):
46    return (struct.pack('2c3B', '\'', 'R', address, 0, 0), 4)
47
48 def WriteEEPROMWord(address, msb, lsb):
49    return struct.pack('2c3B', '\'', 'W', address, msb, lsb)
50
51 def EraseEEPROMWord(address):
52    return struct.pack('2c3B', '\'', 'E', address, 0xAA, 0x55)
53
54 """
55 Three registers for each port control the six different input modes.
56
57 Threshold Register - If bit is high then the threshold voltage is 1.4V and if low 2.5V.
58 Schmitt Trigger Register - Overrides the threshold register when the corresponding bit is low, enabling the Schmitt Trigger input state.
59 Pull-Up register - Enables the corresponding pull-up resistor when the bit is low.
60
61 The default power-up state for all registers is all high bit (TTL Input, No Pull-Up) unless the EEPROM has been programmed to set them up differently.
62 """
63
64
65
66 """
67 Command | Command   |Bytes|      Data       |            Function                   | Response |  Response  |  Response Data
68  ASCII  |   Hex     |     |                 |                                       |  Bytes   | Identifier |
69    A    | 0x41      |  2  |   Port_Value    |          Write Port A                 |    -     |     -      |       -
70    B    | 0x42      |  2  |   Port_Value    |          Write Port B                 |    -     |     -      |       -
71    C    | 0x43      |  2  |   Port_Value    |          Write Port C                 |    -     |     -      |       -
72    a    | 0x61      |  1  |       -         |           Read Port A                 |    2     |     A      |   PortA_Value
73    b    | 0x62      |  1  |       -         |           Read Port B                 |    2     |     B      |   PortB_Value
74    c    | 0x63      |  1  |       -         |           Read Port C                 |    2     |     C      |   PortC_Value
75    !A   | 0x21 0x41 |  3  |    Direction    |    Write Port A Direction Register    |    -     |     -      |       -
76    !B   | 0x21 0x42 |  3  |    Direction    |    Write Port B Direction Register    |    -     |     -      |       -
77    !C   | 0x21 0x43 |  3  |    Direction    |    Write Port C Direction Register    |    -     |     -      |       -
78   IO24  | 0x49 0x4F |  4  |        -        |        Identify IO24 Units            |    12    |    IO24    | 6 Byte MAC Address
79         | 0x32 0x34 |     |                 |                                       |          |            | 2 Byte FW Version
80    !a   | 0x21 0x61 |  2  |        -        |    Read Port A Direction Register     |    3     |     !A     |   Direction
81    !b   | 0x21 0x62 |  2  |        -        |    Read Port B Direction Register     |    3     |     !B     |   Direction
82    !c   | 0x21 0x63 |  2  |        -        |    Read Port C Direction Register     |    3     |     !C     |   Direction
83    @A   | 0x40 0x41 |  3  |     Pull_Up     |     Write Port A Pull Up Register     |    -     |     -      |       -
84    @B   | 0x40 0x42 |  3  |     Pull_Up     |     Write Port B Pull Up Register     |    -     |     -      |       -
85    @C   | 0x40 0x43 |  3  |     Pull_Up     |     Write Port C Pull Up Register     |    -     |     -      |       -
86    #A   | 0x23 0x41 |  3  |    Threshold    |    Write Port A Threshold Register    |    -     |     -      |       -
87    #B   | 0x23 0x42 |  3  |    Threshold    |    Write Port B Threshold Register    |    -     |     -      |       -
88    #C   | 0x23 0x43 |  3  |    Threshold    |    Write Port C Threshold Register    |    -     |     -      |       -
89    $A   | 0x24 0x41 |  3  |     Schmitt     | Write Port A Schmitt Trigger Register |    -     |     -      |       -
90    $B   | 0x24 0x42 |  3  |     Schmitt     | Write Port B Schmitt Trigger Register |    -     |     -      |       -
91    $C   | 0x24 0x43 |  3  |     Schmitt     | Write Port C Schmitt Trigger Register |    -     |     -      |       -
92    @a   | 0x40 0x61 |  2  |        -        |     Read Port A Pull Up Register      |    3     |     @A     |    Pull_Up
93    @b   | 0x40 0x62 |  2  |        -        |     Read Port B Pull Up Register      |    3     |     @B     |    Pull_Up
94    @c   | 0x40 0x63 |  2  |        -        |     Read Port C Pull Up Register      |    3     |     @C     |    Pull_Up
95    #a   | 0x23 0x61 |  2  |        -        |    Read Port A Threshold Register     |    3     |     #A     |   Threshold
96    #b   | 0x23 0x62 |  2  |        -        |    Read Port B Threshold Register     |    3     |     #B     |   Threshold
97    #c   | 0x23 0x63 |  2  |        -        |    Read Port C Threshold Register     |    3     |     #C     |   Threshold
98    $a   | 0x24 0x61 |  2  |        -        | Read Port A Schmitt Trigger Register  |    3     |     $A     |    Schmitt
99    $b   | 0x24 0x62 |  2  |        -        | Read Port B Schmitt Trigger Register  |    3     |     $B     |    Schmitt
100    $c   | 0x24 0x63 |  2  |        -        | Read Port C Schmitt Trigger Register  |    3     |     $C     |    Schmitt
101    'R   | 0x27 0x52 |  5  |  Address NU NU  |         Read EEPROM Word              |    4     |     R      | Address MSB LSB
102    'W   | 0x27 0x57 |  5  | Address MSB LSB |         Write EEPROM Word             |    -     |     -      |       -
103    'E   | 0x27 0x45 |  5  | Address $AA $55 |         Erase EEPROM Word             |    -     |     -      |       -
104    '0   | 0x27 0x30 |  5  |    NU NU NU     |        Write Disable EEPROM           |    -     |     -      |       -
105    '1   | 0x27 0x31 |  5  |   NU $AA $55    |        Write Enable EEPROM            |    -     |     -      |       -
106    '@   | 0x27 0x52 |  5  |   NU $AA $55    |            Reset Module               |    -     |     -      |       -
107    `    | 0x60      |  2  |      Byte       |      Echo Byte back to sender         |    2     |     `      |      Byte
108    *    | 0x2A      |  1  |        -        |      Send Space back to sender        |    1     |  'Space'   |       -
109    %    | 0x25      |  1  |        -        |           Send Host Data              |    16    |     %      | 3 byte IO24 Serial
110         |           |     |                 |                                       |          |            | 4 byte Sender IP
111         |           |     |                 |                                       |          |            | 6 byte Sender MAC
112         |           |     |                 |                                       |          |            | 2 byte Sender Port
113 """
114
115 """
116 Address MSB Function                      LSB Function
117 =========================================================================
118 0-4   | Reserved (Unwritable)          |  Reserved (Unwritable)
119 5     | Control Bits 2                 |  Control Bits 1
120 6     | Fixed IP Address Byte 2        |  Fixed IP Address Byte 1
121 7     | Fixed IP Address Byte 4        |  Fixed IP Address Byte 3
122 8     | Preset Port A Value            |  Preset Port A Direction
123 9     | Preset Port A Pull up          |  Preset Port A Threshold
124 10    | Preset Port B Direction        |  Preset Port A Schmitt Trigger
125 11    | Preset Port B Threshold        |  Preset Port B Value
126 12    | Preset Port B Schmitt Trigger  |  Preset Port B Pull up
127 13    | Preset Port C Value            |  Preset Port C Direction
128 14    | Preset Port C Pull up          |  Preset Port C Threshold
129 15    | Reserved for Future Use        |  Preset Port C Schmitt Trigger
130 16    | AutoScan Port B Mask           |  AutoScan Port A Mask
131 17    | AutoScan Filter Count          |  AutoScan Port C Mask
132 18    | AutoScan Scan Rate MSB         |  AutoScan Scan Rate LSB
133 19    | AutoScan Target MAC Address 2  |  AutoScan Target MAC Address 1
134 20    | AutoScan Target MAC Address 4  |  AutoScan Target MAC Address 3
135 21    | AutoScan Target MAC Address 6  |  AutoScan Target MAC Address 5
136 22    | AutoScan Target IP Address 2   |  AutoScan Target IP Address 1
137 23    | AutoScan Target IP Address 4   |  AutoScan Target IP Address 3
138 24    | AutoScan Target Port MSB       |  AutoScan Target Port LSB
139 25-47 | Reserved for Future Use        |
140 48-63 | For your own use               |
141 """
142
143 """
144 Control Bits 1
145   Fixed IP function     - 1
146      0 - Enable
147      1 - Disable
148   Preset Port function  - 2
149      0 - Reads 8-15 into Port Registers
150      1 - Nothing
151   AutoScan function     - 4
152      0 - Enable
153      1 - Disable
154
155   Value to write = 255 - (Enable Fixed IP | Enable Preset Port | Enable AutoScan)
156 """
157
158 def getLineBit(lineNum):
159    return pow(2, (lineNum - 1))
160
161 WriteDisableEEPROM = struct.pack('2c3B', '\'', '0', 0, 0, 0)
162 WriteEnableEEPROM = struct.pack('2c3B', '\'', '1', 0, 0xAA, 0x55)
163 ResetModule = struct.pack('2c3B', '\'', '@', 0, 0xAA, 0x55)
164 EchoByte = ('`', 2)
165 EchoSpace = ('*', 1)
166 SendHostData = ('%', 16, '1c3B4B6B1h')
Note: See TracBrowser for help on using the browser.