#!/usr/bin/env python

#coding=utf-8
from ctypes import *
import bdaqadamio
import time

def OpenLib() :
	global myprocHandle
	ret = bdaqadamio.ADAMDrvOpen(myprocHandle)
	print("myprocHandle%d"%myprocHandle.value)

	if ret == 0:
		return 0
	else :
		return -99


def CloseLib() :
	global myprocHandle
	if myprocHandle != 0 :
		bdaqadamio.ADAMDrvClose(myprocHandle)

def EX_GetSlotInfo() :
	iSlot = 0
	id = c_int(0)
	byName = create_string_buffer("",10)
	# GetSlotInformation
	for iSlot in range(0, ADAM_SLOT_NUM) :
		if 0 == bdaqadamio.SYS_GetModuleID(myprocHandle, iSlot, id) :
			if 0 == bdaqadamio.SYS_GetModuleName(myprocHandle, iSlot, (byName)) :
					chSlotID = byName
			else :
					print("Slot %d: Failed to get getModuleName."%iSlot)
			print("Slot %d: %s"%(iSlot, chSlotID.value))
		else :
			print("Slot %d: Failed to get."%iSlot)

if __name__ == '__main__':

	ADV_SUCCESS = 0
	MAX_ID_SIZE = 12
	ADAM_SLOT_NUM = 8

	myprocHandle = c_int(0)
	nodeid = c_int(0)
	print("/*** GetSlotInfo Sample ***/")

	iRet = OpenLib()
	if iRet == 0 :                       
		if 0 == bdaqadamio.SYS_GetNodeID(myprocHandle, nodeid) :
			print("Node ID:0x%X"%nodeid.value)                        
		else :                                                            
			print("Get Node ID Failed.")                              
		EX_GetSlotInfo()                                                  
	else :                                                                    
			print("OpenLib(%d) failed."%iRet)                                 
																			  
																			  
	CloseLib()                                                                
	print("/***        END         ***/")  
