コード例 #1
0
ファイル: radium.py プロジェクト: RaymieF/amigos3
def send(message):
    try:
        port = ser('/dev/ttyS3')
        port.baudrate = 115200
        port.open()
        port.flushInput()
    except:
        print('Unable to open port')
        return
    port.write(message)
コード例 #2
0
ファイル: iridium.py プロジェクト: siar7178/amigos3
def read():
    try:
        port = ser('/dev/ttyS1')
        port.baudrate = 9600
        port.timeout = 60
        port.open()
    except:
        printf('Unable to open port')
        return None
    rev = port.read(port.inWaiting())
    return rev
コード例 #3
0
ファイル: radium.py プロジェクト: RaymieF/amigos3
def read(message):
    try:
        port = ser('/dev/ttyS3')
        port.baudrate = 115200
        port.open()
        port.flushInput()
    except:
        print('Unable to open port')
        return None
    rev = port.readline(message)
    return rev
コード例 #4
0
ファイル: gps_data.py プロジェクト: RaymieF/amigos3
 def __init__(self, *args, **kwargs):
     self.sequence = 1
     self.is_saved = False
     self.interval = 15
     self.timeout = 15
     try:
         self.port = ser('/dev/ttyS0')  # set the port
         self.port.baudrate = 115200  # set baudrate
         self.port.timeOut = None  # set port time out
     except:
         self.port = None
         print('Unable to setup port')
コード例 #5
0
 def __init__(self, comid):
     self.name = comid
     self.com = None
     self.alive = False
     try:
         self.com = ser(comid)
     except:
         self.com_not_alive_err(self.name)
     finally:
         if self.com:
             self.alive = True
         else:
             self.alive = False
コード例 #6
0
 def __init__(self, *args, **kwargs):
     self.cmd = {
         'binex':
         'out,,binex/{00_00,01_01,01_02,01_05,01_06,7E_00,7D_00,7F_02,7F_03,7F_04,7F_05}',
         'nmea':
         'out,,nmea/{GGA,GLL,GMP,GNS,GRS,GSA,GST,GSV,HDT,RMC,ROT,VTG,ZDA,UID,P_ATT}',
         'GPGGA': 'out,,nmea/GGA',
         'GPVTG': 'out,,nmea/VTG'
     }
     self.sequence = 1
     self.is_saved = False
     self.interval = 15
     self.timeout = 10
     try:
         self.port = ser('/dev/ttyS0')  # set the port
         self.port.baudrate = 115200  # set baudrate
         self.port.timeOut = None  # set port time out
     except:
         self.port = None
         print('Unable to setup port')
コード例 #7
0
ファイル: iridium.py プロジェクト: siar7178/amigos3
def send(message="Testing"):
    try:
        port = ser('/dev/ttyS1')
        port.baudrate = 9600
        port.open()
        iridium_on(1)
        sbd_on(1)
        sleep(1)
        iridium_off(1)
        enable_serial()
        sleep(1)
    except:
        printf('Unable to open port')
    else:
        port.write(message + '\r')
        printf('sent SBD message: {0} {1}'.format(message, '\r'))
        sleep(60)
    finally:
        disable_serial()
        sbd_off(1)
        iridium_off(1)
コード例 #8
0
ファイル: plot.py プロジェクト: HummusPrince/DLO-138_plotter
def acquire(comport='COM3'):

    p = ser(comport, 115200)

    print("Waiting for data.")

    while p.in_waiting == 0:
        sleep(0.25)

    print("Acquiring...")

    while True:
        tmp = p.in_waiting
        sleep(0.1)
        if tmp == p.in_waiting:
            break

    acquisition = [str(line, 'ascii') for line in p.read_all().split(b'\r\n')]

    p.close()

    print("Done")

    return acquisition
コード例 #9
0
ファイル: mc.py プロジェクト: mjdesrosiers/SurveyBot
import Adafruit_BBIO.UART as uart
from serial import Serial as ser
import time

