forked from xArm-Developer/xArm-Python-SDK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
5008-get_cgpio_state.py
51 lines (42 loc) · 1.48 KB
/
5008-get_cgpio_state.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python3
# Software License Agreement (BSD License)
#
# Copyright (c) 2019, UFACTORY, Inc.
# All rights reserved.
#
# Author: Vinman <[email protected]> <[email protected]>
"""
Example: Get Controller GPIO Digital/Anglog
"""
import os
import sys
import time
sys.path.append(os.path.join(os.path.dirname(__file__), '../../..'))
from xarm.wrapper import XArmAPI
from configparser import ConfigParser
parser = ConfigParser()
parser.read('../robot.conf')
try:
ip = parser.get('xArm', 'ip')
except:
ip = input('Please input the xArm ip address[192.168.1.194]:')
if not ip:
ip = '192.168.1.194'
arm = XArmAPI(ip)
time.sleep(0.5)
if arm.warn_code != 0:
arm.clean_warn()
if arm.error_code != 0:
arm.clean_error()
code, states = arm.get_cgpio_state()
print('get_cgpio_state, code={}'.format(code))
print('GPIO state: {}'.format(states[0]))
print('GPIO error code: {}'.format(states[1]))
print('Digital->Input->FunctionalIO: {}'.format([states[2] >> i & 0x0001 for i in range(8)]))
print('Digital->Input->ConfiguringIO: {}'.format([states[3] >> i & 0x0001 for i in range(8)]))
print('Digital->Output->FunctionalIO: {}'.format([states[4] >> i & 0x0001 for i in range(8)]))
print('Digital->Output->ConfiguringIO: {}'.format([states[5] >> i & 0x0001 for i in range(8)]))
print('Analog->Input: {}'.format(states[6:8]))
print('Analog->Output: {}'.format(states[8:10]))
print('Digital->Input->Conf: {}'.format(states[10]))
print('Digital->Output->Conf: {}'.format(states[11]))