Exemple #1
0
    elif state == "CONNECTED":
        print "Server:-- Connected to", msg


def readData(port=0):
    if port == 0:
        adc_address = 0x48
    elif port == 1:
        adc_address = 0x4D
    rd = bus.read_word_data(adc_address, 0)
    data = ((rd & 0xFF) << 8) | ((rd & 0xFF00) >> 8)
    data = data >> 2
    return data


def setup():
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(P_BUTTON, GPIO.IN)


print "starting..."
setup()
bus = smbus.SMBus(1)
server = TCPServer(port, stateChanged=onStateChanged)
while GPIO.input(P_BUTTON) == GPIO.LOW:
    if server.isConnected():
        v = readData()
        server.sendMessage(str(v))
        time.sleep(dt)
server.terminate()
print "Server terminated"
Exemple #2
0
    info = "n: %d; k: %d; pi: %f" % (n, k, pi)
    totresult.setValue(info)


local_k = 0
local_n = 0
remote_k = 0
remote_n = 0
port = 5000
server = TCPServer(port, stateChanged=onStateChanged)
showStatusDialog()
local.setValue("Waiting for connection...")
locresult.setValue("(n/a)")
remresult.setValue("(n/a)")
totresult.setValue("(n/a)")
while not server.isConnected() and not dlg.isDisposed():
    continue
if dlg.isDisposed():
    server.terminate()

local.setValue("Working...")
n = 0
k = 0
startTime = time.clock()
while not dlg.isDisposed() and server.isConnected():
    zx = random.random()
    zy = random.random()
    if zx * zx + zy * zy < 1:
        k += 1
    n += 1
    if n % sliceSize == 0: