Noob needing guidance.... - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Noob needing guidance.... (/thread-25407.html) |
Noob needing guidance.... - bako - Mar-29-2020 I keep getting issues trying to do a serial thing. I'm copying the lines from another script that kind of works okay. Objective: Send serial modem commands to a Raspberry Pi Hat. root@UPS-pico:/home/binary/GIT/Raspbery_PI_Scripts/Waveshare-GSM-GPRS-GNSS_HAT# python3.6 waveshare_init.py The script I'm working on.import RPi.GPIO as GPIO import serial import time ser = serial.Serial("/dev/ttyS0", 115200) GPIO.setmode(GPIO.BOARD) GPIO.setup(7, GPIO.IN) GPIO.setup(7, GPIO.OUT) GPIO.setwarnings(False) pin7 = GPIO.input(7) W_buff = ["AT+CGNSSEQ=\"RMC\"\r\n", "AT+CGNSINF\r\n"] if pin7 == 1: pin7mode = "off" GPIO.output(7, GPIO.LOW) time.sleep(4) elif pin7 == 0: pin7mode = "on" print(pin7mode) ser.write(W_buff[0]) ser.flushInput() GPIO.cleanup()The script that kind of works... #!/usr/bin/python3.6 import serial import time ser = serial.Serial("/dev/ttyS0",115200) W_buff = ["AT+CGNSPWR=1\r\n", "AT+CGNSSEQ=\"RMC\"\r\n","AT+CGNSINF\r\n", "AT+CGNSURC=2\r\n", "AT+CGNSTST=1\r\n"] ser.write(W_buff[0]) ser.flushInput() data = "" num = 0 try: while True: while ser.inWaiting() > 0: data += ser.read(ser.inWaiting()) if data != "": print(data) time.sleep(0.5) ser.write(W_buff[num+1]) num =num +1 if num == 4: time.sleep(0.5) ser.write(W_buff[4]) data = "" except keyboardInterrupt: if ser != None: ser.close() |