オーディオ帯域のポテンショメータが使用されていてるので、実用周波数は1MHz+α程度ですが、簡単に方形波、三角波、正弦波が得られ、max5Vp-p(実力はせいぜい3V程度)ですが出力レベルの調整もできます。
消費電力の大きい抵抗があれば、Heater代わりになるのですが、残念ながら手持ちに丁度良いものがありませんでしたので、不要となった水晶発振子を改造して小型のHeaterを作成しました。
熱伝導性に優れたグリースを詰め込んで封印します。使用したのは、ホームセンターなどで売っている極圧グラファイトグリースです。絶縁性があり熱伝導性が高い優れもので、耐熱性も200℃と高く粘度も低めで密着度も良いので、やたら高いヒートシンク取り付け用のグリースの代わりにも使用できます。
import wx
import time
import os
import serial
#from serial.tools import list_ports
import argparse
# シリアル設定,本来は引数か、自動検出等があれば汎用的だが、現状専用機仕様なので…
comport = ‘COM5’
combps = 115200
# OSCキャリブレーション値
# このキャリブレーション値と後出のHeater値は起動時に自動設定が良いかもしれない。
pgcal_d = 5683.0 # by GPS
wgcal_d = 3334
pgcal = pgcal_d
wgcal = wgcal_d
# ボードからの戻り値変換用
SINE = 0x2000
SQUARE = 0x2028
TRIANGLE = 0x2002
# 変数の宣言と、てきとうな初期設定
wgwavetype = 0
pg_freq = 25000000
pgfreq = pg_freq
wg_freq = 1200000
wgfreq=wg_freq
wg_type = ‘SINE’
wg_potn = 105
wgpot = wg_potn
# 変数宣言と、将来Target温度・Heaterの設定機能追加時の為。現状値はダミー
wg_temp = 52.5
pg_temp = 47.2
tg_temp = 52.0
osc_heater = 194
# 温度異常時にカラー表示を変えたい為、現時点機能なし
over_temp = tg_temp + 4
wg_temp_color = ‘#ff99b3’
# ボードに起動時(reset含む)おーぷにおんぐメッセージを読み飛ばすフラグ
hello_flag = 0
# wavetypeのシリアルコマンド、数字->1文字コマンドへ変換用文字列
wave_irq = ‘irq’
# シリアルのセマフォフラグ
ser_busy = 0
class MainFrame(wx.Frame):
#トップレベルウィンドウクラス
def __init__(self):
super().__init__(None, wx.ID_ANY, ‘WG/PC Control Panel’,style=(wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX))
# Windowサイズは、アプリに合わして、固定表示
# 表示ポジションは、前回の位置か基準位置
if os.path.exists(“WPGCtrl.exe”):
icon = wx.Icon(‘WPGCtrl.exe’, wx.BITMAP_TYPE_ICO)
self.SetIcon(icon)
else:
icon_path_plus = os.path.dirname(os.path.abspath(__file__))+’\\favicon.ico’
# 実行ファイルのパスにあるアイコンの絶対パス
#print (icon_path_plus)
if os.path.exists(icon_path_plus):
icon = wx.Icon(icon_path_plus, wx.BITMAP_TYPE_ICO)
# jpeg/pngの場合、 BITMAP_TYPE_JPEG/BITMAP_TYPE_PNG
self.SetIcon(icon)
self.CreateStatusBar()
self.SetStatusText(‘ホームページ/ネットショップ/海人ぬ宝 https://www.himeport.co.jp/’)
self.state_panel = STATEPanel(self)
self.state_panel.SetBackgroundColour(‘#ffffbf’)
self.ctrl_panel = CTRLPanel(self)
# ctrl_panel.SetBackgroundColour(‘#ff7396’)
layout = layout = wx.BoxSizer(wx.HORIZONTAL)
layout.Add(self.state_panel, flag=wx.GROW)
layout.Add(self.ctrl_panel, flag=wx.GROW)
self.SetSizer(layout)
self.Fit()
#print (self.ctrl_panel.wg_panel.freq.GetValue())
#print (self.ctrl_panel.wg_panel.wg2_panel.wavetype.GetSelection())
#print (self.ctrl_panel.wg_panel.wg2_panel.wgpot_panel.pot.GetValue())
class STATEPanel(wx.Panel):
# STATEパネル内レイアウト
def __init__(self, parent):
super().__init__(parent, wx.ID_ANY)
self.wg_lobel = wx.StaticText(self, wx.ID_ANY, ‘WAVE Generator’)
self.wg_freq_d = wx.TextCtrl(self, wx.ID_ANY, ‘WG周波数’, style=wx.TE_RIGHT)
self.wg_type_d = wx.TextCtrl(self, wx.ID_ANY, ‘WG波形タイプ’, style=wx.TE_CENTER)
self.wg_potn_d = wx.TextCtrl(self, wx.ID_ANY, ‘WGレベル’, style=wx.TE_RIGHT)
self.pg_lobel = wx.StaticText(self, wx.ID_ANY, ‘PULSE Generator’)
self.pg_freq_d = wx.TextCtrl(self, wx.ID_ANY, ‘PG周波数’, style=wx.TE_RIGHT)
self.tmp_lobel = wx.StaticText(self, wx.ID_ANY, ‘監視温度’)
self.wg_temp_d = wx.TextCtrl(self, wx.ID_ANY, ‘WG温度’, style=wx.TE_RIGHT)
self.pg_temp_d = wx.TextCtrl(self, wx.ID_ANY, ‘PG温度’, style=wx.TE_RIGHT)
self.tg_temp_d = wx.TextCtrl(self, wx.ID_ANY, ‘設定温度’, style=wx.TE_RIGHT)
self.osc_heater_d = wx.TextCtrl(self, wx.ID_ANY, ‘Heater’, style=wx.TE_RIGHT)
dummy_text1 = wx.StaticText(self, wx.ID_ANY, ”)
dummy_text2 = wx.StaticText(self, wx.ID_ANY, ”)
box = wx.StaticBox(self, wx.ID_ANY, ‘STATE’)
# text_1.SetValue(‘text_1’)
#self.wg_temp_d.SetForegroundColour( wg_temp_color )
self.wg_freq_d.SetForegroundColour(‘#0000FF’)
self.wg_type_d.SetForegroundColour(‘#0000FF’)
self.wg_potn_d.SetForegroundColour(‘#0000FF’)
self.pg_freq_d.SetForegroundColour(‘#0000FF’)
self.wg_temp_d.SetForegroundColour(‘#0000FF’)
self.pg_temp_d.SetForegroundColour(‘#0000FF’)
self.tg_temp_d.SetForegroundColour(‘#0000FF’)
self.osc_heater_d.SetForegroundColour(‘#0000FF’)
#self.wg_temp_d.SetBackgroundColour(‘#FFFFFF’)
#self.wg_freq_d.Disable()
#self.wg_type_d.Disable()
#self.wg_potn_d.Disable()
#self.pg_freq_d.Disable()
#self.wg_temp_d.Disable()
#self.pg_temp_d.Disable()
#self.tg_temp_d.Disable()
#self.osc_heater_d.Disable()
layout = wx.StaticBoxSizer(box, wx.VERTICAL)
layout.Add(self.wg_lobel, flag=wx.GROW)
layout.Add(self.wg_freq_d)
layout.Add(self.wg_type_d)
layout.Add(self.wg_potn_d)
layout.Add(dummy_text1, flag=wx.GROW)
layout.Add(self.pg_lobel, flag=wx.GROW)
layout.Add(self.pg_freq_d)
layout.Add(dummy_text2, flag=wx.GROW)
layout.Add(self.tmp_lobel, flag=wx.GROW)
layout.Add(self.wg_temp_d)
layout.Add(self.pg_temp_d)
layout.Add(self.tg_temp_d)
layout.Add(self.osc_heater_d)
self.SetSizer(layout)
global ser
ser = serial.Serial(str(comport),int(combps),timeout=2)
# 必要に応じて引数でポートとレートを渡すようにする。
# タイマーイベント 定期的にイベントを発生させる
self.getSTATE_timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.getSTATE)
# 2秒間隔でイベント発生
self.getSTATE_timer.Start(2000)
# 定期的にステータスを引き取って表示を更新する。
def getSTATE(self,event):
global hello_flag,ser_busy,over_temp,tg_temp
# シリアル使用中なら何もしない
if (not ser_busy):
ser_busy = 1
# シリアルバッファーを空にする。
if (not hello_flag):
while ser.in_waiting > 0:
ser.reset_input_buffer()
time.sleep(0.01)
hello_flag = 1
if ser.out_waiting > 0:
ser.reset_output_buffer()
# コマンド発行、バイナリー文字列にencodeして発行
ser.reset_input_buffer()
ser.write(bytes(‘g\\’,’utf-8′))
i=0
while (ser.in_waiting<1 and i<200):
i=i+1
time.sleep(0.01)
# 結果の受け取りと分析、表示
line = ser.readline()
line_arg=line.split()
# 受信したデーターはバイナリー文字列b’n’なのでdecode()して文字に
if (line_arg[0].decode() == ‘Status:’ ):
self.wg_freq_d.SetValue( line_arg[2].decode() +’ Hz’)
wg_type = ‘NONE’
if(int(line_arg[3].decode()) == SINE):
wg_type = ‘SINE’
elif(int(line_arg[3].decode()) == SQUARE):
wg_type = ‘SQUARE’
elif(int(line_arg[3].decode()) == TRIANGLE):
wg_type = ‘TRIANGLE’
self.wg_type_d.SetValue( ‘出力波形: ‘+ wg_type)
self.wg_potn_d.SetValue( ‘POT: ‘+ line_arg[4].decode()+’/255’)
self.pg_freq_d.SetValue( line_arg[1].decode()+’ Hz’)
self.wg_temp_d.SetValue( ‘WG温度: ‘+ line_arg[5].decode()+’ deg’)
self.pg_temp_d.SetValue( ‘PG温度: ‘+ line_arg[6].decode()+’ deg’)
self.tg_temp_d.SetValue( ‘設定温度: ‘+ line_arg[8].decode()+’ deg’)
self.osc_heater_d.SetValue( ‘ヒータ出力: ‘+ line_arg[7].decode()+’/1024’ )
# 異常温度の場合red、適正温度になるとgreen
if float(line_arg[5].decode()) > over_temp:
self.wg_temp_d.SetBackgroundColour(‘#FF0000’)
elif abs(float(line_arg[5].decode()) – tg_temp) < 0.8:
self.wg_temp_d.SetBackgroundColour(‘#008000’)
else:
self.wg_temp_d.SetBackgroundColour(‘#FFFFFF’)
# Heaterのパワーが50%を超えた場合red…故障など異常の兆候
if int(line_arg[7].decode()) > 512:
self.wg_temp_d.SetBackgroundColour(‘#FF0000’)
else:
self.wg_temp_d.SetBackgroundColour(‘#FFFFFF’)
else:
ser.reset_input_buffer()
ser_busy = 0
class CTRLPanel(wx.Panel):
# CTRL コントロールパネル内レイアウト
def __init__(self, parent):
super().__init__(parent, wx.ID_ANY)
layout = wx.FlexGridSizer(rows=2, cols=1, gap=(0, 0))
self.wg_panel = WGPanel(self)
self.wg_panel.SetBackgroundColour(‘#c5edff’)
self.pg_panel = PGPanel(self)
self.pg_panel.SetBackgroundColour(‘#9bff9b’)
# ctrl_layout.AddGrowableRow(0)
layout.Add(self.wg_panel, flag=wx.GROW)
layout.Add(self.pg_panel, flag=wx.GROW)
self.SetSizer(layout)
class WGPanel(wx.Panel):
# WG コントロールパネル内レイアウト
def __init__(self, parent):
super().__init__(parent, wx.ID_ANY)
self.wgpot_panel = WPOTPanel(self)
self.wgcal_panel = WCALPanel(self)
self.box = wx.StaticBox( self, wx.ID_ANY, ‘WAVE Generator CONTROL’)
layout = wx.StaticBoxSizer(self.box, wx.VERTICAL)
layout.Add(self.wgpot_panel)
layout.Add(self.wgcal_panel)
self.SetSizer(layout)
class WPOTPanel(wx.Panel):
# WG POTコントロールパネル内レイアウト
def __init__(self, parent):
super().__init__(parent, wx.ID_ANY)
self.pot_label = wx.StaticText(self, wx.ID_ANY, ‘ Pot. 0 – 255’)
self.pot = wx.TextCtrl(self, wx.ID_ANY, style=wx.TE_RIGHT)
# pot.GetValue() でテキストを取得できる。
self.pot.SetMaxLength(5)
global wgpot
self.pot.SetValue(str(wgpot))
# 現在の値を表示する
self.button_wgset = wx.Button( self, wx.ID_ANY, ‘Set’)
self.button_wgset.SetBackgroundColour(‘#00ffff’)
dummy_text = wx.StaticText(self, wx.ID_ANY, ”)
self.button_wgset.Bind(wx.EVT_BUTTON, self.click_wgset)
self.wg_freqpanel = WGFreqPanel(self)
self.wg_wavepanel = WGWavePanel(self)
layout = wx.GridBagSizer()
layout.Add(self.wg_freqpanel, (0,0), (1,2), flag=wx.EXPAND)
layout.Add(self.wg_wavepanel, (1,0), (4,1), flag=wx.EXPAND)
layout.Add(self.pot_label, (1,1), (1,1), flag=wx.EXPAND)
layout.Add(self.pot, (2,1), (1,1), flag=wx.EXPAND)
layout.Add(self.button_wgset, (4,1), (1,1), flag=wx.EXPAND)
self.SetSizer(layout)
def click_wgset(self,event):
global wgfreq,wgwavetype,wgpot,ser_busy
if (not ser_busy):
ser_busy = 1
get_wgfreq= self.wg_freqpanel.freq.GetValue()
get_wgwavetype= self.wg_wavepanel.wavetype.GetSelection()
get_wgpot= self.pot.GetValue()
# 処理の都合、一時的に初期値を設定。
self.wg_freqpanel.freq.SetValue(str(wgfreq))
self.wg_wavepanel.wavetype.SetSelection(int(wgwavetype))
self.pot.SetValue(str(wgpot))
# 全ての文字が十進数字か、チェック
if not(str.isdecimal(get_wgfreq.replace(‘.’, ”))):
# 必要ならエラー通知を入れる。
event.Skip()
else:
if (float(get_wgfreq)<0) or (1200000 < float(get_wgfreq)):
# 必要ならエラー通知を入れる。
event.Skip()
else:
if not(str.isdecimal(get_wgpot)):
# 必要ならエラー通知を入れる。
event.Skip()
else:
if (int(get_wgpot)<0) or (255 < int(get_wgpot)):
# 必要ならエラー通知を入れる。
event.Skip()
else:
self.wg_freqpanel.freq.SetValue(str(get_wgfreq))
self.wg_wavepanel.wavetype.SetSelection(int(get_wgwavetype))
self.pot.SetValue(str(get_wgpot))
wgfreq = str(get_wgfreq)
wgwavetype = int(get_wgwavetype)
wgpot = str(get_wgpot)
# シリアルでコマンドを送るサブルーチン追加!
# シリアルバッファーを空にする。
global hello_flag
if (not hello_flag):
while ser.in_waiting > 0:
ser.reset_input_buffer()
time.sleep(0.01)
hello_flag = 1
if ser.out_waiting > 0:
ser.reset_output_buffer()
# コマンド発行、バイナリー文字列にencodeして発行
ser.reset_input_buffer()
ser.write(bytes(‘w\\’,’utf-8′))
i=0
while (ser.in_waiting<1 and i<200):
i=i+1
time.sleep(0.01)
# 結果の受け取りと分析、表示
line = ser.readline()
line_arg=line.split()
# 受信したデーターはバイナリー文字列b’n’なのでdecode()して文字に
if (line_arg[0].decode() == ‘WG’ ):
ser.reset_input_buffer()
ser.write(wgfreq.encode())
ser.write(bytes(‘\\’,’utf-8′))
i=0
while (ser.in_waiting<1 and i<200):
i=i+1
time.sleep(0.01)
line = ser.readline()
line_arg=line.split()
if (line_arg[0].decode() == ‘WG2’ ):
ser.reset_input_buffer()
ser.write(wgpot.encode())
ser.write(bytes(‘\\’,’utf-8′))
i=0
while (ser.in_waiting<1 and i<200):
i=i+1
time.sleep(0.01)
line = ser.readline()
line_arg=line.split()
if (line_arg[0].decode() == ‘WG3’ ):
ser.reset_input_buffer()
b_wgwavetype = wave_irq[wgwavetype]
ser.write(b_wgwavetype.encode())
ser.write(bytes(‘\\’,’utf-8′))
i=0
while (ser.in_waiting<1 and i<200):
i=i+1
time.sleep(0.01)
line = ser.readline()
line_arg=line.split()
if (line_arg[0].decode() == ‘WG4’ ):
self.button_wgset.SetBackgroundColour(‘#00ffff’)
# NG受信データの処理内容
else:
self.button_wgset.SetBackgroundColour(‘#ffff00’)
else:
self.button_wgset.SetBackgroundColour(‘#ff0000’)
else:
self.button_wgset.SetBackgroundColour(‘#ff00ff’)
else:
self.button_wgset.SetBackgroundColour(‘#000000’)
ser_busy = 0
class WGWavePanel(wx.Panel):
# WG WaveType コントロールパネル内レイアウト
def __init__(self, parent):
super().__init__(parent, wx.ID_ANY)
self.wavetype_array = (‘正弦波’, ‘三角波’, ‘方形波’)
self.wavetype = wx.RadioBox(self, wx.ID_ANY, ‘Wave type’,
choices=self.wavetype_array, style=wx.RA_VERTICAL)
# wavetype.GetSelection()で選択値、wavetype.GetStringSelection()要素名で取得
global wgwavetype
self.wavetype.SetSelection(int(wgwavetype))
# 仮に初期値を三角波に、要素名で指定はSetStringSelection()
layout = wx.BoxSizer(wx.VERTICAL)
layout.Add(self.wavetype, flag=wx.SHAPED | wx.ALIGN_LEFT)
self.SetSizer(layout)
class WGFreqPanel(wx.Panel):
# WG Freqコントロールパネル内レイアウト
def __init__(self, parent):
super().__init__(parent, wx.ID_ANY)
self.freq_label = wx.StaticText(self, wx.ID_ANY, ‘ Frequency 0.1-1200000Hz’)
self.freq = wx.TextCtrl(self, wx.ID_ANY, style=wx.TE_RIGHT)
# freq.GetValue() でテキストを取得できる。
# print(freq.GetValue())
self.freq.SetMaxLength(10)
global wgfreq
self.freq.SetValue(str(wgfreq))
layout = wx.BoxSizer(wx.VERTICAL)
layout.Add(self.freq_label)
layout.Add(self.freq, flag=wx.GROW)
self.SetSizer(layout)
class WCALPanel(wx.Panel):
# WG Cal コントロールパネル内レイアウト
def __init__(self, parent):
super().__init__(parent, wx.ID_ANY)
self.cal_label = wx.StaticText(self, wx.ID_ANY, ‘ OSC cal. -200000.0 – +200000.0 (Hz)’)
self.cal_value = wx.TextCtrl(self, wx.ID_ANY, style=wx.TE_RIGHT)
# cal.GetValue() でテキストを取得できる。
self.cal_value.SetMaxLength(9)
self.cal_value.SetValue(str(wgcal))
# 現在のキャリブレーション値を表示する
self.button_wgcal = wx.Button( self, wx.ID_ANY, ‘Cal’)
self.button_wgcal.SetBackgroundColour(‘#00ffff’)
self.button_wgcal.Bind(wx.EVT_BUTTON, self.click_wgcal)
layout = wx.GridBagSizer()
layout.Add(self.cal_label, (0,0), (1,2), flag=wx.EXPAND)
layout.Add(self.cal_value, (1,0), (1,1), flag=wx.EXPAND)
layout.Add(self.button_wgcal, (1,1), (1,1), flag=wx.EXPAND)
self.SetSizer(layout)
def click_wgcal(self, event):
global wgcal,ser_busy
if (not ser_busy):
get_wgcal= self.cal_value.GetValue()
# 全ての文字が十進数字か、「-」「.」を除いてチェック
if not(str.isdecimal(get_wgcal.replace(‘-‘,”).replace(‘.’, ”))):
self.cal_value.SetValue(str(wgcal))
event.Skip()
else:
if (abs(int(get_wgcal)) > 200000):
self.cal_value.SetValue(str(wgcal))
event.Skip()
else:
if (int(get_wgcal) >= 200000 ):
get_wgcal=wgcal_d
self.cal_value.SetValue(str(wgcal_d))
ser_busy = 1
self.button_wgcal.SetBackgroundColour(‘#ffff00’)
wgcal = str(get_wgcal)
# シリアルバッファーを空にする。
global hello_flag
if (not hello_flag):
while ser.in_waiting > 0:
ser.reset_input_buffer()
time.sleep(0.01)
hello_flag = 1
if ser.out_waiting > 0:
ser.reset_output_buffer()
# コマンド発行、バイナリー文字列にencodeして発行
ser.reset_input_buffer()
ser.write(bytes(‘c\\’,’utf-8′))
i=0
while (ser.in_waiting<1 and i<200):
i=i+1
time.sleep(0.01)
# 結果の受け取りと分析、表示
line = ser.readline()
line_arg=line.split()
# 受信したデーターはバイナリー文字列b’n’なのでdecode()して文字に
if len(line_arg)>0:
if (line_arg[0].decode() == ‘WG’ ):
ser.reset_input_buffer()
ser.write(wgcal.encode())
ser.write(bytes(‘\\’,’utf-8′))
i=0
while (ser.in_waiting<1 and i<200):
i=i+1
time.sleep(0.01)
# 結果の受け取りと分析、表示
line = ser.readline()
line_arg=line.split()
# 受信したデーターはバイナリー文字列b’n’なのでdecode()して文字に
if (len(line_arg)>0):
if (line_arg[0].decode() == ‘WG’ ):
self.button_wgcal.SetBackgroundColour(‘#00ffff’)
# 処理内容
ser_busy = 0
class PGPanel(wx.Panel):
# PG コントロールパネル内レイアウト
def __init__(self, parent):
super().__init__(parent, wx.ID_ANY)
self.pgfreq_panel = PFREQPanel(self)
self.pgcal_panel = PCALPanel(self)
self.box = wx.StaticBox( self, wx.ID_ANY, ‘PULSE Generator CONTROL’)
layout = wx.StaticBoxSizer(self.box, wx.VERTICAL)
layout.Add(self.pgfreq_panel)
layout.Add(self.pgcal_panel)
self.SetSizer(layout)
class PFREQPanel(wx.Panel):
# PG Freq コントロールパネル内レイアウト
def __init__(self, parent):
super().__init__(parent, wx.ID_ANY)
self.freq_label = wx.StaticText(self, wx.ID_ANY, ‘ Frequency 4000-225000000Hz’)
self.freq = wx.TextCtrl(self, wx.ID_ANY, style=wx.TE_RIGHT)
# freq.GetValue() でテキストを取得できる。
# print(freq.GetValue())
self.freq.SetMaxLength(10)
self.freq.SetValue(str(pgfreq))
self.button_pgset = wx.Button( self, wx.ID_ANY, ‘Set’)
self.button_pgset.SetBackgroundColour(‘#00ffff’)
self.button_pgset.Bind(wx.EVT_BUTTON, self.click_pgset)
layout = wx.GridBagSizer()
layout.Add(self.freq_label, (0,0), (1,2), flag=wx.EXPAND)
layout.Add(self.freq, (1,0), (1,1), flag=wx.EXPAND)
layout.Add(self.button_pgset, (1,1), (1,1), flag=wx.EXPAND)
self.SetSizer(layout)
def click_pgset(self, event):
global pgfreq,ser_busy
if (not ser_busy):
get_pgfreq= self.freq.GetValue()
# 全ての文字が十進数字か、チェック
if not(str.isdecimal(get_pgfreq)):
self.freq.SetValue(str(pgfreq))
event.Skip()
else:
if ((int(get_pgfreq)<4000) or (int(get_pgfreq)>225000000)):
self.freq.SetValue(str(pgfreq))
event.Skip()
else:
# シリアルでコマンドを送るサブルーチン追加!
ser_busy = 1
self.button_pgset.SetBackgroundColour(‘#ffff00’)
pgfreq = str(get_pgfreq)
# シリアルバッファーを空にする。
global hello_flag
if (not hello_flag):
while ser.in_waiting > 0:
ser.reset_input_buffer()
time.sleep(0.01)
hello_flag = 1
if ser.out_waiting > 0:
ser.reset_output_buffer()
# コマンド発行、バイナリー文字列にencodeして発行
ser.reset_input_buffer()
ser.write(bytes(‘p\\’,’utf-8′))
i=0
while (ser.in_waiting<1 and i<200):
i=i+1
time.sleep(0.01)
# 結果の受け取りと分析、表示
line = ser.readline()
line_arg=line.split()
# 受信したデーターはバイナリー文字列b’n’なのでdecode()して文字に
if len(line_arg)>0:
if (line_arg[0].decode() == ‘PG’ ):
ser.reset_input_buffer()
ser.write(pgfreq.encode())
ser.write(bytes(‘\\’,’utf-8′))
i=0
while (ser.in_waiting<1 and i<200):
i=i+1
time.sleep(0.01)
# 結果の受け取りと分析、表示
line = ser.readline()
line_arg=line.split()
# 受信したデーターはバイナリー文字列b’n’なのでdecode()して文字に
if (len(line_arg)>0):
if (line_arg[0].decode() == ‘PG’ ):
self.button_pgset.SetBackgroundColour(‘#00ffff’)
# 処理内容
ser_busy = 0
class PCALPanel(wx.Panel):
# PG Cal コントロールパネル内レイアウト
def __init__(self, parent):
super().__init__(parent, wx.ID_ANY)
self.cal_label = wx.StaticText(self, wx.ID_ANY, ‘ calibration -200000.0 – +200000.0ppm’)
self.cal_value = wx.TextCtrl(self, wx.ID_ANY, style=wx.TE_RIGHT)
# cal.GetValue() でテキストを取得できる。
self.cal_value.SetMaxLength(9)
self.cal_value.SetValue(str(pgcal))
# 現在のキャリブレーション値を表示する
self.button_pgcal = wx.Button( self, wx.ID_ANY, ‘Cal’)
self.button_pgcal.SetBackgroundColour(‘#00ffff’)
self.button_pgcal.Bind(wx.EVT_BUTTON, self.click_pgcal)
layout = wx.GridBagSizer()
layout.Add(self.cal_label, (0,0), (1,2), flag=wx.EXPAND)
layout.Add(self.cal_value, (1,0), (1,1), flag=wx.EXPAND)
layout.Add(self.button_pgcal,(1,1), (1,1), flag=wx.EXPAND)
self.SetSizer(layout)
def click_pgcal(self, event):
global pgcal,ser_busy
if (not ser_busy):
get_pgcal= self.cal_value.GetValue()
# 全ての文字が十進数字か「-」「.」符号を予めreplaceしてから、チェック
if not(str.isdecimal(get_pgcal.replace(‘-‘,”).replace(‘.’, ”))):
self.cal_value.SetValue(str(pgcal))
event.Skip()
else:
if (abs(float(get_pgcal)) > 200000):
self.cal_value.SetValue(str(pgcal))
event.Skip()
else:
if (float(get_pgcal) >= 200000 ):
get_pgcal=pgcal_d
self.cal_value.SetValue(str(pgcal_d))
# シリアルでコマンドを送るサブルーチン追加!
ser_busy = 1
self.button_pgcal.SetBackgroundColour(‘#ffff00’)
pgcal = str(get_pgcal)
# シリアルバッファーを空にする。
global hello_flag
if (not hello_flag):
while ser.in_waiting > 0:
ser.reset_input_buffer()
time.sleep(0.01)
hello_flag = 1
if ser.out_waiting > 0:
ser.reset_output_buffer()
# コマンド発行、バイナリー文字列にencodeして発行
ser.reset_input_buffer()
ser.write(bytes(‘C\\’,’utf-8′))
i=0
while (ser.in_waiting<1 and i<200):
i=i+1
time.sleep(0.01)
# 結果の受け取りと分析、表示
line = ser.readline()
line_arg=line.split()
# 受信したデーターはバイナリー文字列b’n’なのでdecode()して文字に
if len(line_arg)>0:
if (line_arg[0].decode() == ‘PG’ ):
ser.reset_input_buffer()
ser.write(pgcal.encode())
ser.write(bytes(‘\\’,’utf-8′))
i=0
while (ser.in_waiting<1 and i<200):
i=i+1
time.sleep(0.01)
# 結果の受け取りと分析、表示
line = ser.readline()
line_arg=line.split()
# 受信したデーターはバイナリー文字列b’n’なのでdecode()して文字に
if (len(line_arg)>0):
if (line_arg[0].decode() == ‘PG’ ):
self.button_pgcal.SetBackgroundColour(‘#00ffff’)
# 処理内容
ser_busy = 0
if __name__ == ‘__main__’:
# カスタムフレームを初期化してアプリケーションを開始
application = wx.App()
frame = MainFrame()
frame.Show()
application.MainLoop()