#P9_13 => Serial4_Tx
#P9_11 => Serial4_Rx
uart.setup("UART4")
s = ser(port="/dev/ttyO2", baudrate=9600, timeout=1)
s.close()
s.open()

M1_OFFSET = 1
M2_OFFSET = 128

MIN_SIG = 0
MAX_SIG = 126

def make_msg(speed, motor_offset):
    return speed + motor_offset

while (True):
    for SIGNAL in range(MIN_SIG, MAX_SIG):
        msg1 = make_msg(SIGNAL, M1_OFFSET)
        msg2 = make_msg(SIGNAL, M2_OFFSET)
        s.write(chr(msg1))
        s.write(chr(msg2))
        print("writing value of '{}'".format(msg1))
        print("writing value of '{}'".format(msg2))
        time.sleep(0.2)
コード例 #10
0
#!/usr/bin/python

# moculos 
from sqlite3 import connect as con
from serial import Serial as ser

# constantes de la comunicacion serial
port = 0
bd = 2400

# establecer conemunicacion serial
s = ser(port,bd)

# conexion con la base de datos
conn = con('lab06BD.db')
c = conn.cursor()

# condiconal y aumentador
salir = False
n = 1

# loop
while not salir:
	recv = s.readline()
	if recv != null:
		if recv == "salir":
			con.close()
			s.close()
			salir = True
		else:
			sql = "INSERT INTO T_Datos VALUES(?, ?, date('now'))"
コード例 #11
0
from serial import Serial as ser

port = raw_input("/dev/ttyUSB")
baud = raw_input("Baudrate: ")

dev = ser("/dev/ttyUSB" + port, baudrate=baud)

while True:
    dev.flush()

    dev.write("RID\n")

    try:
        print "%s" % dev.readline()
    except KeyboardInterrupt:
        print "Failed to receive"

    cont = raw_input("Continue? (y/n)")

    if cont == "n":
        break

dev.close()
コード例 #12
0
from serial import Serial as ser

p = ser('/dev/ttyAMA0', 115200, timeout=1)

if p.read() == b'':
    print("LIDAR.py: no LIDAR serial connection.")


def getFrame():
    frame = []
    header = b''
    while True:
        header = p.read(2)
        if int.from_bytes(header, byteorder='big') == 22873:
            for a in range(7):
                frame.append(int.from_bytes(p.read(), byteorder='big'))
            if frame[6] == (sum(frame[0:6]) + 89 + 89) % 256:
                return frame
            else:
                frame = []


def getDist(frame=None):
    if frame is None:
        frame = getFrame()
    dist = bytes([frame[3], frame[2]])
    return int.from_bytes(dist, byteorder='big')
