-
Notifications
You must be signed in to change notification settings - Fork 6
/
eeprom.py
163 lines (137 loc) · 4.3 KB
/
eeprom.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
from pyEtherCAT import MasterEtherCAT
import time
import os
import psutil
def CRC(data):
crc = 0xFF
for i in range(len(data)):
crc ^= data[i]
for j in range(8):
if(crc & 0x80):
crc = (crc << 1) ^ 0x07
else:
crc = (crc << 1)
return (0xFF & crc)
def main():
cat = MasterEtherCAT.MasterEtherCAT("eth0")
cat.ADP = 0x000000
"""
cat.APRD(IDX=0x00,ADP=cat.ADP,ADO=0x0502,DATA=[0x00,0x00])
time.sleep(0.05)
(DATA,WKC) = cat.socket_read()
print(DATA)
print('DATA:{:04x}'.format(DATA[0] | DATA[1]<<8))
"""
# EEPROM Setup
print("EEPROM Setup")
cat.EEPROM_SetUp(0x0000)
# EEPROM ゼロクリア
print("EEPROM Zero Clear")
for i in range(0x010):
cat.EEPROM_AddrSet(i)
cat.EEPROM_Write(0)
cat.EEPROM_Stasus(enable=0x01, command=0x02)
time.sleep(0.01)
"""
# EEPROM データ書き込み
#800E00CC8813f000000000800000
print("EEPROM Deta Write")
d = [0x0180,0xFF00,0x0000,0x00FF,0x0000,0x0000,0x0000,0x0065]
for i in range(8):
cat.EEPROM_AddrSet(i)
cat.EEPROM_Write(d[i])
cat.EEPROM_Stasus(enable=0x01,command=0x02)
time.sleep(0.01)
time.sleep(0.01)
"""
# EEPROM データ書き込み
# 800100FF0000FF
print("EEPROM Deta Write")
d = [0x80, 0x01, 0x00, 0xFF, 0x00, 0x00, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
# d = [0x80, 0x00, 0x00, 0xCC, 0x88, 0x13, 0xf0,
# 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00]
buf = [d[0] | d[1] << 8, d[2] | d[3] << 8, d[4] | d[5] << 8, d[6] |
d[7] << 8, d[8] | d[9] << 8, d[10] | d[11] << 8, d[12] | d[13] << 8]
for i in range(7):
cat.EEPROM_AddrSet(i)
cat.EEPROM_Write(buf[i])
cat.EEPROM_Stasus(enable=0x01, command=0x02)
time.sleep(0.01)
crc = CRC(d)
cat.EEPROM_AddrSet(7)
cat.EEPROM_Write(crc)
cat.EEPROM_Stasus(enable=0x01, command=0x02)
time.sleep(0.01)
print('CRC:{:04x}'.format(crc))
# ベンダーID [0x00000A68]
cat.EEPROM_AddrSet(0x0008)
cat.EEPROM_Write(0x0A68)
cat.EEPROM_Stasus(enable=0x01, command=0x02)
time.sleep(0.01)
cat.EEPROM_AddrSet(0x0009)
cat.EEPROM_Write(0x0000)
cat.EEPROM_Stasus(enable=0x01, command=0x02)
time.sleep(0.01)
# プロダクト コード [0x00000001]
cat.EEPROM_AddrSet(0x000A)
cat.EEPROM_Write(0x0001)
cat.EEPROM_Stasus(enable=0x01, command=0x02)
time.sleep(0.01)
cat.EEPROM_AddrSet(0x000B)
cat.EEPROM_Write(0x0000)
cat.EEPROM_Stasus(enable=0x01, command=0x02)
time.sleep(0.01)
# リビジョン ナンバー [0x00000001]
cat.EEPROM_AddrSet(0x000C)
cat.EEPROM_Write(0x0001)
cat.EEPROM_Stasus(enable=0x01, command=0x02)
time.sleep(0.01)
cat.EEPROM_AddrSet(0x000D)
cat.EEPROM_Write(0x0000)
cat.EEPROM_Stasus(enable=0x01, command=0x02)
time.sleep(0.01)
# シリアル ナンバー [0x00000001]
cat.EEPROM_AddrSet(0x000E)
cat.EEPROM_Write(0x0001)
cat.EEPROM_Stasus(enable=0x01, command=0x02)
time.sleep(0.01)
cat.EEPROM_AddrSet(0x000F)
cat.EEPROM_Write(0x0000)
cat.EEPROM_Stasus(enable=0x01, command=0x02)
time.sleep(0.01)
# シリアル ナンバー [0x00000001]
cat.EEPROM_AddrSet(0x003E)
cat.EEPROM_Write(0x0001)
cat.EEPROM_Stasus(enable=0x01, command=0x02)
time.sleep(0.01)
"""
Category_Header = 30
Category_Data = 0x0001
Category_Size
cat.EEPROM_AddrSet(0x0040)
cat.EEPROM_Write(0x0000)
cat.EEPROM_AddrSet(0x0041)
cat.EEPROM_Write(0x0000)
cat.EEPROM_AddrSet(0x0042)
cat.EEPROM_Write(0x0000)
"""
# EEPROM モード切替
cat.EEPROM_Stasus(enable=0x01, command=0x02)
time.sleep(0.01)
# EEPROM 読み出し
for i in range(0x0010):
cat.EEPROM_AddrSet(i)
cat.EEPROM_Stasus(enable=0x00, command=0x01)
(DATA, WKC) = cat.EEPROM_Read()
print("READ[0x{:04x}]= 0x{:04x}".format(i, DATA[0] | DATA[1] << 8))
cat.EthereCAT_Reset()
time.sleep(1)
cat.ADP = 0x0000
cat.APRD(IDX=0x00, ADP=cat.ADP, ADO=0x0502, DATA=[0x00, 0x00])
time.sleep(0.05)
(DATA, WKC) = cat.socket_read()
print(DATA)
print('DATA:{:04x}'.format(DATA[0] | DATA[1] << 8))
if __name__ == "__main__":
main()