cms-gem-daq-project / xhal

XHAL interface library
0 stars 10 forks source link

Fixing logging issues, adding exceptions forwarding and re(dis)connect methods #90

Closed mexanick closed 6 years ago

mexanick commented 6 years ago

Description

Example code:

import xhalpy as xi
print "TEST OF XHAL RPC EXCEPTIONS HANDLING"
eagle64=xi.XHALDevice("eagle64","/opt/cmsgemos/etc/maps/amc_address_table_top.xml")
print "read reg by name: eagle64.readReg(GEM_AMC.GEM_SYSTEM.BOARD_ID)=%08x"%(eagle64.readReg("GEM_AMC.GEM_SYSTEM.BOARD_ID"))
print "Now disconnect"
eagle64.disconnect()
print "RPC service disconnected. Now try to read register by name again"
try:
  print "read reg by name: eagle64.readReg(GEM_AMC.GEM_SYSTEM.BOARD_ID)=%08x"%(eagle64.readReg("GEM_AMC.GEM_SYSTEM.BOARD_ID"))
except xi.XHALRPCNotConnectedException as e:
  print "Caught exception: %s" %(e)
print "Now reconnect"
eagle64.reconnect()
print "RPC service reconnected. Now try to read register by name again"
try:
  print "read reg by name: eagle64.readReg(GEM_AMC.GEM_SYSTEM.BOARD_ID)=%08x"%(eagle64.readReg("GEM_AMC.GEM_SYSTEM.BOARD_ID"))
except xi.XHALRPCNotConnectedException as e:
  print "Caught exception: %s" %(e)
print "Test reconnection attempt on connected service"
try:
  eagle64.reconnect()
except xi.XHALRPCException as e:
  print "Caught exception: %s" %(e)

Expected output:

1 [140054805878592] INFO XHALInterface_eagle64_0 <> - XHAL Logger tuned up
5 [140054805878592] INFO XHALInterface_eagle64_0 <> - RPC connected
5 [140054805878592] INFO XHALInterface_eagle64_0 <> - XHAL Interface connected
10 [140054805878592] INFO XHALXMLParser_0 <> - Successfully initialized XML4C system
read reg by name: eagle64.readReg(GEM_AMC.GEM_SYSTEM.BOARD_ID)=0000beef
Now disconnect
2133 [140054805878592] INFO XHALInterface_eagle64_0 <> - RPC disconnected
RPC service disconnected. Now try to read register by name again
2133 [140054805878592] ERROR XHALInterface_eagle64_0 <> - Caught NotConnectedException: Not connected to rpc service
Caught exception: RPC NotConnectedException: Not connected to rpc service
Now reconnect
2137 [140054805878592] INFO XHALInterface_eagle64_0 <> - RPC connected
RPC service reconnected. Now try to read register by name again
read reg by name: eagle64.readReg(GEM_AMC.GEM_SYSTEM.BOARD_ID)=0000beef
Test reconnection attempt on connected service
2476 [140054805878592] ERROR XHALInterface_eagle64_0 <> - Interface already connected. Reconnection failed
Caught exception: RPC exception: Interface already connected. Reconnection failed
2476 [140054805878592] INFO XHALInterface_eagle64_0 <> - RPC disconnected

Types of changes

How Has This Been Tested?

Tested with (updated) testing script

Screenshots (if appropriate):

Checklist:

mexanick commented 6 years ago

@bdorney please rebase #89 with this update