def output_to_MC(self, data=list, baudrate=int):
     length = len(data)
     #Checks if the list is of length 4. If it isn't, immediately return
     if(length!=4):
         print("Invalid list size. Needed size of 4, you provided a list whose size is {}".format(length))
         return
     wiringpi.wiringPiSetup()
     #opens the Raspberry Pi's UART port, w/ a data transfer rate of
     #115200 bits/s
     serial = wiringpi.serialOpen('/dev/ttyS0', baudrate)
     #sleep a few seconds to make sure the port opens and sets connections
     #properly
     sleep(2)
    #signals to start data transmission, uses start of header char
     wiringpi.serialPuts(serial, chr(1).encode('ascii'))
     wiringpi.serialPuts(serial, data[0].encode('ascii'))
     for index in range(1, length, 1):
         #signals that the next data is being sent, uses start of text char
         wiringpi.serialPuts(serial, chr(2).encode('ascii'))
         #write the string data, as ascii, to the Raspberry Pi
         wiringpi.serialPuts(serial, data[index].encode('ascii'))
     #signals that data transmission is ending, uses end of transmission char
     wiringpi.serialPuts(serial, chr(4).encode('ascii'))
     #closes the serial port
     wiringpi.serialClose(serial)
     return
def Gpio_Intent(status, room):
    wiringpi.wiringPiSetupGpio()

    wiringpi.pinMode(18, 2)  # pwm mode = 2
    wiringpi.pwmSetMode(0)

    # pwmFrequency in Hz = 19.2e6 Hz / pwmClock / pwmRange.
    wiringpi.pwmSetRange(4096)
    wiringpi.pwmSetClock(4095)
    if status in STATUSON:
        wiringpi.pwmWrite(18, 4096)
        return statement('turning {} blue L E D'.format(status))
    elif status in STATUSOFF:
        wiringpi.pwmWrite(18, 0)
        return statement('turning {} blue L E D'.format(status))
    elif status in STATUSTOGGLE:
        wiringpi.pwmWrite(18, 2048)
        return statement('{}ing blue L E D'.format(status))
    elif status in STATUSCMD:
        serial = wiringpi.serialOpen('/dev/ttyAMA0', 9600)
        if status == 'a':
            wiringpi.serialPuts(serial, 'a')
        elif status == 'be':
            wiringpi.serialPuts(serial, 'b')
        elif status == 'see':
            wiringpi.serialPuts(serial, 'c')
        wiringpi.serialClose(serial)
        return statement(
            'Trying to send command ASCII character {}'.format(status))
    else:
        return statement('Sorry not possible.')
Exemple #3
0
def _serial(send=None):
    wiringpi.wiringPiSetup()
    serial = wiringpi.serialOpen('/dev/ttyAMA0', 9600)
    if send != None:
        wiringpi.serialPuts(serial, send)
        wiringpi.serialPutchar(serial, 3)
        wiringpi.serialClose(serial)
    else:
        char = ""
        asciinum = -1
        while (True):
            asciinum = wiringpi.serialGetchar(serial)
            if asciinum != -1 and asciinum != 3:
                char += chr(asciinum)
            elif asciinum == 3:
                break
        wiringpi.serialClose(serial)
        return char
    def output_to_MC(self, data=list):

        wiringpi.wiringPiSetup()
        #opens the Raspberry Pi's UART port, w/ a data transfer rate of
        #115200 bits/s
        serial = wiringpi.serialOpen('/dev/ttyS0', 115200)
        #sleep a few seconds to make sure the port opens and sets connections
        #properly
        sleep(2)
        #signals to start data transmission, uses start of header char
        wiringpi.serialPuts(serial, chr(1).encode('ascii'))
        wiringpi.serialPuts(serial, data[0].encode('ascii'))
        for index in range(1, len(data), 1):
            #signals that the next data is being sent, uses start of text char
            wiringpi.serialPuts(serial, chr(2).encode('ascii'))
            #write the string data, as ascii, to the Raspberry Pi
            wiringpi.serialPuts(serial, data[index].encode('ascii'))
        #signals that data transmission is ending, uses end of transmission char
        wiringpi.serialPuts(serial, chr(4).encode('ascii'))
        #closes the serial port
        wiringpi.serialClose(serial)
        return
