diff --git a/README.md b/README.md index 5759e85..96a0b2e 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,4 @@ -WIZnetTool -=========== -WIZnetTool is module Configuration & Test Tool for WIZ75X Series. - [SUPPORT DEVICES](#support-devices) - [CONFIGURATION TOOL](#configuration-tool) @@ -12,6 +9,12 @@ WIZnetTool is module Configuration & Test Tool for WIZ75X Series. - [FAQ](#faq) +# OVERVIEW +WIZnet-S2E-Tool is module Configuration & Test Tool for WIZnet S2E devices. \ +Python interpreter based and it is platform independent. +It works on version 2.7 python current. + + # SUPPORT DEVICES ## 1 Port Serial to Ethernet Module - [WIZ750SR](http://wizwiki.net/wiki/doku.php?id=products:wiz750sr:start) @@ -19,11 +22,11 @@ WIZnetTool is module Configuration & Test Tool for WIZ75X Series. - [WIZ750SR-100](http://wizwiki.net/wiki/doku.php?id=products:wiz750sr-100:start) - [WIZ750SR-105](http://wizwiki.net/wiki/doku.php?id=products:wiz750sr-105:start) - [WIZ750SR-110](http://wizwiki.net/wiki/doku.php?id=products:wiz750sr-110:start) -- [WIZ750SR-120](http://wizwiki.net/wiki/doku.php?id=products:wiz750sr-120:start) - [WIZ107SR](http://www.wiznet.io/product-item/wiz107sr/) & [WIZ108SR](http://www.wiznet.io/product-item/wiz108sr/) ## 2 Port Serial to Ethernet Module - [WIZ752SR-120](https://wizwiki.net/wiki/doku.php?id=products:s2e_module:wiz752sr-120:start) +- [WIZ752SR-125](https://wizwiki.net/wiki/doku.php?id=products:s2e_module:wiz752sr-125:start) # CONFIGURATION TOOL - [CLI Configuration Tool](#cli-configuration-tool) @@ -36,7 +39,7 @@ WIZnetTool is module Configuration & Test Tool for WIZ75X Series. ### Pre-Required #### 1) Python -WIZnetTool works on Python version 2.7.X. +WIZnet-S2E-Tool works on Python version 2.7. If you don't have Python, refer to https://www.python.org/ If python already installed, check the version as follow. @@ -50,6 +53,94 @@ Next, you have to install **pySerial** module as follow. $ pip install pyserial If you want more detail, refer to https://github.com/pyserial/pyserial +---- + +### Option +#### optional arguments: + -h, --help show this help message and exit + -d MACADDR, --device MACADDR + Device mac address to configuration + -a, --all Configuration about all devices (in mac_list.txt) + +#### Firmware Upload: + -u FWFILE, --upload FWFILE + Firmware upload from file + +#### No parameter Options: + -s, --search Search devices (in same network) + -c, --clear Mac list clear + -r, --reset Reboot device + -f, --factory Factory reset + +#### Network Configuration: + --nmode {0,1,2,3} Network operation mode (0: tcpclient, 1: tcpserver, 2: mixed, 3: udp) + --alloc {0,1} IP address allocation method (0: Static, 1: DHCP) + --ip IP Local ip address + --subnet SUBNET Subnet mask + --gw GW Gateway address + --dns DNS DNS server address + --port PORT Local port number + --rip IP Remote host IP address / Domain + --rport PORT Remote host port number + +#### UART #0 Configurations: + --baud0 BAUD0 baud rate (300|600|1200|1800|2400|4800|9600|14400|19200|28800|38400|57600|115200|230400) + --data0 {0,1} data bit (0: 7-bit, 1: 8-bit) + --parity0 {0,1,2} parity bit (0: NONE, 1: ODD, 2: EVEN) + --stop0 {0,1} stop bit (0: 1-bit, 1: 2-bit) + --flow0 {0,1,2} flow control (0: NONE, 1: XON/XOFF, 2: RTS/CTS) + --time0 TIME0 Time delimiter (0: Not use / 1~65535: Data packing time (Unit: millisecond)) + --size0 SIZE0 Data size delimiter (0: Not use / 1~255: Data packing size (Unit: byte)) + --char0 CHAR0 Designated character delimiter (00: Not use / Other: Designated character) + --it timer Inactivity timer value for TCP connection close + when there is no data exchange (0: Not use / 1~65535: timer value) + --ka {0,1} Keep-alive packet transmit enable for checking TCP connection established + --ki number Initial TCP keep-alive packet transmission interval value + (0: Not use / 1~65535: Initial Keep-alive packet transmission interval (Unit: millisecond)) + --ke number TCP Keep-alive packet transmission retry interval value + (0: Not use / 1~65535: Keep-alive packet transmission retry interval (Unit: millisecond)) + --ri number TCP client reconnection interval value [TCP client only] + (0: Not use / 1~65535: TCP client reconnection interval (Unit: millisecond)) + +#### UART #1 Configurations: + --baud1 BAUD1 baud rate (300|600|1200|1800|2400|4800|9600|14400|19200|28800|38400|57600|115200|230400) + --data1 {0,1} data bit (0: 7-bit, 1: 8-bit) + --parity1 {0,1,2} parity bit (0: NONE, 1: ODD, 2: EVEN) + --stop1 {0,1} stop bit (0: 1-bit, 1: 2-bit) + --flow1 {0,1,2} flow control (0: NONE, 1: XON/XOFF, 2: RTS/CTS) + --time1 TIME1 Time delimiter (0: Not use / 1~65535: Data packing time (Unit: millisecond)) + --size1 SIZE1 Data size delimiter (0: Not use / 1~255: Data packing size (Unit: byte)) + --char1 CHAR1 Designated character delimiter (00: Not use / Other: Designated character) + --rv timer Inactivity timer value for TCP connection close + when there is no data exchange (0: Not use / 1~65535: timer value) + --ra {0,1} Keep-alive packet transmit enable for checking TCP connection established + --rs number Initial TCP keep-alive packet transmission interval value + (0: Not use / 1~65535: Initial Keep-alive packet transmission interval (Unit: millisecond)) + --re number TCP Keep-alive packet transmission retry interval value + (0: Not use / 1~65535: Keep-alive packet transmission retry interval (Unit: millisecond)) + --rr number TCP client reconnection interval value [TCP client only] + (0: Not use / 1~65535: TCP client reconnection interval (Unit: millisecond)) + +#### UART Command mode switch settings: + --te {0,1} Serial command mode switch code enable + --ss 3-byte hex Serial command mode switch code (default: 2B2B2B) + +#### Configs: + --cp {0,1} TCP connection password enable [TCP server mode only] + --np pw TCP connection password (string, up to 8 bytes / default: None) [TCP server mode only] + --sp value Search identification code (string, up to 8 bytes / default: None) + --dg {0,1} Serial debug message enable (Debug UART port) + +#### Configuration from File: + --setfile SETFILE File name to Set + --getfile GETFILE File name to Get info. Refer default command(cmd_oneport.txt or cmd_twoport.txt). + +#### Set IP address for multi devices: + -m ipaddr, --multiset ipaddr + Set IP address for all device in 'mac_list.txt'. Parameter is first address. + +---- + ### Usage $ python wizconfig.py [Options ...] You can see detail description as following command. @@ -58,15 +149,20 @@ You can see detail description as following command. When config the serial port, refer below. +- ***Warning*** +The *UART #1 Configurations* is for 2 port S2E devices. refer to below. + - 1 Port S2E devices - WIZ750SR Series - - Use **UART #0 Configurations** + - Use **UART #0 Configurations** only. - 2 Port S2E devices - WIZ752SR Series - Use **UART #0 Configurations** & **UART #1 Configurations** both. And all other options are common for 1 port & 2 port S2E devices. +---- + #### 1. Search Devices First, you could search devices use '-s' or '--search' option. @@ -81,18 +177,19 @@ And then **mac_list.txt** is created, there are MAC address information of each * All Devices $ python wizconfig.py -a [Options ...] - -* Set example - Set baud rate to 115200 of 1 port S2E device. - If device's mac address is '00:08:DC:AA:BB:CC', you can set like this. +*Set example* - $ python wizconfig.py -d 00:08:DC:AA:BB:CC --baud0 115200 +Set baud rate to 115200 of 1 port S2E device. - If you want to set baud rate for all devices on the network, do like this. +If device's mac address is '00:08:DC:AA:BB:CC', you can set like this. - $ python wizconfig.py -a --baud0 115200 + $ python wizconfig.py -d 00:08:DC:AA:BB:CC --baud0 115200 + +If you want to set baud rate for all devices on the network, do like this. + + $ python wizconfig.py -a --baud0 115200 #### 3. Firmware Upload @@ -167,11 +264,13 @@ Then, config deivce use --setfile option. $ python wizconfig.py -a --setfile set_cmd.txt - +---- ## GUI Configuration Tool _GUI Configuration Tool is not supported yet. It will be updated soon._ +---- + # TEST TOOL ## Loopback Test This tool is perform simple loopback test for functional verification of WIZ75XSR devices. @@ -193,5 +292,7 @@ This tool is perform simple loopback test for functional verification of WIZ75XS + + # FAQ If you have any problems, please visit [WIZnet Forum](https://forum.wiznet.io/). diff --git a/TCPServerThread.py b/TCPServerThread.py deleted file mode 100644 index a0b6b3f..0000000 --- a/TCPServerThread.py +++ /dev/null @@ -1,266 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - -# Implemented by James YS Kim - -import sys - -# sys.path.append('./TCPClient/') -import time -import socket -import getopt -import threading -# import thread -import errno - -from wizsocket.TCPServer import TCPServer -from time import gmtime, strftime, localtime - -from TCPClientThread import msg -# msg = "Hello WIZ750SR\r" - -''' -TCP server -#socket = socket.socket( socket.AF_INET , socket.SOCK_STREAM ) -1> socket.bind( addr ) // 서버의 아이피와 포트번호를 고정 -2> socket.listen(0) // 클라이언트의 연결을 받을 수 있는 상태 -3> socket.accept() // 클라이언트로부터 소켓과 클라이언트의 주소를 반환 -4> socket.recv( byte수 ) // 연결되어진 클라이언트로부터 데이터를 받는다 -''' - -class TCPServerThread(threading.Thread): - def __init__(self, serverip, serverport, trycount): - # def __init__(self) - threading.Thread.__init__(self) - self.serverip = serverip - self.serverport = serverport - # self.f = fd - self.totaltrycount = 0 - self.successcount = 0 - self.failcount = 0 - self.trycount = trycount - self.server = None - - def stop(self): - if self.server is not None: - self.server.close() - self.server = None - sys.stdout.write('thread for %r ' % self.serverip) - sys.stdout.write('is shutdowning (server)\r\n') - # if not self.f.closed: - if self.totaltrycount > 0: - logstr = "======================================\r\n" - logstr = logstr + '[' + self.serverip + '] stopped at ' + strftime("%d %b %Y %H:%M:%S", localtime()) + '\r\n' - logstr = logstr + 'Total try: ' + str(self.totaltrycount) + '\r\n' - logstr = logstr + 'Success count: ' + str(self.successcount) + '\r\n' - logstr = logstr + 'Fail count: ' + str(self.failcount) + '\r\n' - logstr = logstr + 'Success Rate: ' + "{0:.1f}".format( - float(self.successcount) / float(self.totaltrycount) * 100) + '%\r\n' - logstr = logstr + '======================================\r\n' - sys.stdout.write(logstr) - else: - logstr = "======================================\r\n" - logstr = logstr + '[' + self.serverip + '] stopped at ' + strftime("%d %b %Y %H:%M:%S", localtime()) + '\r\n' - logstr = logstr + 'Connection Failed\r\n' - logstr = logstr + '======================================\r\n' - sys.stdout.write(logstr) - # self.f.write(logstr) - self._Thread__stop() - - # TCP Server - def run(self): - # SOCK_CLOSE_STATE = 1 - # SOCK_OPENTRY_STATE = 2 - # SOCK_OPEN_STATE = 3 - # SOCK_LISTEN_STATE = 4 - # SOCK_ACCEPT_STATE = 5 - - SOCK_CLOSE_STATE = 1 - SOCK_OPENTRY_STATE = 2 - SOCK_OPEN_STATE = 3 - SOCK_CONNECTTRY_STATE = 4 - SOCK_CONNECT_STATE = 5 - - idle_state = 1 - datasent_state = 2 - - sys.stdout.write('thread for %r ' % self.serverip) - sys.stdout.write('is starting\r\n') - - # TCPClient instance creation - - try: - self.server = TCPServer(2, self.serverip, self.serverport) - except: - self.stop() - - while True: - if self.server.state is SOCK_CLOSE_STATE: - try: - cur_state = self.server.state - self.server.open() - # sys.stdout.write('1 : %r' % self.server.getsockstate()) - if self.server.state is SOCK_OPEN_STATE: - sys.stdout.write('[%r] is OPEN\r\n' % (self.serverip)) - # sys.stdout.write('[%r] client.working_state is %r\r\n' % (self.serverip, self.server.working_state)) - time.sleep(1) - except (KeyboardInterrupt, SystemExit): - sys.stdout.write('OPEN: keyboard interrupt occured!!') - for i in range(self.trycount): - print('trycount: ', i) - - elif self.server.state is SOCK_OPEN_STATE: - cur_state = self.server.state - try: - self.server.connect() - # time.sleep(3) - except Exception as e: - time.sleep(1) - # print('Server.connect() error:', e) - try: - # sys.stdout.write('2 : %r' % self.server.getsockstate()) - if self.server.state is SOCK_CONNECT_STATE: - sys.stdout.write('[%r] is CONNECTED\r\n' % (self.serverip)) - # sys.stdout.write('[%r] client.working_state is %r\r\n' % (self.serverip, self.server.working_state)) - time.sleep(1) - except (KeyboardInterrupt, SystemExit): - sys.stdout.write('CONNECT: keyboard interrupt occured!!\nExit.') - for i in range(self.trycount): - time.sleep(1) - self.stop() -# threads[i].stop() - - elif self.server.state is SOCK_CONNECT_STATE: - if self.server.working_state == idle_state: - # sys.stdout.write('3 : %r' % self.server.getsockstate()) - try: - if self.totaltrycount >= self.trycount: - break - # time.sleep(1) - self.server.write(msg) - # print('============== debug 3') - logstr = '[' + self.serverip + '] sent ' + msg + '\r\n' - sys.stdout.write(logstr) - # self.f.write(logstr) - self.server.working_state = datasent_state - self.totaltrycount += 1 - except Exception as e: - time.sleep(1) - sys.stdout.write('%r\r\n' % e) - # if isinstance(e.args, tuple): - # print('errno is %d', e[0]) - # if e[0] == errno.EPIPE: - # # remote peer diconnected - # print('Detected remote disconnect') - # else: - # pass - # else: - # print('socket error', e) - # self.server.close() - # break - - elif self.server.working_state == datasent_state: - # sys.stdout.write('4 : %r' % self.server.getsockstate()) - time.sleep(1.7) - response = self.server.readline() - # print('===> TCP reponse', response) - if (response != ""): - logstr = '[' + self.serverip + '] received ' + response + '\r\n' - sys.stdout.write(logstr) - sys.stdout.flush() - # self.f.write(logstr) - if (msg in response): - logstr = '[' + self.serverip + ']' + strftime(" %d %b %Y %H:%M:%S", - localtime()) + ': success,' - self.successcount += 1 - # sys.stdout.write(logstr) - # self.f.write(logstr) - else: - logstr = '[' + self.serverip + ']' + strftime(" %d %b %Y %H:%M:%S", - localtime()) + ': fail by broken data,' - # sys.stdout.write(logstr) - self.failcount += 1 - # self.f.write(logstr) - - logstr = logstr + ' success rate: ' \ - + "{0:.2f}".format(float(self.successcount) / float(self.totaltrycount) * 100) + '%, [' \ - + str(self.successcount) + '/' + str(self.totaltrycount) + ']\r\n\r\n' - sys.stdout.write(logstr) - # self.f.write(logstr) - # time.sleep(1) - self.server.working_state = idle_state - - response = "" - - self.stop() - -if __name__ == '__main__': - - dst_ip = '' - dst_port = 5000 - dst_num = 0 - retrycount = 10 - - # msg = "Hello WIZ750SR\r" - - if len(sys.argv) <= 4: - sys.stdout.write('Invalid syntax. Refer to below\r\n') - sys.stdout.write('TCPClientThreadNew.py -s -c \r\n)') - sys.exit(0) - - try: - opts, args = getopt.getopt(sys.argv[1:], "hs:c:r:") - except getopt.GetoptError: - sys.stdout.write('Invalid syntax. Refer to below\r\n') - sys.stdout.write('TCPClientThreadNew.py -s -c \r\n)') - sys.exit(0) - - sys.stdout.write('%r\r\n' % opts) - - threads = [] - - try: - for opt, arg in opts: - if opt == '-h': - sys.stdout.write('Valid syntax\r\n') - sys.stdout.write('TCPClientThreadNew.py -s -c \r\n') - sys.exit(0) - elif opt in ("-s", "--sip"): - dst_ip = arg - sys.stdout.write('%r\r\n' % dst_ip) - elif opt in ("-c", "--count"): - dst_num = int(arg) - sys.stdout.write('%r\r\n' % dst_num) - elif opt in ("-r", "--retry"): - retrycount = int(arg) - sys.stdout.write('%r\r\n' % retrycount) - - lastnumindex = dst_ip.rfind('.') - lastnum = int(dst_ip[lastnumindex + 1:len(dst_ip)]) - - - # filename = strftime("%d-%b-%Y", localtime()) + '_log.txt' - # fd = open(filename, 'w') - - for i in range(dst_num): - t = TCPClientThreadNew(dst_ip[:lastnumindex + 1] + str(lastnum + i), dst_port, retrycount) - threads.append(t) - - for i in range(dst_num): - threads[i].start() - - end_flag = False - - while not end_flag: - end_flag = not end_flag - for i in range(len(threads)): - end_flag &= not threads[i].is_alive() - - except (KeyboardInterrupt, SystemExit): - sys.stdout.write('--------> Keyboard interrupt 33!!\r\n') - for i in range(dst_num): - threads[i].stop() - # finally: - # # time.sleep(5) - # fd.close() - diff --git a/WIZUART.py b/WIZUART.py deleted file mode 100644 index a9ef200..0000000 --- a/WIZUART.py +++ /dev/null @@ -1,113 +0,0 @@ -# -*- coding: utf-8 -*- -# Serial test program - -import serial -import time -import sys -import threading -import signal - -# Test message - 송수신 데이터 비교하기 위해 가져옴 -from TCPClientThread import msg - -# BAUDRATES = [300, 600, 1200, 1800, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, 115200, 230400] - -## pyserial은 기본 설치 모듈이 아니므로 설치 유무를 판단하여 -# 설치가 되어있지 않으면 설치하도록 하는 코드 추가 필요 (?) (외부 명령어 사용?) pip3 install ~ - -class WIZUART(threading.Thread): - - def __init__(self, device, trycount, baud): - # print('WIZUART: __init__') - # - threading.Thread.__init__(self) - - self.device = device - # self.timer1 = None - # self.totaltrycount = 0 - # self.successcount = 0 - # self.failcount = 0 - # self.client = None - - self.baud = baud # mapping: 0~13 => baud 300~230400 - self.rcv_data = None - - self.count = trycount - - def open(self): - print('WIZUART: open') - - # Serial Device open (in init) - self.ser = serial.Serial() - - # Serial 설정 - self.ser.port = self.device - self.ser.baudrate = self.baud - # self.ser.baudrate = 115200 - self.ser.parity = serial.PARITY_NONE - self.ser.stopbits = serial.STOPBITS_ONE - self.ser.bytesize = serial.EIGHTBITS - # timeout=None # block read - self.ser.timeout = 1 # non-block read - self.ser.xonxoff = False # disable software flow control - self.ser.rtscts = False # disable hardware (RTS/CTS) flow control - self.ser.dsrdtr = False # disable hardware (DSR/DTR) flow control - - try: - self.ser.open() - print('UART device open: %s:%s' % (self.device, self.baud)) - except serial.SerialException as e: - sys.stderr.write('Could not open serial port {}: {}\n'.format(self.ser.name, e)) - sys.exit(1) - - # def write(self): - # print('WIZUART: send') - # # for i in range(100): - # while True: - # try: - # # self.ser.write(msg.encode()) - # self.ser.write(self.rcv_data) - # # time.sleep(1) - # except (KeyboardInterrupt, SystemExit): - # print('Keyborad interrupt - Exit') - # break - - # Serial로 받은 데이터를 다시 돌려줌 - # def redirect(self): - def run(self): - while True: - try: - # 수신 데이터 저장 - self.rcv_data = self.ser.readline() - - if self.rcv_data: # 데이터를 받으면 - if msg in self.rcv_data: # 원본 데이터와 비교 - # print(self.rcv_data, 'UART: Success!') - logstr = '<' + self.device + '> receive ' + msg + '\r\n' - sys.stdout.write(logstr) - - self.ser.write(self.rcv_data) - - logstr = '<' + self.device + '> sent ' + msg + '\r\n' - sys.stdout.write(logstr) - # time.sleep(0.5) - else: - print('UART: Fail') - - # trycount 만큼 돌림 - if self.count == 0: - break - self.count -= 1 - - # except Exception as e: - # sys.stdout.write('Error:\r\n', e) - except (KeyboardInterrupt, SystemExit): - print('Keyborad interrupt - Exit') - break - - def stop(self): - if self.ser.isOpen: - self.ser.close() - # self.ser = None - self._Thread__stop() - \ No newline at end of file diff --git a/wiz750_loopback_test.py b/wiz750_loopback_test.py deleted file mode 100644 index 636a019..0000000 --- a/wiz750_loopback_test.py +++ /dev/null @@ -1,166 +0,0 @@ -#!/usr/bin/python - -import socket -import time -import struct -import binascii -import sys -import getopt -import logging -from WIZ750CMDSET import WIZ750CMDSET -from WIZUDPSock import WIZUDPSock -from WIZMSGHandler import WIZMSGHandler -from TCPClientThread import TCPClientThread - -OP_SEARCHALL = 1 -OP_SETIP = 2 -OP_CHECKIP = 3 -OP_FACTORYRESET = 4 -OP_GETDETAIL = 5 - -if __name__=='__main__': - - retrycount = 10 - - if len(sys.argv) <= 4: - sys.stdout.write('Invalid syntax. Refer to below\r\n') - sys.stdout.write('%s -r -t \r\n' % sys.argv[0]) - sys.exit(0) - - try: - opts, args = getopt.getopt(sys.argv[1:], "hs:t:r:") - except getopt.GetoptError: - sys.stdout.write('Invalid syntax. Refer to below\r\n') - sys.stdout.write('%s -r -t \r\n' % sys.argv[0]) - sys.exit(0) - - threads = [] - - try: - for opt, arg in opts: - if opt == '-h': - sys.stdout.write('Valid syntax\r\n') - sys.stdout.write('%s -r -t \r\n' % sys.argv[0]) - sys.exit(0) - elif opt in ("-r", "--retry"): - retrycount = int(arg) - # sys.stdout.write('%r\r\n' % retrycount) - elif opt in ("-t", "--target"): - dst_ip = arg - # sys.stdout.write('%r\r\n' % dst_ip) - - conf_sock = WIZUDPSock(5000, 50001) - conf_sock.open() - wizmsghangler = WIZMSGHandler(conf_sock) - cmd_list = [] - - ################################### - # Search All Devices on the network - cmd_list.append(["MA", "FF:FF:FF:FF:FF:FF"]) - cmd_list.append(["PW", " "]) - cmd_list.append(["MC", ""]) - cmd_list.append(["VR", ""]) - cmd_list.append(["MN", ""]) - cmd_list.append(["UN", ""]) - cmd_list.append(["ST", ""]) - cmd_list.append(["IM", ""]) - cmd_list.append(["OP", ""]) - cmd_list.append(["DD", ""]) - cmd_list.append(["CP", ""]) - cmd_list.append(["PO", ""]) - cmd_list.append(["DG", ""]) - # sys.stdout.write("%s\r\n" % cmd_list) - wizmsghangler.makecommands(cmd_list, OP_SEARCHALL) - wizmsghangler.sendcommands() - retval = wizmsghangler.parseresponse() - sys.stdout.write("%r devices are detected\r\n" % retval) - - ################################### - # Set a consequent IP address and the same port number 5000 to each WIZ750SR Device - - # dst_ip = "192.168.50.50" - dst_port = "5000" - - lastnumindex = dst_ip.rfind('.') - lastnum = int(dst_ip[lastnumindex+1:len(dst_ip)]) - try: - for i in range(0, retval): - cmd_list[:] = [] - mac_addr = wizmsghangler.getmacaddr(i) - print ("mac addr: " + mac_addr) - target_ip = dst_ip[:lastnumindex + 1] + str(lastnum + i) - target_gw = dst_ip[:lastnumindex + 1] + str(1) - cmd_list.append(["MA", mac_addr]) - cmd_list.append(["PW", " "]) - cmd_list.append(["LI", target_ip]) - cmd_list.append(["GW", target_gw]) - cmd_list.append(["LP", dst_port]) - cmd_list.append(["OP", "1"]) - cmd_list.append(["SV", ""]) # save device setting - cmd_list.append(["RT", ""]) # Device reboot - # sys.stdout.write("%s\r\n" % cmd_list) - wizmsghangler.makecommands(cmd_list, OP_SETIP) - wizmsghangler.sendcommands() - wizmsghangler.parseresponse() - - time.sleep(2) - t = TCPClientThread(target_ip, int(dst_port), retrycount) - t.start() - threads.append(t) - # time.sleep(2) - except (KeyboardInterrupt, SystemExit): - sys.stdout.write('Keyboard interrupt occured!!') - for i in range(retrycount): - threads[i].stop() - - ################################### - # Factory Reset all selected Devices - # for i in range(0, retval): - # cmd_list[:] = [] - # mac_addr = wizmsghangler.getmacaddr(i) - # cmd_list.append(["MA", mac_addr]) - # cmd_list.append(["PW", ""]) - # cmd_list.append(["FR", ""]) - # cmd_list.append(["RT", ""]) - # # sys.stdout.write("%s\r\n" % cmd_list) - # wizmsghangler.makecommands(cmd_list, OP_FACTORYRESET) - # wizmsghangler.sendcommands() - # wizmsghangler.parseresponse() - - # sys.stdout.write("%s\r\n" % cmd_list) - - end_flag = False - stop_thread_count = 0 - - while not end_flag: - end_flag = not end_flag - for i in range(len(threads)): - end_flag &= not threads[i].is_alive() - # if(not threads[i].is_alive()): - # sys.stdout.write("thread[%r] is alive : %r\r\n" % (i, threads[i].is_alive())) - # stop_thread_count += 1 - # - # if stop_thread_count is len(threads): - # break - # else: - # stop_thread_count = 0 - # # sys.stdout.write("[%r] ") - # end_flag = False - - sys.stdout.write("all threads are dead\r\n") - except (KeyboardInterrupt, SystemExit): - for i in range(len(threads)): - threads[i].stop() - finally: - for i in range(0, retval): - cmd_list[:] = [] - mac_addr = wizmsghangler.getmacaddr(i) - cmd_list.append(["MA", mac_addr]) - cmd_list.append(["PW", ""]) - cmd_list.append(["FR", ""]) - cmd_list.append(["RT", ""]) - # sys.stdout.write("%s\r\n" % cmd_list) - wizmsghangler.makecommands(cmd_list, OP_FACTORYRESET) - wizmsghangler.sendcommands() - wizmsghangler.parseresponse() - diff --git a/wizconfig.py b/wizconfig.py index ad3a08f..6e0af1a 100644 --- a/wizconfig.py +++ b/wizconfig.py @@ -9,7 +9,6 @@ import sys import getopt import logging -import serial import re import os from WIZ750CMDSET import WIZ750CMDSET @@ -256,6 +255,9 @@ def isvalid(self, mac_addr): sys.exit(0) f = open('mac_list.txt', 'r') mac_list = f.readlines() + if len(mac_list) is 0: + print('There is no mac address. Please search devices from \'-s/--search\' option.') + sys.exit(0) f.close() # Check parameter if args.multiset: