Пример #1
0
 def record_data(self):
     '''
     Description:
     ------------
     Begin recording and streaming (if any streaming options are enabled)
     '''
     
     if not self.ui.recording.isChecked():
         self.disable_inputs()
         
         if self.ui.live_usb.isChecked():
             self.usb_port = self.ui.usb_ports.currentText()
             self.usb_baud = int(self.ui.usb_baud.currentText())
             self.transfer = transfer.SerialTransfer(self.usb_port, self.usb_baud)
         
         if self.ui.mqtt.isChecked():
             self.mqtt_sub_th = MqttSubThread(self)
             self.mqtt_sub_th.start()
             self.mqtt_sub_th.update_names.connect(self.update_player_names)
             self.mqtt_sub_th.send_stream_data.connect(self.send_to_stream)
         
         if self.ui.live_telem.isChecked():
             self.stream_th = StreamThread(self)
             self.stream_th.start()
         
         self.rec_th = RecordThread(self)
         self.rec_th.start()
         self.rec_th.send_stream_data.connect(self.send_to_stream)
         self.rec_th.send_overlay_data.connect(self.update_overlay)
         
         self.ui.recording.setChecked(True)
Пример #2
0
def connect():
    # HOST_COMM_PORT, DEBUG_PORT = find_devices() ??not working
    HOST_COMM_PORT = '/dev/ttyUSB1'
    link = txfer.SerialTransfer(HOST_COMM_PORT)
    link.open()
    # DEBUG_COMM_INSTANCE = serial.Serial(DEBUG_PORT, 115200)

    return link
def connect_to_arduino(comport, motor0_enable, motor0_direction,
                       motor0_position, motor1_enable, motor1_direction,
                       motor1_position, motor2_enable, motor2_direction,
                       motor2_position, motor3_enable, motor3_direction,
                       motor3_position):
    try:
        print(f"Connecting to {comport}")
        link = txfer.SerialTransfer(comport)

        link.open()
        time.sleep(1)  # allow some time for the Arduino to completely reset

        # reset send_size
        send_size = 0

        # Send a list
        list_ = [
            motor0_enable, motor0_direction, motor0_position, motor1_enable,
            motor1_direction, motor1_position, motor2_enable, motor2_direction,
            motor2_position, motor3_enable, motor3_direction, motor3_position
        ]
        list_size = link.tx_obj(list_)
        send_size += list_size

        # Transmit all the data to send in a single packet
        link.send(send_size)
        print("Message sent...")

        # Wait for a response and report any errors while receiving packets
        while not link.available():
            if link.status < 0:
                if link.status == -1:
                    print('ERROR: CRC_ERROR')
                elif link.status == -2:
                    print('ERROR: PAYLOAD_ERROR')
                elif link.status == -3:
                    print('ERROR: STOP_BYTE_ERROR')

        # Parse response list
        ###################################################################
        rec_list_ = link.rx_obj(obj_type=type(list_),
                                obj_byte_size=list_size,
                                list_format='i')

        print(f'SENT: {list_}')
        print(f'RCVD: {rec_list_}')

        link.close()
        return rec_list_

    except KeyboardInterrupt:
        link.close()

    except:
        import traceback
        traceback.print_exc()
        link.close()
Пример #4
0
 def __init__(self, door):
     try:
         print("Initializing...")
         self.door = door
         self.link = serial.SerialTransfer(self.door)
         self.link.open()
         sleep(3)
         print("Ready")
         self.error = False
     except Exception as e:
         self.error = True
Пример #5
0
    def __init__(self, com):
        self.com = com

        self.link = txfer.SerialTransfer(com)

        self.list_size = 0

        self.list_ = []

        self.link.open()
        # allow some time for the Arduino to completely reset
        time.sleep(2)
Пример #6
0
 def create_io_ACM1_1(self):
     try:
         self.link_temp = txfer.SerialTransfer('/dev/ttyACM1')
         self.link_temp.open()
         time.sleep(
             2)  # allow some time for the Arduino to completely reset
         print(
             "ACM1 arduino serial transfer link is connected successfully!")
         self.recognize_board()
     except KeyboardInterrupt:
         try:
             self.link_temp.close()
             print(
                 "ACM1 arduino serial transfer connection fails due to interruption!"
             )
         except:
             print(
                 "ACM1 arduino serial transfer connection fails due to unknown reason!"
             )
