Professional Documents
Culture Documents
Etching Pathways Labview and Raspberry Pi TCP Ip Communications Codepdf
Etching Pathways Labview and Raspberry Pi TCP Ip Communications Codepdf
# Client Program
import socket
import threading
import os
import sys
import select
from time import sleep
class Transmit(threading.Thread):
def run(self):
# Sending data to the server
#print('Transmit started')
global s # connection
global threadRunning
while(threadRunning):
# Read text with 1 sec timeout
i, o, e = select.select( [sys.stdin], [], [], 1 )
if(i):
string = sys.stdin.readline().strip() + '\r\n'
byteArray = bytearray(string, "utf-8") # Convert string into a b$
s.sendall(byteArray)
class Receive(threading.Thread):
def run(self):
# Receiving data from the server
#print('Receive started')
global s # connection
global threadRunning
while(threadRunning):
# Use 1 second timeout on receive
ready = select.select( [s], [], [], 1 )
if(ready[0]):
data = s.recv(1024).strip()
if(len(data) == 0): # Connection closed by server
threadRunning = False
else:
print('Received:', data.decode("utf-8")) # Converts thhe receive$
sleep(0.1)
os.system('clear')
print('Connection with server established')
try:
http://etchingpathways.blogspot.it/2013/09/labview-and-raspberry-pi-tcpip.html?sf22430516=1 1/2
18/2/2014 Etching Pathways: LabVIEW and Raspberry Pi TCP/IP Communications
print(34 * '-')
print(" M A I N - M E N U")
print(' Press CTRL+C to close connection')
print(34 * '-')
# Create instance of class
threadRunning = True
transmit = Transmit()
receive = Receive()
# Start class
transmit.start()
receive.start()
while(threadRunning):
sleep(0.1)
finally:
s.close()
http://etchingpathways.blogspot.it/2013/09/labview-and-raspberry-pi-tcpip.html?sf22430516=1 2/2