34 from struct
import pack, unpack
38 _SOCKET_IP_ADDRESS =
"192.168.0.23" 39 _SOCKET_PORT_NUMBER = 5500
47 _CMD_SETPOSTURE = 0x10B
48 _CMD_GETPOSTURE = 0x10C
57 _CMD_NOCOMMAND = 0xFFF
59 _CONNECTING_PROCCES_ROS = 0x02
62 _DATA_TYPE_PROGRAM = 0x01
63 _DATA_TYPE_CONNECT_CHECK = 0x02
64 _DATA_TYPE_OPERATION_GET = 0x03
66 _SOCKET_RECV_BUFF_SIZE = 4096
68 def __init__(self, ip_address=_SOCKET_IP_ADDRESS):
70 self.
_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
71 self._sock.setsockopt(socket.SOL_TCP, socket.TCP_NODELAY, 1)
77 self._sock.sendall(send_data)
80 recv_data = json.loads(rec_msg)
81 err_code = recv_data[
"RE"]
82 return_data[
"DA"] = json.loads(recv_data[
"DA"])
90 "DA": json.dumps(data)
92 send_char_data = json.dumps(send_json)
93 pack_format = str(len(send_char_data)) +
"s" 94 send_data = pack(pack_format, send_char_data)
119 def qjmove(self, ax1, ax2, ax3, ax4, ax5, ax6, speed=None):
120 print "qjmove execution" 129 if speed
is not None:
133 print "qjmove success" 134 print "return:" + str(return_data)
138 print "abortm execution" 142 print "abortm success" 143 print "return:" + str(return_data)
146 def syssts(self, stat_type, output_data):
152 return_data = self.
_send_data(send_data, output_data)
158 print "set_jspeed execution" 165 print "set_jspeed success" 166 print "return:" + str(return_data)
175 print "set_posture success" 176 print "return:" + str(return_data)
183 return_data = self.
_send_data(send_data, output_data)
184 print "get_posture success" 185 print "return:" + str(return_data)
186 print "output:" + str(output_data)
200 return_data = self.
_send_data(send_data, output_data)
201 print "position_to_joint success" 202 print "return:" + str(return_data)
212 print "set_io success" 213 print "return:" + str(return_data)
216 def get_io(self, start_addr, end_addr, output_data):
222 return_data = self.
_send_data(send_data, output_data)
223 print "get_io success" 224 print "return:" + str(return_data)
225 print "output_data:" + str(output_data)
235 print "set_adc success" 236 print "return:" + str(return_data)
242 return_data = self.
_send_data(send_data, output_data)
243 print "get_adc success" 244 print "return:" + str(return_data)
245 print "output_data:" + str(output_data)
262 print "set_tool success" 263 print "return:" + str(return_data)
266 if __name__ ==
'__main__':
268 print "check_connect_status():" 269 print api.check_connect_status()
270 print "get_operation_permission():" 271 print api.get_operation_permission()
def __init__(self, ip_address=_SOCKET_IP_ADDRESS)
def _send_data(self, send_data, return_data={})
def get_posture(self, output_data)
def set_io(self, address, signal)
int _SOCKET_RECV_BUFF_SIZE
def exec_program(self, path, param='', delete_flag=0)
def syssts(self, stat_type, output_data)
int _CONNECTING_PROCCES_ROS
def get_io(self, start_addr, end_addr, output_data)
int _DATA_TYPE_CONNECT_CHECK
def set_tool(self, x, y, z, rz, ry, rx)
def get_operation_permission(self)
int _DATA_TYPE_OPERATION_GET
def position_to_joint(self, x, y, z, rx, ry, rz, output_data)
def check_connect_status(self)
def qjmove(self, ax1, ax2, ax3, ax4, ax5, ax6, speed=None)
def set_adc(self, ch, mode)
def get_adc(self, output_data)
def _create_send_data(self, cmd_id, data, data_type=_DATA_TYPE_CMD)
def set_posture(self, posture)