Skip to content

Commit

Permalink
Increase tcp/ip control
Browse files Browse the repository at this point in the history
  • Loading branch information
anla-xu committed Nov 12, 2021
1 parent ed61346 commit 21afccc
Show file tree
Hide file tree
Showing 7 changed files with 348 additions and 134 deletions.
46 changes: 4 additions & 42 deletions demo/Client.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,5 @@
#!/usr/bin/env python3
# coding:utf-8
# // An highlighted block
import traceback
import socket
import time
import sys
# RPi's IP
SERVER_IP = "192.168.10.115" # 输入正确的目标ip地址,请查看树莓派ip
SERVER_PORT = 9000

print("Starting socket: TCP...")

print("Please input!")
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((SERVER_IP, SERVER_PORT)) # 打开链接
444
sock.sendall(str.encode("12312"))
received = sock.recv(1024)
print("read: " + received.decode())
while True:
try:
#
# if len(data)>0:
command = input()
command += '\n'
print("send: " + command)
try:
sock.sendall(str.encode(command))
received = sock.recv(1024)
print("read: " + received.decode())
except ConnectionRefusedError:
print('error')
sock.close()
pass
except BlockingIOError:
pass
except:
pass

except Exception:
# print("exception")
print(traceback.format_exc())
sys.exit(1)
from pymycobot.mycobotsocket import MyCobotSocket
m = MyCobotSocket("192.168.10.115", "/dev/ttyAMA0", "1000000")
print(m.send_command("get_coords"))
4 changes: 2 additions & 2 deletions demo/REMADE.md → demo/SOCT_REMADE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# 使用说明
## 使用说明
* "Client.py"是客户端的样例,使用在电脑中
* "Servo.py"是服务器端的执行文件,使用前要修改对应的ip地址信息,防止设备无法连接
* "Client.py"是客户端的样例,使用在你的电脑中运行
* "Servo.py"是服务器端的执行文件,在机械臂中运行
## 参考内容
* [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)

Expand Down
Loading

0 comments on commit 21afccc

Please sign in to comment.