Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to use Select function call in python . Inside input list i have given socketFd & serialFd

What I have tried:

import select
import socket
import sys
import Queue
import serial

try :
    server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    server.connect(("192.168.10.109",2404))
    serFd = serial.Serial()
    serFd.baudrate = 115200
    serFd.port = "COM6"
    serFd.open()
    
    inputs = [ server,serFd]
    outputs = [ ]
    print type(server)
    print type(serFd)
except Exception as e :
    print "Exception : ",e
    
while inputs:
    try :
        readable, writable, exceptional = select.select(inputs, outputs, inputs)
    except Exception as e :
        print "select Exception : ",select.error
        break
    
    try :
        for s in readable :
            if s is server:
                print "s is : sockFd"
                data = s.recv(1024)
                print data
            elif s is serFd :
                print "s is : serFd"
                data1 = serFd.readline()
                print data1
    except Exception as e :
        print "Exception : ",e
        break
Posted
Comments
Richard MacCutchan 28-Jul-18 4:14am    
What is the question?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900