1414import busio # noqa: E402
1515
1616
17- def NotecardExceptionInfo (exception ):
18- """Construct a formatted Exception string.
19-
20- Args:
21- exception (Exception): An exception object.
22-
23- Returns:
24- string: a summary of the exception with line number and details.
25- """
26- name = exception .__class__ .__name__
27- return sys .platform + ": " + name \
28- + ": " + " " .join (map (str , exception .args ))
29-
30-
3117def configure_notecard (card , product_uid ):
3218 """Submit a simple JSON-based request to the Notecard.
3319
@@ -39,11 +25,7 @@ def configure_notecard(card, product_uid):
3925 req ["product" ] = product_uid
4026 req ["mode" ] = "continuous"
4127
42- try :
43- card .Transaction (req )
44- except Exception as exception :
45- print ("Transaction error: " + NotecardExceptionInfo (exception ))
46- time .sleep (5 )
28+ card .Transaction (req )
4729
4830
4931def get_temp_and_voltage (card ):
@@ -53,20 +35,13 @@ def get_temp_and_voltage(card):
5335 card (object): An instance of the Notecard class
5436
5537 """
56- temp = 0
57- voltage = 0
58-
59- try :
60- req = {"req" : "card.temp" }
61- rsp = card .Transaction (req )
62- temp = rsp ["value" ]
38+ req = {"req" : "card.temp" }
39+ rsp = card .Transaction (req )
40+ temp = rsp ["value" ]
6341
64- req = {"req" : "card.voltage" }
65- rsp = card .Transaction (req )
66- voltage = rsp ["value" ]
67- except Exception as exception :
68- print ("Transaction error: " + NotecardExceptionInfo (exception ))
69- time .sleep (5 )
42+ req = {"req" : "card.voltage" }
43+ rsp = card .Transaction (req )
44+ voltage = rsp ["value" ]
7045
7146 return temp , voltage
7247
@@ -75,7 +50,8 @@ def run_example(product_uid, use_uart=True):
7550 """Connect to Notcard and run a transaction test."""
7651 print ("Opening port..." )
7752 if use_uart :
78- port = busio .UART (board .TX , board .RX , baudrate = 9600 )
53+ port = busio .UART (board .TX , board .RX , baudrate = 9600 ,
54+ receiver_buffer_size = 128 )
7955 else :
8056 port = busio .I2C (board .SCL , board .SDA )
8157
0 commit comments