n00bからのPython 2.7の質問は次のとおりです。
シリアル ポートからデータを読み取り、Tkinter-Canvas を使用してライブ グラフを作成するアプリを実行しています。このライブラリは、プログラムを実行したい A20 プラットフォームでは利用できないため、私は matplotlib を使用していません。(mpl の一部の依存関係は、A20 ではまだ必要なバージョンに達していません)
これがライブ グラフを描画する最もエレガントな方法ではないことはわかっていますが、実際にはすべてのプラットフォームで利用可能な Tkinter を lib として依存しているだけなので、最も互換性があるように思えました。私は基本的にキャンバスを削除し、新しいデータが入るたびに1つの位置オフセットで再描画しています。少しちらつきますが、私が言ったように...私はn00bです。:)
グラフを描画するための私のコードは次のとおりです。
class TeleGraph(Canvas):
def __init__(self, master, FrameTitle, Col, Row, Height):
Canvas.__init__(self, master)
self.FrameTitle = FrameTitle
self.Value1 = range(60)
self.Value2 = range(60)
self.Value3 = range(60)
self.configure(height = Height, width = 750, bg = 'grey', bd = 3,relief = GROOVE)
self.grid()
self.grid_propagate(0)
self.Col = Col
self.Row = Row
self.place(y = Col, x = Row)
def NewEntry(self, NewValue1, NewValue2, NewValue3 = 0, Centerline = False, ThirdLine = False):
self.delete("all")
self.create_text( 380,20,text = self.FrameTitle, fill = 'black')
if Centerline == True:
self.create_line(0,90,760,90, fill = 'dark grey')
for x in range(1,59):
self.Value1[x] = self.Value1[x+1]
self.Value2[x] = self.Value2[x+1]
self.Value3[x] = self.Value3[x+1]
self.Value1[59] = NewValue1
self.Value2[59] = NewValue2
self.Value3[59] = NewValue3
for x in range(0,59):
self.create_line(-13+(x*13),self.Value1[x],0+(x*13),self.Value1[x+1], fill='blue' )
self.create_line(-13+(x*13),self.Value2[x],0+(x*13),self.Value2[x+1], fill='red' )
if ThirdLine == True:
self.create_line(-13+(x*13),self.Value3[x],0+(x*13),self.Value3[x+1], fill='yellow' )
これまでのところ問題なく動作していますが、奇妙なエラーに気付きました:
30 分ほどすると、Canvas の更新が停止しますが、プログラム自体はまだ完全に実行されています。アプリの上にマウスを移動すると、キャンバスが再び更新されます。0.5 秒ごとに NewEntry 関数を呼び出します。時々マウスイベントを生成することを考えましたが、それは厄介な回避策です...どんな助けも大歓迎です!
ありがとう、
デッキ