pyserial read

Solutions on MaxInterview for pyserial read by the best coders in the world

showing results for - "pyserial read"
Ivan
21 Aug 2019
1//python
2
3import serial
4
5port = serial.Serial('COM5',9600)
6
7while( port.isOpen()):
8    comdata = int(input())
9
10    if(comdata == 1):
11        port.write(str.encode('1'))
12    elif(comdata == 2):
13        port.write(str.encode('2'))
14
15    elif (comdata == 3):
16        port.write(str.encode('3'))
17    elif (comdata == 4):
18        port.write(str.encode('4'))
19
20    elif (comdata == 5):
21        port.write(str.encode('5'))
22    elif (comdata == 6):
23        port.write(str.encode('6'))
24
25    elif (comdata == 7):
26        port.write(str.encode('7'))
27    elif (comdata == 8):
28        port.write(str.encode('8'))
29
30    else:
31        print('Invalid input!!!!')
32        
33// arduino
34
35const int LED1 = 8;
36const int LED2 = 9;
37const int LED3 = 10;
38const int LED4 = 11;
39char comdata;
40
41void setup() {
42
43  pinMode(LED1, OUTPUT);
44  pinMode(LED2, OUTPUT);
45  pinMode(LED3, OUTPUT);
46  pinMode(LED4, OUTPUT);
47  Serial.begin(9600);
48}
49
50void loop() {
51
52  if (Serial.available() > 0) {
53      comdata =(Serial.read());
54      
55    if (comdata == '1') {
56      Serial.println("LED1 is ON");
57      digitalWrite(LED1, HIGH);
58    }  
59    else if (comdata == '2') {
60      Serial.println("LED1 is OFF");
61      digitalWrite(LED1, LOW);
62    }
63    
64    
65    else if (comdata == '3' ) {
66      Serial.println("LED2 is ON");
67      digitalWrite(LED2, HIGH);
68    }
69    else if (comdata == '4' ) {
70      Serial.println("LED2 is OFF");
71      digitalWrite(LED2, LOW);
72    }
73    
74    else if (comdata == '5') {
75      Serial.println("LED3 is ON");
76      digitalWrite(LED3, HIGH);
77    }
78    else if (comdata == '6') {
79      Serial.println("LED3 is OFF");
80      digitalWrite(LED3, LOW);
81    }
82    
83    else if (comdata == '7') {
84      Serial.println("LED4 is ON");
85      digitalWrite(LED4, HIGH);
86    }
87    
88    else if (comdata == '8') {
89      Serial.println("LED4 is OFF");
90      digitalWrite(LED4, LOW);}
91
92
93    
94  }
95}
96
97
Louis
14 Nov 2018
1# https://pyserial.readthedocs.io/en/latest/pyserial_api.html
2# pip install pyserial
3import serial
4
5if __name__ == "__main__":
6    with serial.Serial('COM10') as serial_port:
7        line = serial_port.readline()
queries leading to this page
python view serial communicationhow to use python serial modulepython write to serial portpython serial 5caserial serail 28 29python install serial communicationpython and serial communicationserial ports pythonserial pythonpython serial withserial terminal pythoncreate a serial terminal on pythonpython2 serialserial port pythonserial python usingpython serial communication desktoppyserial read linepython serial interfaceserial 28 29 pythonpyserial readpython with serial 28 29 as portpython serial readline timeoutwrite over serial port pythonpython with serial pyserial com portserial port python examplpython serial write python serial port communication exampleread serial pythonpython serial communication linuxhow to use com port in pythonserial python communicationpython serial communication webpython uartpython com port stop read at 10047python serial read lineserial communication python windowsserial communication with pythonpyserial uart exampleserial communication in pythonpython com port stop read writecom port pythonseriall on pythonpython3 serial reading examplepython serial ir communication exampleread serial data pythonhow to use the serial module in python 3fpython to python serial communication without pyserialpython serial communication codepyserial readlinepython serial readlinepython serial exampleuart pythopython open serial line on produced idpyserial code examplepython pyserial examplepyserial listenuart pythonserial communication in oythonpython serialpython read 2fwrite serial portpyserial examplepyserial read serial port in linuxserial serial pythonserial python examplepython serial communication pyserialpython serial commandspython com portpyserial read examplepython serial port exampleserial read in pythonpython com port communicationpython serial serialserial in pythonhow to use serial port in pythonpython serial communication readreadline serial pythonprint in serial pythonpython serial communicationport com pythonlisten to a com port with pyserialread serial port pythonpyserialserials port pythonhow to get serial in pythonpython read serial with marjersreading serial string pyserialserial readline pythonpython serial communication serverserial communication pythonpython library for serial communicationserialport pythonpython serial readpython serial communication examplepython usb serial communicationpython serielpyserial tutorialpython ser readpython read from serial portpyserial read