Пример #7
0
def rosinfo_server():
    #datalink = Serial(DEVICE, baudrate=BAUDRATE, timeout=2)
    link = txfer.SerialTransfer('/dev/ttyACM0')
    link.open()

    while not rospy.is_shutdown():
        #command_string = datalink.readline()
        #cmd_string = input("command: ")
        #cmd = cmd_string[0:len(cmd_string)-2].decode()
        time.sleep(2)
        dummy = 1
        size = link.tx_obj(int(dummy), val_type_override='i')
        link.send(size, ROS_ALIVE_ID)

        size = 0
        size = link.tx_obj(cmd_vel.x, start_pos=size)
        size = link.tx_obj(cmd_vel.y, start_pos=size)
        size = link.tx_obj(cmd_vel.z, start_pos=size)
        size = link.tx_obj(cmd_vel.yaw, start_pos=size)
        size = link.tx_obj(cmd_vel.pitch, start_pos=size)
        size = link.tx_obj(cmd_vel.roll, start_pos=size)
        link.send(size, CMD_VEL_ID)

        size = 0
        size = link.tx_obj(int(manual_auto_mode),
                           start_pos=size,
                           val_type_override='i')
        link.send(size, PACKET_ID_WHEELE_MODE)

        size = 0
        size = link.tx_obj(nav_state, start_pos=size)
        link.send(size, PACKET_ID_NAV_STATE)

        size = 0
        size = link.tx_obj(heading.yaw, start_pos=size)
        link.send(size, PACKET_ID_CUR_POSE)
Пример #8
0
            play_mp3(mixer, voice_command)
    
    elif link.status < 0:
        if link.status == txfer.CRC_ERROR:
            print('ERROR: CRC_ERROR')
        elif link.status == txfer.PAYLOAD_ERROR:
            print('ERROR: PAYLOAD_ERROR')
        elif link.status == txfer.STOP_BYTE_ERROR:
            print('ERROR: STOP_BYTE_ERROR')
        else:
            print('ERROR: {}'.format(link.status))


if __name__ == '__main__':
    try:
        link = txfer.SerialTransfer(ARDUINO_PORT)
        link.open()
        
        pygame.init()
        clock = pygame.time.Clock()
        mixer.init()
        
        play_mp3(14)
        
        sleep(2.5)
        
        while not joystick.get_count():
            pass
            
        gamepad = pygame.joystick.Joystick(0)
        
