Пример #1
0
 def connect(self):
     """
     Creates a serial port.
     """
     if platform.system() == 'Windows':
         self.port = serialwin32.Serial(
             self.port_name,
             baudrate=9600,
             parity=serial.PARITY_EVEN,
             stopbits=serial.STOPBITS_ONE,
             bytesize=serial.SEVENBITS,
             writeTimeout=0,
             timeout=self.timeout / 2,
             rtscts=False,
             dsrdtr=False,
             xonxoff=False,
         )
     else:
         self.port = serial.Serial(
             self.port_name,
             baudrate=9600,
             parity=serial.PARITY_EVEN,
             stopbits=serial.STOPBITS_ONE,
             bytesize=serial.SEVENBITS,
             writeTimeout=0,
             timeout=self.timeout / 2,
             rtscts=False,
             dsrdtr=False,
             xonxoff=False,
         )
def serialComm(filepath: str = "",
               apikey: str = "",
               port: str = "COM7",
               baudrate: int = 115200):
    with serial.Serial(port=port, baudrate=baudrate) as ser:
        while 1:
            # If there is incoming connection
            if ser.inWaiting() > 0:
                date = datetime.now().strftime("%Y.%m.%d %H:%M:%S")
                # Write the recieved data to the given file
                with open(filepath, "a") as f:
                    f.write(f"date:{date};{ser.readline()}")
Пример #3
0
 def IceSend(self, CommandInput):
     '''Function that sends a serial string command to ICE Box 
     Input: ICE Box Number[int], ICE Slot Number[int], CommandInput[str]
     Output: None (unless print line uncommented)/Read buffer always emptied!
     Note 1: Enter a slot number outside range(1-8) and function sends command directly
     to master board (ex. '#PowerOff' Command)
     Note 2: COM Port is opened/closed each time funciton is run'''
     
     #Open Port w/ ICE COM Default Settings
     IceSer = serial.Serial(port='COM'+str(int(self.BoxNum)),baudrate=115200,timeout=self.IceTimeout,parity='N',stopbits=1,bytesize=8)
     self.wait(.001)
     
     #Define Command and Send (perform read after each command to maintain synchronicity)
     if int(self.SlotNum) in range(1,9): #If a Valid Slot Number is input, send command to slot num
         #Define Commands        
         MasterCommand = str('#slave ' + str(int(self.SlotNum)) + '\r\n')
         SlaveCommand = str(str(CommandInput) + '\r\n')
         
         #Send Commands/Close Port
         IceSer.write(MasterCommand.encode())
         self.wait(self.IceDelay)
         IceOutputSlave = IceSer.read(self.IceByteRead).decode() #Read Buffer
         self.wait(self.IceDelay)
         IceSer.write(SlaveCommand.encode())
         self.wait(self.IceDelay)
         IceOutputReturn = IceSer.read(self.IceByteRead).decode() #Read Buffer
         self.wait(self.IceDelay)
         IceSer.close() #Close COM Port
 
         #Return Output       
         return IceOutputReturn
         print( ' ')
         print( 'Master Board Return: ', IceOutputSlave)
         print( 'Slave Board Return: ', IceOutputReturn)
         7
     else: #Command sent only to Master Board (preceding '#', no slot num to specify)
         #Define Command        
         MasterCommand = str('#' + str(CommandInput) + '\r\n')
         
         #Send Commands/Close Port
         IceSer.write(MasterCommand)
         self.wait(self.IceDelay)
         IceOutputReturn = IceSer.read(self.IceByteRead) #Read Buffer
         self.wait(self.IceDelay)
         IceSer.close() #Close COM Port
         
         #Return Output
         return IceOutputReturn
         print( ' ')
         print( 'Master Board Return: ', IceOutputReturn)
Пример #4
0
 def __init__(self, comNum):
     '''
     Initatizes the device
     Input: COM number [int]
     Output: None
     '''
     self.IceTimeout = .1  #Communication Timeout (seconds)
     self.IceByteRead = 256  #Number of bytes to read on ser.read()
     self.IceDelay = .01  #Delay in seconds after sending Ice Command to ensure execution
     self.comNum = int(comNum)
     try:
         self.IceSer = serial.Serial(port='COM' + str(int(self.comNum)),
                                     baudrate=115200,
                                     timeout=self.IceTimeout,
                                     parity='N',
                                     stopbits=1,
                                     bytesize=8)
     except:
         print("Could not open ICE on COM" + str(comNum))
     return None
Пример #5
0
#define END_FLASH_KEY                 0xCC
FLASH_NEW_APP_KEY = 0xAA
START_OF_FRAME_KEY = 0xBB
END_FLASH_KEY = 0xCC
#define FLASH_NEW_APP_SIZE            0X13
#define FLASH_WRITE_SECTOR_SIZE       0X0B+(4*MAX_DATA_SIZE)
#define RESPOND_FRAME_SIZE            0x04
#define END_FLASH_SIZE                0x04
FLASH_NEW_APP_SIZE = 0X10
FLASH_WRITE_SECTOR_SIZE = 0X0C + (MAX_DATA_SIZE)
RESPOND_FRAME_SIZE = 0x04
END_FLASH_SIZE = 0x04
DUMMY_BYTE = 0
##########################################################################################################
port = "COM29"
ser = serialwin32.Serial(port, 9600)
file = open(sys.argv[1], "rb")
elf_Handler = ELFFile(file)
Header = elf_Handler.header  #elf file header
Magic = Header.e_ident['EI_MAG']  #magic number
EntryPoint = Header.e_entry  #entry point
program_header_number = elf_Handler.num_segments(
)  #number of segments in the elf file
elf_Class = elf_Handler.elfclass  #elf file class
segments_header = []
segments = []
Req_num = 0


#Verification function
def verify_Elf_File():
Пример #6
0
from serial import serialwin32
from time import sleep
import requests

com = serialwin32.Serial('COM3', baudrate=115200, timeout=3)

# print (com.baudrate)
# print(com)

cmd_s = [0xBB, 0x00, 0x22, 0x00, 0x00, 0x22, 0x7E]

cmd_m = [0xBB, 0x00, 0x27, 0x00, 0x03, 0x22, 0x27, 0x10, 0x83, 0x7E]

# print(cmd)
com.flush()

clen = com.write(cmd_m)  #Write desired command at serial port

while 1:
    count = 0
    data = com.read(size=20)

    str1 = list(data)

    # list_output = ' '.join( [ "%02X" % ord( x ) for x in str1])
    list_output = ' '.join(["%02X" % ord(x) for x in str1])

    # list_output=[hex(ord(x))[2:] for x in str1]

    new_list = list_output.split()
    # print("new_list :: ", new_list[8:20])
Пример #7
0
 def __init__(self):
     Thread.__init__(self)
     self.daemon = True
     self.NMEA = NMEA.NMEA()
     self.ser = serial.Serial(SERIALPORT, BAUDRATE)
Пример #8
0
def Transport_Init(port, BaudRate, time):
    s = 0
    s = serialwin32.Serial(port, BaudRate, timeout=time)
    return s