Exemple #5
0
running = True

def read_serial():
    while running:
        try:
            if wpi.serialDataAvail(fd) != -1 :
                ch = wpi.serialGetchar(fd)
                if ch== -1 :
                    continue
                ch = chr(ch)
                if ch == '\r':
                    ch = '\n'
                print(ch, end='')
        except:
            pass
    print("bye.")
    
try:
    t = threading.Thread(target=read_serial)
    t.start()
    print('serial is ready.')
    while True:
        line = input(">")
        if line == 'exit':
            break
        wpi.serialPrintf(fd,  (line + '\r\n'))
    print('closing.')
finally:
    running = False
    wpi.serialClose(fd)
Exemple #6
0
pi.pinMode(back_r, pi.OUTPUT)

pi.softPwmCreate(front_l, 0, 100)
pi.softPwmWrite(front_l, 0)
pi.softPwmCreate(front_r, 0, 100)
pi.softPwmWrite(front_r, 0)
pi.softPwmCreate(back_l, 0, 100)
pi.softPwmWrite(back_l, 0)
pi.softPwmCreate(back_r, 0, 100)
pi.softPwmWrite(back_r, 0)

try:
    while True:
        speed = 0
        while (speed <= 100):
            pi.softPwmWrite(front_l, speed)
            pi.softPwmWrite(front_r, speed)
            pi.softPwmWrite(back_l, speed)
            pi.softPwmWrite(back_r, speed)
            time.sleep(0.3)
            speed = speed + 1

        pi.softPwmWrite(front_l, 0)
        pi.softPwmWrite(front_r, 0)
        pi.softPwmWrite(back_l, 0)
        pi.softPwmWrite(back_r, 0)
        time.sleep(2)
finally:
    print("Cleaning Up!")
    pi.serialClose(motor_pin)
Exemple #7
0
 def __exit__(self, exc_type, exc_val, exc_tb):
     print("with exit...")
     if self.serial_fd:
         wiringpi.serialClose(self.serial_fd)
         self.serial_fd = None
#!/usr/bin/env python
import wiringpi as wpi
import time

serial = wpi.serialOpen('/dev/ttyS0', 115200)

while True:
    input_str = raw_input('Serial Input> ')
    wpi.serialPuts(serial, input_str)
    time.sleep(0.1)

    output_str = 'Serial Output> '
    while wpi.serialDataAvail(serial):
        output_str += chr(wpi.serialGetchar(serial))
    print output_str

wpi.serialClose(serial)
Exemple #9
0
pi.softPwmCreate(back_l, 0, 100)
pi.softPwmWrite(back_l, 0)

pi.softPwmCreate(back_r, 0, 100)
pi.softPwmWrite(back_r, 0)

try:
    while True:
        speed = 20
        pi.softPwmWrite(front_l, speed)
        time.sleep(2)
        pi.softPwmWrite(front_r, speed)
        time.sleep(2)
        pi.softPwmWrite(back_l, speed)
        time.sleep(2)
        pi.softPwmWrite(back_r, speed)
        time.sleep(2)

        pi.softPwmWrite(front_l, 0)
        pi.softPwmWrite(front_r, 0)
        pi.softPwmWrite(back_l, 0)
        pi.softPwmWrite(back_r, 0)
        time.sleep(2)
finally:
    print("Cleaning Up!")
    pi.serialClose(front_l)
    pi.serialClose(front_r)
    pi.serialClose(back_l)
    pi.serialClose(back_r)
