help with E32 program (simple)
Re: help with E32 program (simple)
The difference could be caused by encoding or by different \r \n behaviour.
Re: help with E32 program (simple)
Ok, can anyone look at this and see if they have an idea as to why it's not working?
( for reference, the TX side is transmitting:
"(,2,255,1,0,0,1,1,0,1,0,126,685,1011,975,)"
( for reference, the TX side is transmitting:
"(,2,255,1,0,0,1,1,0,1,0,126,685,1011,975,)"
Code: Select all
from machine import Pin,UART
import _thread
from time import sleep
uart = UART(1,115200, tx=Pin(4), rx=Pin(5))
command = []
inCommand = False
led=Pin(25,Pin.OUT)
def handle():
if len(command) == 16:
print(command)
else:
print('Incomplete Command Received')
while True:
if uart.any():
rec = uart.read()
#print('rec')
if rec == '(':
inCommand = True
if inCommand == True:
command.append(rec)
if rec == ')':
handle()
command = []
inCommand = False
else:
print("No Data Received")
Re: help with E32 program (simple)
rec is a string not a single character
Your program has no hope of working and you've ignored everything we've told you
Your program has no hope of working and you've ignored everything we've told you
Re: help with E32 program (simple)
How is rec a string? it's = uart.read().
As I understand it, (and I may be completely wrong, - and if so, PLEASE correct me) uart.read() reads a single byte, so rec should be a byte?.
I am not ignoring anything that has been said, I am just not understanding anything the way it has been stated. I am hoping for not only suggestions on how to write the program, but also the logic behind the suggestions as well. The point of all of this is to not only get this program to work, but for me to gain knowledge as to WHY it works the way it does. You say it's a string, how about explaining why it is a string, or what line of the code that sets it as a string. Telling me that "it's a string" only goes so far, and still doesn't help me to understand anything.
As I understand it, (and I may be completely wrong, - and if so, PLEASE correct me) uart.read() reads a single byte, so rec should be a byte?.
I am not ignoring anything that has been said, I am just not understanding anything the way it has been stated. I am hoping for not only suggestions on how to write the program, but also the logic behind the suggestions as well. The point of all of this is to not only get this program to work, but for me to gain knowledge as to WHY it works the way it does. You say it's a string, how about explaining why it is a string, or what line of the code that sets it as a string. Telling me that "it's a string" only goes so far, and still doesn't help me to understand anything.
Re: help with E32 program (simple)
You assume that uart.read() returns one byte. This might happen in rare cases, but the documentation of uart.read() states otherwise:
At least the sample code @francis posted told you this:Read characters. If nbytes is specified then read at most that many bytes, otherwise read as much data as possible. It may return sooner if a timeout is reached. The timeout is configurable in the constructor.
Code: Select all
while True:
got = uart.read()
for ch in got:
packet.append(ch)
A few hours of debugging might save you from minutes of reading the documentation!
My repositories: https://github.com/karfas
My repositories: https://github.com/karfas
Re: help with E32 program (simple)
Sorry but you're being ridiculous
The documentation, and every answer here tells uart.read() delivers as many characters as possible.
The only reason for believing uart.read() delivers just one character is because you want it to be so. Everything else from documentation to every single answer here tells you otherwise.
And if you just bothered to debug print what uart.read() returns you would know that.
You are not debugging your problem. You are hoping strangers on a forum will slowly rewrite your code so it works
The documentation, and every answer here tells uart.read() delivers as many characters as possible.
The only reason for believing uart.read() delivers just one character is because you want it to be so. Everything else from documentation to every single answer here tells you otherwise.
And if you just bothered to debug print what uart.read() returns you would know that.
You are not debugging your problem. You are hoping strangers on a forum will slowly rewrite your code so it works