Esempio n. 1
0
def EtherCAT_Init(nic):
    cat = MasterEtherCAT.MasterEtherCAT(nic)  #ネットワークカードのアドレスを記載

    return cat
Esempio n. 2
0
def EtherCAT_Init():
    cat = MasterEtherCAT.MasterEtherCAT("enp0s25")  #ネットワークカードのアドレスを記載
    return cat
Esempio n. 3
0
from pyEtherCAT import MasterEtherCAT  #ライブラリの読出し
nic = "eth0"  # ネットワークカードのアドレスを記載
cat = MasterEtherCAT.MasterEtherCAT(nic)

ADP = 0x0000  #1台目
ADDR = 0x0E00  #コアレジスタのアドレス
cat.APRD(IDX=0x00, ADP=ADP, ADO=ADDR, DATA=[0, 0, 0, 0, 0, 0, 0,
                                            0])  #DATAは0を8個(64bit分)の枠を指示
(DATA, WKC) = cat.socket_read()  #結果を読出し
print(
    "[0x{:04X}]= 0x{:02x}{:02x},0x{:02x}{:02x},0x{:02x}{:02x},0x{:02x}{:02x}".
    format(ADDR, DATA[7], DATA[6], DATA[5], DATA[4], DATA[3], DATA[2], DATA[1],
           DATA[0]))
#読み出したデータを表示する
Esempio n. 4
0
from pyEtherCAT import MasterEtherCAT
import time

cat = MasterEtherCAT.MasterEtherCAT("enp0s25")

# EEPROM Setup
cat.EEPROM_SetUp(0x0000)

# EEPROM ゼロクリア
for i in range(0x0080):
    cat.EEPROM_AddrSet(i)
    cat.EEPROM_Write(0)
    cat.EEPROM_Stasus(enable=0x01,command=0x02)
    time.sleep(0.01)

# EEPROM データ書き込み
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 ベンダーID
cat.EEPROM_AddrSet(0x0008)
cat.EEPROM_Write(0x0A68)
#cat.EEPROM_Write(0x0000)

# EEPROM モード切替
cat.EEPROM_Stasus(enable=0x01,command=0x02)
Esempio n. 5
0
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(0x0FF):
        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,  #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)

    # EEPROM Size [0x003E]
    cat.EEPROM_AddrSet(0x003E)
    cat.EEPROM_Write(0x000F)
    cat.EEPROM_Stasus(enable=0x01, command=0x02)
    time.sleep(0.01)
    # Version [0x003F]
    cat.EEPROM_AddrSet(0x003F)
    cat.EEPROM_Write(0x0001)
    cat.EEPROM_Stasus(enable=0x01, command=0x02)
    time.sleep(0.01)

    ADDR_BASE = 0x0040

    Category_Header = 10  #STRINGS TYPE
    Category_DATA = "HELLO!"
    Category_Size = len(Category_DATA)

    cat.EEPROM_AddrSet(ADDR_BASE + 0)
    cat.EEPROM_Write(Category_Header)
    cat.EEPROM_Stasus(enable=0x01, command=0x02)
    time.sleep(0.01)

    cat.EEPROM_AddrSet(ADDR_BASE + 1)
    cat.EEPROM_Write(int(Category_Size / 2))
    cat.EEPROM_Stasus(enable=0x01, command=0x02)
    time.sleep(0.01)

    cat.EEPROM_AddrSet(ADDR_BASE + 2)
    cat.EEPROM_Write(0x01 | Category_Size << 8)
    cat.EEPROM_Stasus(enable=0x01, command=0x02)
    time.sleep(0.01)

    for i in range(0, int(Category_Size / 2) + 2, 2):
        cat.EEPROM_AddrSet(ADDR_BASE + 3 + int(i / 2))
        cat.EEPROM_Write(
            ord(Category_DATA[i]) | ord(Category_DATA[i + 1]) << 8)
        cat.EEPROM_Stasus(enable=0x01, command=0x02)
        time.sleep(0.01)

    #cat.EEPROM_AddrSet(ADDR_BASE+3+i+2)
    #cat.EEPROM_Write(0xFFFF)
    #cat.EEPROM_Stasus(enable=0x01, command=0x02)
    #time.sleep(0.01)

    # EEPROM 読み出し
    for i in range(0x0050):
        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))
Esempio n. 6
0
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))