def main():

    ## MAIN ALGORITHM

    ## Open Serial Port
    ser = serial.Serial (port='/dev/ttyAMA0',baudrate=9600,parity=serial.PARITY_EVEN,stopbits=serial.STOPBITS_TWO,timeout=1)
    wiring_serial = wiringpi.serialOpen('/dev/ttyAMA0',9600)
    new = termios.tcgetattr(wiring_serial)
    new[2] |= termios.CSTOPB
    new[2] |= termios.PARENB
    termios.tcsetattr(wiring_serial,termios.TCSANOW,new)

    ## GUI
    print ('====================================================================')
    print ('            Xirka Silicon Technology Smart Card Reader              ')
    print ('====================================================================')
    print ('Instruction:')
    print ('1. Do not remove the smartcard in the middle of the program')
    print ('2. Enter x or X as APDU Command to exit the program')
    print ('3. Enter t or T as APDU Command to test the performance')
    print (' ')

    init_setup()
    warm_reset()


    GPIO.setmode(GPIO.BCM)
    GPIO.setup(TRG, GPIO.IN, pull_up_down = GPIO.PUD_UP)

    print 

    try:
        if wiringpi.digitalRead(TRG_wiringpi)==0:
            print "Waiting for Card";
            print
            GPIO.wait_for_edge(TRG, GPIO.RISING)
            ATR=read_ATR(wiring_serial)
            print "ATR :",ATR
            print 

            while True:
                apdu = raw_input("Enter APDU Command = ")
                if ((apdu == 'x') or (apdu == 'X')):
                    print
                    print "Please remove the smartcard..."
                    GPIO.wait_for_edge(TRG, GPIO.FALLING)
                    print
                    print "Thank you"
                    break
                elif (apdu=='t') or (apdu == 'T'):
                    start=time.time()
                    print
                    print ("Enter APDU Command = 00 a4 00 00 02 3f 00")
                    transmit_APDU('00 a4 00 00 02 3f 00',wiring_serial,ser)
                    print ("Enter APDU Command = 00 a4 00 00 02 30 00")
                    transmit_APDU('00 a4 00 00 02 30 00',wiring_serial,ser)
                    print ("Enter APDU Command = 00 a4 00 00 02 30 01")
                    transmit_APDU('00 a4 00 00 02 30 01',wiring_serial,ser)
                    print ("Enter APDU Command = 00 b0 00 00 08")
                    transmit_APDU('00 b0 00 00 08',wiring_serial,ser)
                    end = time.time()
                    print 'Execution time: ',(end - start), 'seconds'
                    break
                else:
                    transmit_APDU(apdu,wiring_serial,ser)
        else:
            ATR=read_ATR(wiring_serial)
            print "ATR :",ATR
            print 

            while True:
                apdu = raw_input("Enter APDU Command = ")
                if ((apdu == 'x') or (apdu == 'X')):
                    print
                    print "Please remove the smartcard..."
                    GPIO.wait_for_edge(TRG, GPIO.FALLING)
                    print
                    print "Thank you"
                    break
                elif (apdu=='t') or (apdu == 'T'):
                    start=time.time()
                    print
                    print ("Enter APDU Command = 00 a4 00 00 02 3f 00")
                    transmit_APDU('00 a4 00 00 02 3f 00',wiring_serial,ser)
                    print ("Enter APDU Command = 00 a4 00 00 02 30 00")
                    transmit_APDU('00 a4 00 00 02 30 00',wiring_serial,ser)
                    print ("Enter APDU Command = 00 a4 00 00 02 30 01")
                    transmit_APDU('00 a4 00 00 02 30 01',wiring_serial,ser)
                    print ("Enter APDU Command = 00 b0 00 00 08")
                    transmit_APDU('00 b0 00 00 08',wiring_serial,ser)
                    end = time.time()
                    print 'Execution time: ',(end - start), 'seconds'
                    break

                else:
                    transmit_APDU(apdu,wiring_serial,ser)            
    except KeyboardInterrupt:  
        GPIO.cleanup()       # clean up GPIO on CTRL+C exit  
    GPIO.cleanup()           # clean up GPIO on normal exit  


    wiringpi.serialClose(wiring_serial)
    ser.close()
Exemple #11
0
 def close(self):
     wpi.serialClose(self.serial)