Skip to content

Commit 21afccc

Browse files
committed
Increase tcp/ip control
1 parent ed61346 commit 21afccc

File tree

7 files changed

+348
-134
lines changed

7 files changed

+348
-134
lines changed

demo/Client.py

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,5 @@
1+
#!/usr/bin/env python3
12
# coding:utf-8
2-
# // An highlighted block
3-
import traceback
4-
import socket
5-
import time
6-
import sys
7-
# RPi's IP
8-
SERVER_IP = "192.168.10.115" # 输入正确的目标ip地址,请查看树莓派ip
9-
SERVER_PORT = 9000
10-
11-
print("Starting socket: TCP...")
12-
13-
print("Please input!")
14-
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
15-
sock.connect((SERVER_IP, SERVER_PORT)) # 打开链接
16-
444
17-
sock.sendall(str.encode("12312"))
18-
received = sock.recv(1024)
19-
print("read: " + received.decode())
20-
while True:
21-
try:
22-
#
23-
# if len(data)>0:
24-
command = input()
25-
command += '\n'
26-
print("send: " + command)
27-
try:
28-
sock.sendall(str.encode(command))
29-
received = sock.recv(1024)
30-
print("read: " + received.decode())
31-
except ConnectionRefusedError:
32-
print('error')
33-
sock.close()
34-
pass
35-
except BlockingIOError:
36-
pass
37-
except:
38-
pass
39-
40-
except Exception:
41-
# print("exception")
42-
print(traceback.format_exc())
43-
sys.exit(1)
3+
from pymycobot.mycobotsocket import MyCobotSocket
4+
m = MyCobotSocket("192.168.10.115", "/dev/ttyAMA0", "1000000")
5+
print(m.send_command("get_coords"))

demo/REMADE.md renamed to demo/SOCT_REMADE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# 使用说明
22
## 使用说明
3-
* "Client.py"是客户端的样例,使用在电脑中
4-
* "Servo.py"是服务器端的执行文件,使用前要修改对应的ip地址信息,防止设备无法连接
3+
* "Client.py"是客户端的样例,使用在你的电脑中运行
4+
* "Servo.py"是服务器端的执行文件,在机械臂中运行
55
## 参考内容
66
* [Socket 使用解析](https://blog.csdn.net/pashanhu6402/article/details/96428887?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522162392592016780357215629%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=162392592016780357215629&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~top_positive~default-1-96428887.first_rank_v2_pc_rank_v29&utm_term=socket&spm=1018.2226.3001.4187)
77

0 commit comments

Comments
 (0)