Prisijungti

stringa programa

  • 12 Grd '15

Sveiki, vienai sekundei stringa programa.
"timeout" reiksme pakeitus į '0' išmeta klaida: > ValueError: could not convert string to float:

style.use('ggplot')
import matplotlib.pyplot as plt
import matplotlib.dates as md
from drawnow import *
import Tkinter as Tkinter
from Tkinter import *


SerialPort = serial.Serial(port ='/dev/ttyUSB0',
                         baudrate=9600,parity =serial.PARITY_NONE,
                         stopbits=serial.STOPBITS_ONE,bytesize=serial.EIGHTBITS, 
                         timeout =1)

print SerialPort.isOpen()
pressureArray=[]

tWindow=1 #moving window in minutes
def makeFig():
    plt.grid(True)
    plt.ylabel('Pressure(Torr)')
    plt.xlabel('Time')
    plt.xticks( rotation=25 )


    plt.plot(pressureArray)

plt.ion()

while True:
    SerialPort.write('@253PR4?;FF')

    pressure= SerialPort.readall() [7:15]
##    print pressure , 'Torr'
    pressureArray.append(pressure)
    print pressureArray
    drawnow(makeFig)
#    time.sleep(1)

Kaip spręsti šį reikalą?

TechtronicMindaugas N.
  • 12 Grd '15

Kokia klaida raso ? (postink visa python rasoma informacija!).
Kas yra serial ? Ar nori kad mes spetume?

Ok, speju tai pySerial, tai gal nurodzius timeout=None veiks, o gal ir ne.

  • 12 Grd '15

taip pyserial. klaidos pranesimas su "timeout" parametru 0

Traceback (most recent call last):
File "/home/bar/Dropbox/metu13share/liberlab/mkstransducer/transducer.py", line 54, in <module>
drawnow(makeFig)
File "/usr/local/lib/python2.7/dist-packages/drawnow/drawnow.py", line 62, in drawnow
draw_fig(argv, **kw)
File "/home/bar/Dropbox/metu13share/liberlab/mks_transducer/transducer.py", line 43, in makeFig
plt.plot(pressureArray)
File "/usr/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 3099, in plot
ret = ax.plot(
args, **kwargs)
File "/usr/lib/python2.7/dist-packages/matplotlib/axes/_axes.py", line 1375, in plot
self.add_line(line)
File "/usr/lib/python2.7/dist-packages/matplotlib/axes/_base.py", line 1486, in add_line
self._update_line_limits(line)
File "/usr/lib/python2.7/dist-packages/matplotlib/axes/_base.py", line 1497, in _update_line_limits
path = line.get_path()
File "/usr/lib/python2.7/dist-packages/matplotlib/lines.py", line 871, in get_path
self.recache()
File "/usr/lib/python2.7/dist-packages/matplotlib/lines.py", line 581, in recache
y = np.asarray(yconv, np.float
)
File "/usr/lib/python2.7/dist-packages/numpy/core/numeric.py", line 460, in asarray
return array(a, dtype, copy=False, order=order)
ValueError: could not convert string to float:

Bandžiau ir "None" , bet tuomet išviso nesulaukiu atsakymo.
Čia bandau piešti vakuumo daviklio reikšmes
http://www.mksinst.com/product/Product. ... ductID=441
https://www.dropbox.com/s/2yx8lbtfriknb ... n.pdf?dl=0

  • 13 Grd '15

http://stackoverflow.com/questions/3877 ... s-in-numpy

Tavo atveju matyt reikia pakeist galą iš:

while True:
    SerialPort.write('@253PR4?;FF')
    pressure= SerialPort.readall() [7:15]
    pressureArray.append(pressure)
    print pressureArray
    drawnow(makeFig)

Į:

import numpy as np
while True:
    SerialPort.write('@253PR4?;FF')
    pressure= SerialPort.readall() [7:15]
    pressureArray.append(pressure)
    np.array(map(float, pressureArray))
    print pressureArray
    drawnow(makeFig)
Atsakyti