Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

send serial commands in python

import time
import serial

# configure the serial connections (the parameters differs on the device you are connecting to)
ser = serial.Serial(
    port='/dev/ttyUSB1',
    baudrate=9600,
    parity=serial.PARITY_ODD,
    stopbits=serial.STOPBITS_TWO,
    bytesize=serial.SEVENBITS
)

ser.isOpen()

print 'Enter your commands below.
Insert "exit" to leave the application.'

input=1
while 1 :
    # get keyboard input
    input = raw_input(">> ")
        # Python 3 users
        # input = input(">> ")
    if input == 'exit':
        ser.close()
        exit()
    else:
        # send the character to the device
        # (note that I happend a 
 carriage return and line feed to the characters - this is requested by my device)
        ser.write(input + '
')
        out = ''
        # let's wait one second before reading output (let's give device time to answer)
        time.sleep(1)
        while ser.inWaiting() > 0:
            out += ser.read(1)

        if out != '':
            print ">>" + out
Comment

PREVIOUS NEXT
Code Example
Python :: tkinter canvas text size 
Python :: python PyDrive service account credentials 
Python :: range of y & x in scatter 
Python :: remote python running line by line visual code 
Python :: python for web development 
Python :: pandas astype str still object 
Python :: python enum to int 
Python :: read cells in csv with python 
Python :: slicing in python 
Python :: Replace all the empty rows in the column with the value that you have identified 
Python :: replace multiple column values pandas 
Python :: find keys to minimum value in dict 
Python :: pandas datetime to unix timestamp 
Python :: how get 1st column in all rows of a 2d matrix in python 
Python :: how to get pytroch model layer name 
Python :: random normal 
Python :: panda python 
Python :: Seaborn python for stacked column 
Python :: purpose of meta class in django 
Python :: str to datetime time 
Python :: check if number is prime python 
Python :: reset index python 
Python :: iterate over a set python 
Python :: character in string python 
Python :: intersect index in python 
Python :: how to find the cosine in python 
Python :: properties of tuples in python 
Python :: opening files in python 
Python :: convert a string into a list 
Python :: how to show bar loading in python in cmd 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =