bread, coffee and coding
통신 본문
|
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
|
# -*- coding: utf-8 -*-
import socket
import threading
def recv():
try:
recv_data = client_socket.recv(256).decode('utf-8')
except BlockingIOError:
return ""
return recv_data
def send(send_data):
client_socket.sendall(send_data.encode())
return send_data
def connect():
try:
client_socket.connect((ip, port))
print("connected")
except socket.error as e:
print(f"error while connecting : {e}")
return False
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.setblocking(False)
# 서버
ip = '127.0.0.1'
port = 9999
# recv_thread = threading.Thread(target=recv, args=(client_socket,))
# send_thread = threading.Thread(target=send, args=(client_socket,))
|
cs |
|
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
49
50
51
|
# -*- coding: utf-8 -*-
from socket import SocketIO
from cv2 import QRCodeDetector
import qr
import soc
import time
print('start')
soc.connect()
soc.send('CLIENT_TYPE=INSPECTION')
while True:
time.sleep(1)
print('waiting server...')
recv_data = soc.recv()
print(recv_data)
if recv_data == 'ack\n':
break
soc.send('PI_ONE_STATE=READY')
print('pi ready')
while True:
time.sleep(1)
try:
recv_data = soc.recv()
if recv_data == 'REQUEST_START\n':
if qr.check:
soc.send('PI_ONE_STATE=START')
else:
soc.send('PI_ONE_STATE=FAIL')
if recv_data == 'CAPTURE_START\n':
while True:
qrdata = qr.decode()
if qrdata == "QR_READ_ERROR":
continue
else:
temp = str(qrdata).split('|')[0]
if temp not in str(qr.decode()).split('|')[0]:
print("ok")
soc.send(qrdata)
else:
continue
except BlockingIOError as e:
print(e)
|
cs |
|
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
|
# -*- coding: utf-8 -*-
import cv2
import base64
import os
import numpy as np
from pyzbar import pyzbar
cap = cv2.VideoCapture(0)
def check():
try:
cap = cv2.VideoCapture(0)
if not cap.isOpened():
return False
else:
return True
except cv2.error as e:
print(e)
def decode():
retval, frame = cap.read()
retval, buffer = cv2.imencode('.jpg', frame)
decoded_objects = pyzbar.decode(frame)
converted_string = base64.b64encode(buffer)
if not decoded_objects:
print(decoded_objects)
return "QR_READ_ERROR"
else:
for obj in decoded_objects:
print(obj.data)
return f'<QR:{obj.data}|{converted_string.decode("utf-8")}>'
|
cs |
'The final team project' 카테고리의 다른 글
| 라즈베리파이 (0) | 2021.08.21 |
|---|