コード例 #13
0
def main():
    with ser() as Serial:
        Serial.baudrate = 115200
        Serial.port = argv[1]
        Serial.open()
    if (!Serial.is_open):
        print("ERROR :: Serial commincation fail.")
        print("Cannot connect to %s." % (argv[1]))
        exit()
        
    Serial.readline()
    Serial.write("Next");
    intro = '''G-Code Interpreter V_1.0
               Type "help" for more information.'''
    ready_symbol = ">>$ "

    print (intro)

    # Program loop
    while (True):

        # Wait for a microcontroller to be ready for next command.
        while(Serial.readline() != "ready\r\n"):
            pass

        # Get the next command, remove any leading spaces, then split by spaces.
        command = raw_input(ready_symbol)
        command = command.strip()
        command = command.split(" ")

        if (command[0] == "exit"):
            exit();

        # Prints a list of all possible commands.
        elif (command[0] == "help"):
            print ('''
    The following are a list of possible commands and their parameters ::

    exit           ::  Exits the program.

    ## INFORMATION ##
    help           ::  List of possible commands
    version        ::  Current version of G-Code Interpreter.

    ## WORKING WITH FILES ##
    run_gcode      ::  Runs the gcode file of name provided.
                 >>  [filename].gcode

    ## MOTOR COMMANDS ##
    enable_motors  ::  Enable motors, constant power. (Default)
    disable_motors ::  Disable motors, no power.
    move_to        ::  Moves endpoint of CNC.
                 >>  X[position] - X Position(float 0.00-MAX DEPTH)
                 >>  Y[position] - Y Position(float 0.00-MAX WIDTH)
                 >>  Z[position] - Z Position(float 0.00-MAX HEIGHT)
                 >>  F[percent]  - Feedrate  (int 0-100)
    rmove_to       ::  Moves endpoint of CNC to XYZ position at full speed.
                 >>  X[position] - X Position(float 0.00-MAX DEPTH)
                 >>  Y[position] - Y Position(float 0.00-MAX WIDTH)
                 >>  Z[position] - Z Position(float 0.00-MAX HEIGHT)
    where          ::  Returns X, Y, Z position and current feedrate.
    home           ::  Sends the endpoint home.
                 >>  F[percent] - Feedrate(int 0-100)
    units          ::  Sets the units.
                 >>  mm   - Millimeters
                 >>  inch - Inches
    absolute       ::  Absolute positioning, relative to home position.
    relative       ::  Relatvie positioning, relative to current position.
            ''')

        # Prints the current version
        elif (command[0] == "version"):
            print("Version %.1f" % (VERSION))

        # Runs G-Code of given file.
        elif (command[0] == "run_gcode"):
            if (len(command) != 2):
                print ("ERROR :: Missing file name")
                continue
            file_name = command[1]
            try:
                gcode_file = open(file_name,"r")
            except:
                print ("ERROR :: Couldn not open %s." % (file_name))
            for i, _ in enumerate(gcode_file):
                pass
            i+=1
            gcode_file.seek(0, 0)
            try:
                for index, line in enumerate(gcode_file):
                    Serial.write(line+'\n')
                    done = (float(index)/(i))*100
                    stdout.write("File read percentage: %.2f%% \r"% (done))
                    stdout.flush()
                    if (index < i-1):
                        while(Serial.readline() != "ready\r\n"):
                            pass
                print("File read percentage :: 100.00% <<SUCCESS>>\r")
            except:
                print("File read percentage :: %.2f%% <<FAIL>>\r"% (done))
            print("Closing file         :: %s" % (file_name))
            gcode_file.close()

        # Linear to given X Y Z location at F feedrate.
        elif (command[0] == "move_to"):
            cmd = command[1:]
            Serial.write("G01 " + ' '.join(cmd))

        # Rapid linear move to given X Y Z location.
        elif (command[0] == "rmove_to"):
            cmd = command[1:]
            Serial.write("G00 " + ' '.join(cmd))

        # Prints where the endpoint in located.
        elif (command[0] == "where"):
            Serial.write("M114")
            print (Serial.readline())

        # Sends the endpoint to the home position
        elif (command[0] == "home"):
            feed = command[1:]
            Serial.write("G28 " + ''.join(feed))

        # Sets units to either mm or inches
        elif (command[0] == "set_units"):
            units = command[1]
            units = units.replace(" ","")
            if (units == "mm"):
                Serial.write("G21")
            elif (units == "inch"):
                Serial.write("G00")
            else:
                print("ERROR :: Incorrect input parameter")
                print("ERROR :: Possible inputs are")
                print("      >> mm")
                print("      >> inch")

        # Sets coordinates to absolute (relative to origin)
        elif (command[0] == "absolute"):
            Serial.write("G90")

        # Sets coordinates to absolute (relative to current position)
        elif (command[0] == "relative"):
            Serial.write("G91")
コード例 #14
0
ファイル: GPS_Sensor.py プロジェクト: mjdesrosiers/SurveyBot
 def init_uart(self):
     uart.setup("UART4")
     self.port = ser(port="/dev/ttyO4", baudrate=57600, timeout=1)