Пример #9
0
        suffix      - Optional  : suffix string (Str)
        decimals    - Optional  : positive number of decimals in percent complete (Int)
        length      - Optional  : character length of bar (Int)
        fill        - Optional  : bar fill character (Str)
        printEnd    - Optional  : end character (e.g. "\r", "\r\n") (Str)
    """
    filledLength = int(length * iteration // total)
    bar = fill * filledLength + '-' * (length - filledLength)
    print('\r%s |%s| %s/%s %s' % (prefix, bar, iteration, total, suffix),
          end=printEnd)
    # Print New Line on Complete
    if iteration == total:
        print()


link = txfer.SerialTransfer("COM3", baud=115200)


def main():
    try:
        instruction = sys.argv[1] if len(sys.argv) > 1 else "read"

        if instruction == "write":
            link.open()
            time.sleep(
                2)  # allow some time for the Arduino to completely reset

            fileName = sys.argv[2] if len(sys.argv) > 2 else "EEPROMdata"
            fileStartPage = int(sys.argv[3]) if len(sys.argv) > 3 else 0
            fileEndPage = 0
            if len(sys.argv) > 4:
Пример #10
0
import time
from pySerialTransfer import pySerialTransfer as txfer

if __name__ == '__main__':
    try:
        link = txfer.SerialTransfer('COM3')

        link.open()
        time.sleep(2)  # allow some time for the Arduino to completely reset

        while True:
            sendSize = 0

            ###################################################################
            # Send a string
            ###################################################################
            print("Ready to enroll a fingerprint")
            userInput = input(
                "Enter the ID # (from 1 to 127) of the enrollment: ")

            command = (int(userInput) % 127) + 1
            commandSize = link.tx_obj(command, sendSize) - sendSize
            sendSize += commandSize

            ###################################################################
            # Transmit all the data to send in a single packet
            ###################################################################
            link.send(sendSize)

            ###################################################################
            # Wait for a response and report any errors while receiving packets
Пример #11
0
        suffix      - Optional  : suffix string (Str)
        decimals    - Optional  : positive number of decimals in percent complete (Int)
        length      - Optional  : character length of bar (Int)
        fill        - Optional  : bar fill character (Str)
        printEnd    - Optional  : end character (e.g. "\r", "\r\n") (Str)
    """
    filledLength = int(length * iteration // total)
    bar = fill * filledLength + '-' * (length - filledLength)
    print('\r%s |%s| %s/%s %s' % (prefix, bar, iteration, total, suffix),
          end=printEnd)
    # Print New Line on Complete
    if iteration == total:
        print()


link = txfer.SerialTransfer("COM3")
if __name__ == '__main__':
    try:
        instruction = sys.argv[1] if len(sys.argv) > 1 else "read"

        if instruction == "write":
            link.open()
            time.sleep(
                2)  # allow some time for the Arduino to completely reset

            fileName = sys.argv[2] if len(sys.argv) > 2 else "EEPROMdata"
            fileStartPage = int(sys.argv[3]) if len(sys.argv) > 3 else 0
            fileEndPage = 0
            if len(sys.argv) > 4:
                if sys.argv[4] == "end":
                    fileEndPage = 2**10
Пример #12
0
	print("Could not open video device")

width = 640
height = 480
#To set the resolution
cap.set(cv2.CAP_PROP_FRAME_WIDTH,width);
cap.set(cv2.CAP_PROP_FRAME_HEIGHT,height);
#find port where arduino is located
ports = list(serial.tools.list_ports.comports())
port = "";
for p in ports:
        print(p.description)
        if "Arduino" in p.description or "CH340" in p.description:
                print("Arduino detected on ", p.device)
                port = p.device
                link = txfer.SerialTransfer(port, baud=115200)
link.open()
time.sleep(2) # allow some
for a in range(6):
	link.txBuff[a] = 50
	link.txBuff[2] = 20

circle_gen = False
xyr = [0,0,0]
cvxyr = [0,0,0]
angle = 100

while (True):
	ret, frame = cap.read()
	overlay = frame.copy();
	gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
Пример #13
0
import time
from pySerialTransfer import pySerialTransfer as txfer
from get_serial_port import get_port

BATCH_SIZE = 28
DEBUG = False

link = None

# def initialize_connection():

# get serial port
port = get_port()

try:
    link = txfer.SerialTransfer(port)

    link.open()
    time.sleep(2)  # allow some time for the Arduino to completely reset

except KeyboardInterrupt:
    try:
        link.close()
    except:
        pass

except:
    import traceback
    traceback.print_exc()

    try:
Пример #14
0
import platform
import struct
import time
from pySerialTransfer import pySerialTransfer as txfer


def clear():
    os.system('cls' if os.name == 'nt' else 'clear')


if __name__ == '__main__':
    try:
        clear()

        if platform.system() == 'Linux':
            link = txfer.SerialTransfer('/dev/ttyACM0', 115200)
        elif platform.system() == 'Darwin':
            link = txfer.SerialTransfer('/dev/cu.usbmodem14101', 115200)
        else:
            link = txfer.SerialTransfer('COM4', 115200)

        if link.open():
            time.sleep(0)

            while True:
                while not link.available():
                    if link.status < 0:
                        if link.status == txfer.CRC_ERROR:
                            print('ERROR: CRC_ERROR')
                        elif link.status == txfer.PAYLOAD_ERROR:
                            print('ERROR: PAYLOAD_ERROR')
Пример #15
0
import time
from pySerialTransfer import pySerialTransfer as txfer

link = txfer.SerialTransfer('/dev/cu.usbmodem141201')

link.open()
time.sleep(2) # allow some time for the Arduino to completely reset

while True:
    send_size = 0
    
    #send a float
    float_ = 5.234
    float_size = link.tx_obj(float_, send_size) - send_size
    send_size += float_size
    
    #transmit float
    link.send(send_size)
    
    #wait for response
    while not link.available():
        if link.status < 0:
            if link.status == txfer.CRC_ERROR:
                print('ERROR: CRC_ERROR')
            elif link.status == txfer.PAYLOAD_ERROR:
                print('ERROR: PAYLOAD_ERROR')
            elif link.status == txfer.STOP_BYTE_ERROR:
                print('ERROR: STOP_BYTE_ERROR')
            else:
                print('ERROR: {}'.format(link.status))
    
Пример #16
0
from WarThunder import telemetry
from pySerialTransfer import pySerialTransfer as txfer

if __name__ == '__main__':
    try:
        telem = telemetry.TelemInterface()

        while True:
            try:
                link = txfer.SerialTransfer('COM16')
                link.open()
                break

            except:
                pass

        while True:
            if telem.get_telemetry():
                pitch = telem.basic_telemetry['roll']
                roll = telem.basic_telemetry['pitch']
                hdg = telem.basic_telemetry['heading']
                alt = telem.basic_telemetry['altitude']
                lat = telem.basic_telemetry['lat']
                lon = telem.basic_telemetry['lon']
                ias = telem.basic_telemetry['IAS']
                flaps = telem.basic_telemetry['flapState']
                gear = telem.basic_telemetry['gearState']

                sendSize = 0
                sendSize = link.tx_obj(pitch,
                                       start_pos=sendSize,
Пример #17
0
import datetime
import time
import pymongo
import json
from pySerialTransfer import pySerialTransfer as txfer
from python.DBInit import ActCol, AlarmCol, ButtonCol, LogicCol, SetCol, FlagCol

if __name__ == '__main__':
    try:
        while True:
            try:
                stLink = txfer.SerialTransfer('COM12', baud=250000)
                print("here")
                stLink.open()

                #Al primo giro richiede ad Ino tutti i dati di HMI
                boFirstRound = True
                #Dopodichè manda tutti i Setpoint aggiornati
                boRefreshInoData = False
                #inizializzo la flag di coonessione ok con l'arudino a false
                boConnectionOK = True
                #numero di eventi prima che il watchdog resetti il comando dei button
                inWdN = 10

                time.sleep(
                    2)  # allow some time for the Arduino to completely reset

                while boConnectionOK:

                    ###################################################################
                    # Wait for a response and report any errors while receiving packets
import time
from pySerialTransfer import pySerialTransfer as txfer

if __name__ == '__main__':
    try:
        link = txfer.SerialTransfer('/dev/ttyACM0')

        link.open()
        time.sleep(2)  # allow some time for the Arduino to completely reset

        while True:
            time.sleep(2)
            send_size = 0

            ###################################################################
            # Send a list
            ###################################################################
            list_ = [1, 3]
            list_size = link.tx_obj(list_)
            send_size += list_size

            ###################################################################
            # Send a string
            ###################################################################
            str_ = 'hello'
            str_size = link.tx_obj(str_, send_size) - send_size
            send_size += str_size

            ###################################################################
            # Send a float
            ###################################################################
Пример #19
0
    tmp_list = []
    for val in range(count):
        tmpStr = link.rx_obj(obj_type=type(val),
                             obj_byte_size=INT_SIZE,
                             list_format='i',
                             start_pos=position * INT_SIZE)
        tmp_list.append(int(tmpStr))
        position = position + 1
    return tmp_list


# ================================================
if __name__ == '__main__':
    try:
        link = txfer.SerialTransfer(PORT)
        # List will always have 10 elements
        outList = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]

        link.open()
        time.sleep(2)  # allow some time for the Arduino to completely reset

        for x in range(100):
            inList = []

            list_size = send_list(outList)
            wait_for_available()

            inList = recv_list(10)

            ###########################################