Python 因为我可以区分不同的数据和串行数据?

Python 因为我可以区分不同的数据和串行数据?,python,split,serial-port,picaxe,Python,Split,Serial Port,Picaxe,我试图通过序列差的值来读取,但我不知道如何分割,因为这两个值是数字,但来源不同 首先,我有一个PICAXE,通过光传感器的ADC将转换后的数据串行发送到python。 第二,我有一个PICAXE通过串口将温度传感器的数据发送到python 光码PICAXE symbol puerto = B.5 main: readadc10 puerto,w1 ; read value into w1 sertxd(#w1,cr,lf) goto main ; loop back to st

我试图通过序列差的值来读取,但我不知道如何分割,因为这两个值是数字,但来源不同

首先,我有一个PICAXE,通过光传感器的ADC将转换后的数据串行发送到python。 第二,我有一个PICAXE通过串口将温度传感器的数据发送到python

光码PICAXE

symbol puerto = B.5
main: readadc10 puerto,w1    ; read value into w1
sertxd(#w1,cr,lf)
goto main       ; loop back to start
symbol temp = B.4

readtemp temp, w0    ; read value into w1
debug
sertxd(#w0,cr,lf)
goto main
温度代码PICAXE

symbol puerto = B.5
main: readadc10 puerto,w1    ; read value into w1
sertxd(#w1,cr,lf)
goto main       ; loop back to start
symbol temp = B.4

readtemp temp, w0    ; read value into w1
debug
sertxd(#w0,cr,lf)
goto main
Python代码

   import pygame
   import sys, serial
   from pygame.locals import *




   ser = serial.Serial()
   ser.port = 3
   ser.baudrate = 4800

   while True:

        datos = ser.readline()            
        grados = float(datos)
        print grados
问题是picaxe从light和temp同时发送数据,但当python接收数据时,我不知道如何识别每个数据

有人能帮我吗


谢谢!

如果要同时发送温度读数和亮度读数,可以将它们放在一行中,用空格隔开

皮卡克斯:

sertxd(#w0," ",#w1,cr,lf)
sertxd("T ",#w0,cr,lf)
...
sertxd("L ",#w1,cr,lf)
Python:

readings = ser.readline()
[reading1, reading2] = readings.split()
temperature = float(reading1)
lightlevel = float(reading2)
reading = ser.readline()
[readingtype, readingvalue] = reading.split()
if readingtype == "T":
    temperature = float(readingvalue)
elif readingtype == "L":
    lightlevel = float(readingvalue)
如果这两种类型的读取是不规则产生的,您可以在每一种读取之前发送一个字符,以确定它是什么类型的

皮卡克斯:

sertxd(#w0," ",#w1,cr,lf)
sertxd("T ",#w0,cr,lf)
...
sertxd("L ",#w1,cr,lf)
Python:

readings = ser.readline()
[reading1, reading2] = readings.split()
temperature = float(reading1)
lightlevel = float(reading2)
reading = ser.readline()
[readingtype, readingvalue] = reading.split()
if readingtype == "T":
    temperature = float(readingvalue)
elif readingtype == "L":
    lightlevel = float(readingvalue)