本文整理汇总了Python中Arduino.Arduino.disconnect方法的典型用法代码示例。如果您正苦于以下问题:Python Arduino.disconnect方法的具体用法?Python Arduino.disconnect怎么用?Python Arduino.disconnect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Arduino.Arduino
的用法示例。
在下文中一共展示了Arduino.disconnect方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: connect_arduino
# 需要导入模块: from Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino import disconnect [as 别名]
def connect_arduino(P_knob, I_knob, D_knob,
P_result_box, I_result_box, D_result_box,
connected_result, com_choice, connect_button, disconnect_button, set_temp_box, manual_com_choice,
start_data, stop_data, save_params_button, display_params_button, params_box, set_temp_button, auto_collect, current_temp,
plot, messages, **kwargs):
global parameters
global arduino
arduino = Arduino()
parameters = np.zeros(6)
found_PID_controller = False
found_arduino = False
if manual_com_choice.value:
arduino = Arduino('COM%s'%com_choice.value, 9600, 1.0)
if arduino.connect():
if arduino.ID == 'PID Temperature Controller':
found_PID_controller = True
found_arduino = True
connected_result.value = 'Connected on COM%s'%(com_choice.value)
messages.write('Successfully connected to Arduino on COM%s. '%com_choice.value)
else:
messages.write('Successfully connected to Arduino on %s but ID was not correct.\nID: %s\n' %(com_choice.value, arduino.ID))
found_arduino = True
arduino.disconnect()
else:
connected_result.value = 'Failed to connect on COM%s' %(com_choice.value)
else:
coms = []
for x in map(str, range(1,101)): coms.append('COM'+x)
for com in coms:
arduino = Arduino(com, 9600, 1.0)
if arduino.connect():
if arduino.ID == 'PID Temperature Controller':
found_PID_controller = True
found_arduino = True
connected_result.value = 'Connected on %s' %(com)
messages.write('Successfully connected to Arduino on %s. '%com)
print arduino.ID
else:
messages.write('Successfully connected to Arduino on %s but ID was not correct.\nID: %s\n' %(com, arduino.ID))
found_arduino = True
arduino.disconnect()
else:
connected_result.value = 'Failed to connect on %s' %(com)
if found_PID_controller: break
if not found_arduino and not found_PID_controller:
messages.write('Failed to connect to Arduino on COMs 1-100\n')
if found_arduino:
if found_PID_controller:
messages.write('PID Temperature Controller found.\n')
if arduino.is_connected and arduino.is_ready:
time.sleep(.2)
messages.write('Arduino is open for communication.\n')
P_knob.enabled=True
I_knob.enabled=True
D_knob.enabled=True
P_result_box.enabled=True
I_result_box.enabled=True
D_result_box.enabled=True
connect_button.enabled = False
disconnect_button.enabled = True
save_params_button.enabled=False
display_params_button.enabled=True
params_box.value=''
set_temp_button.enabled=True
start_data.enabled=True
stop_data.enabled=True
auto_collect.enabled=True
initialize_parameters(P_knob, I_knob, D_knob,
P_result_box, I_result_box,
D_result_box, set_temp_box, start_data, stop_data,
current_temp, auto_collect, messages, plot, params_box, **kwargs)
else:
messages.write('Arduino connected but not yet ready for serial communication.\n')
else:
messages.write('Failed to find PID Temperature Controller, but Arduino boards detected.\n')
else:
arduino.disconnect()
P_knob.enabled=False
I_knob.enabled=False
D_knob.enabled=False
P_result_box.enabled=False
I_result_box.enabled=False
D_result_box.enabled=False
disconnect_button.enabled=False
connect_button.enabled=True
set_temp_button.enabled=False
display_params_button.enabled=False
start_data.enabled=False
stop_data.enabled=False