Issues receiving serial commands
mike2
Posts: 8
A lot of the code I've been finding online for sending and receiving data is using spin code.
I have a c project I'm working on in which I need to send and receive data to a python program over usb.
Here's my code. Does anyone know why it's not working?
Here's my python I run immediately after loading c code into ram using simpleide
Output
I have a c project I'm working on in which I need to send and receive data to a python program over usb.
Here's my code. Does anyone know why it's not working?
#include <stdio.h> #include <string.h> #include <propeller.h> #include <simpletools.h> int main(void) { // Wait some time waitcnt((CLKFREQ+CNT)*5); char buffer[300]; int buflen = 300; serial *term; simpleterm_close(); term = serial_open(31,30,0,57600); writeStr(term,"give_data\r"); getStr(buffer, buflen); waitcnt((CLKFREQ+CNT)*2); writeStr(term,"Data received.\r"); return 0; }
Here's my python I run immediately after loading c code into ram using simpleide
import time import serial print "Communicating with propeller over COM4" s = serial.Serial( port='COM4',\ baudrate=57600,\ parity=serial.PARITY_NONE,\ stopbits=serial.STOPBITS_ONE,\ bytesize=serial.EIGHTBITS,\ timeout=0) while True: data = s.read(9999) if len(data) > 0: print 'Received:'+ data if "give_data" in data: print "Sending data to the propeller..." s.write("Here is some data\r") time.sleep(1) s.close()
Output
C:\Users\mike\Desktop>python scom.py Communicating with propeller over COM4 Received:give_data Sending data to the propeller... _
Comments
If I use the parallax serial terminal I can use C read functions like scanf, but I need to get python working.
Same result running this on a linux host
[code]
C:\Users\mike\Desktop>python kuronekotest.py
Communicating with propeller over COM4
Received:give_data
Sending data to the propeller...
Received:Hn,