--- /dev/null
+# -*- coding: utf-8 -*-
+
+#@author: daimashiren
+#@time: 2020/07/06
+from time import sleep
+from PyQt5.QtCore import Qt,QRect,QPoint,QTimer
+from PyQt5.QtWidgets import QDialog,QLabel,QApplication,QHBoxLayout,QDesktopWidget
+
+
+class Msg(QDialog):
+ def __init__(self, master):
+ super(Msg, self).__init__()
+ self.master = master
+ self.ini_ui()
+
+ def ini_ui(self):
+ self.setWindowModality(Qt.NonModal)
+ self.setWindowOpacity(0.8) # 设置窗口透明度
+ self.setStyleSheet("""
+ QDialog{
+ border: none;
+ background:rgb(150,150,150,100);}
+ """)
+ self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint | Qt.Tool)
+ win_center = QDesktopWidget().availableGeometry().center()
+ x = self.master.x()+self.master.width()/2
+ y = self.master.y()+self.master.height()/2
+ geo = QRect( x - 150, y- 50, 300, 100)
+ self.setGeometry(geo)
+ self.setContentsMargins(0, 0, 0, 0)
+ main_layout = QHBoxLayout()
+ self.setLayout(main_layout)
+ main_layout.setAlignment(Qt.AlignVCenter|Qt.AlignHCenter)
+ self.msg_label = QLabel()
+ self.msg_label.setStyleSheet("""
+ QLabel{
+ color:#7fccde;
+ text-align:left;
+ border:none;
+ border-image:none;
+ font-size:25px;
+ font-weight:300;
+ font-family: "黑体","Arial","Microsoft YaHei","宋体",sans-serif;
+ }
+ """)
+ main_layout.addWidget(self.msg_label)
+
+ self.fade_timer = QTimer()
+ self.fade_timer.setInterval(2000)
+ self.fade_timer.timeout.connect(self.faded_out)
+
+ # (中心展示)只能在show方法后调用
+ def center_show(self, offset):
+ geo = self.frameGeometry()
+ cp = QDesktopWidget().availableGeometry().center() # 获取显示器分辨率,并找到中间点
+ if offset:
+ print("窗口偏置")
+ geo.moveCenter(cp + offset) # 将窗口中点偏置
+ else:
+ geo.moveCenter(cp) # 将窗口中点放在屏幕中间
+ self.move(geo.topLeft())
+
+ def show_msg(self,text):
+ self.fade_timer.start()
+ self.msg_label.setText(text)
+ self.msg_label.repaint()
+ self.raise_()
+ self.show()
+ self.center_show(QPoint(75,0))
+ self.exec_() # 动画弹出
+ sleep(0.5)
+
+
+
+ def faded_out(self):
+ print("窗口渐隐")
+ for i in range(80,0,-1):
+ opacity = i/100
+ print("opacity:",opacity)
+ self.setWindowOpacity(opacity) # 设置窗口透明度
+ self.repaint()
+ QApplication.processEvents()
+ sleep(0.05)
+
+ self.fade_timer.stop()
+ self.close()
+
+
+if __name__ == "__main__":
+ import sys
+ app = QApplication(sys.argv)
+ msg = Msg()
+ msg.show_msg("测试信息...")
+ sys.exit(app.exec_())
\ No newline at end of file
import intelhex
import yn_download
import mk_ota_image
+import popup
+import serial
#生成CRC16-MODBUS校验码
#crc16 = crcmod.mkCrcFun(0x18005, rev=True, initCrc=0xFFFF, xorOut=0x0000)
class App( QDialog, ui_welding.Ui_Dialog ):
trigger_rx_pkt = pyqtSignal( tuple )
+ trigger_ctrl_write = pyqtSignal( tuple )
def __init__( self ):
super().__init__()
self.setupUi(self)
- self.setWindowTitle( u"焊接控制器调试工具 V0.5")
+ self.setWindowTitle( u"焊接控制器调试工具 V0.6")
self.trigger_rx_pkt.connect( self.on_rx_pkt )
+ self.trigger_ctrl_write.connect( self.on_ctrl_write_signal )
self.ser_opened = False
self.connected = 0 #0-disconnect 1-devinfo 2-curr 3-update
+ self.tabWidget.currentChanged.connect( self.on_tab_changed )
self.btn_devinfo.released.connect( lambda:self.on_table_select(1) )
self.btn_curr.released.connect( lambda:self.on_table_select(2) )
self.btn_update.released.connect( lambda:self.on_table_select(3) )
self.btn_cfg.released.connect( lambda:self.on_table_select(4) )
+ self.btn_ctrl.released.connect( lambda:self.on_table_select(5) )
self.tabWidget.findChild( QTabBar).hide()
self.btn_connect_devinfo.released.connect( lambda:self.on_btn_connect(1))
###self.cbx_debug.release
#self.cbx_debug.stateChanged.connect( lambda:self.on_cbx_debug() )
- self.cb_debug_mode.currentIndexChanged.connect( self.on_cb_debug_mode )
+ self.cb_weld_curr_debug.stateChanged.connect( self.on_cb_weld_curr_debug )
+ #self.cb_debug_mode.currentIndexChanged.connect( self.on_cb_debug_mode )
self.btn_debug_write.released.connect( self.on_btn_debug_write )
self.debug_mode = 0
- self.on_cb_debug_mode(0)
+ self.on_cb_weld_curr_debug()
+
+ self.cfg_timer = QTimer()
+ self.cfg_timer.timeout.connect(self.on_cfg_timer)
self.io_timer = QTimer()
self.io_timer.timeout.connect(self.on_scan_timer)
self.btn_gas_read.released.connect( self.on_btn_gas_read )
self.btn_gas_write.released.connect( self.on_btn_gas_write )
+ self.btn_flow_alarm_read.released.connect( self.on_btn_alarm_read )
+ self.btn_flow_alarm_write.released.connect( self.on_btn_alarm_write )
+
+ self.btn_tig.released.connect( lambda: self.trigger_ctrl_write.emit(( "method", "tig" ) ))
+ self.btn_mig.released.connect( lambda: self.trigger_ctrl_write.emit(( "method", "mig" ) ))
+ self.btn_mag.released.connect( lambda: self.trigger_ctrl_write.emit(( "method", "mag" ) ))
+ self.btn_factor_add.released.connect( lambda: self.trigger_ctrl_write.emit(( "factor", "add" ) ))
+ self.btn_factor_sub.released.connect( lambda: self.trigger_ctrl_write.emit(( "factor", "sub" ) ))
+ self.btn_prev_add.released.connect( lambda: self.trigger_ctrl_write.emit(( "prev", "add" ) ))
+ self.btn_prev_sub.released.connect( lambda: self.trigger_ctrl_write.emit(( "prev", "sub" ) ))
+ self.btn_bypass_on.released.connect( lambda: self.trigger_ctrl_write.emit(( "bypass", "on" ) ))
+ self.btn_bypass_off.released.connect( lambda: self.trigger_ctrl_write.emit(( "bypass", "off" ) ))
+
+ def on_ctrl_write_signal( self, cmd ):
+ if not self.ser_opened:
+ if not self.ser_open():
+ return
+
+ item, action = cmd
+ if item == "timer":
+ self.tx_cmd( cmd = 0x00B6, wait=False )
+ else:
+ #B6 read cfg, 节气因子4B,工艺4B,前气开度4B,流量计补偿值4B,流量计气体修正系数4B, 气路选择掉电保存
+ method = factor = prev = comp = coeff = bypass_save = bypass = 0x7FFFFFFF
+ if item == "method" :
+ method = 0 if action == "tig" else 1 if action=="mig" else 2
+ elif item == "factor":
+ factor = int(self.label_factor.text())
+ factor += 1 if action == "add" else -1 if action == "sub" else 0
+ factor = 100 if factor>100 else 0 if factor < 0 else factor
+ elif item == "prev":
+ prev = int(self.label_prev.text())
+ prev += 1 if action == "add" else -1 if action == "sub" else 0
+ prev = 100 if prev>100 else 0 if prev < 0 else prev
+ elif item == "bypass":
+ bypass = 1 if action == "on" else 0 if action=="off" else bypass
+ else:
+ return
+ self.tx_cmd( cmd = 0x00B7, data=struct.pack( '>LLLlLLL', method, factor, prev, comp, coeff, bypass_save, bypass ), wait=False )
+
def on_btn_mk_ota_img(self):
file , check = QFileDialog.getOpenFileName(None, u"选择固件", "", "image (*hex *bin)")
print("select fw file:{}, check:{}".format( file, check) )
print( "save file:%s len:%d/%08X Bytes"%( save_name, len(img_data), len( img_data)))
ota_fd.write( img_data )
+ def on_btn_alarm_read( self ):
+ self.on_btn_gas_read()
+ def on_btn_alarm_write( self ):
+ if self.ser_open():
+ self.tx_cmd( cmd = 0xC1, data=struct.pack( ">BBL", 0xFF, 0xFF, int( 1000*float(self.lineEdit_flow_low_alarm.text() ) ) ) )
+ self.ser_close()
+
def on_btn_gas_read( self ):
if self.ser_open():
self.tx_cmd( cmd = 0xC0 )
self.ser_close()
def on_btn_gas_write( self ):
if self.ser_open():
- self.tx_cmd( cmd = 0xC1, data=struct.pack( ">BB", self.cb_flow_sel.currentIndex(), self.cb_gas_sel.currentIndex() ) )
+ self.tx_cmd( cmd = 0xC1, data=struct.pack( ">BBL", self.cb_flow_sel.currentIndex(), self.cb_gas_sel.currentIndex(), 0xFFFFFFFF ) )
self.ser_close()
def on_btn_rpt_period_read( self ):
self.tx_cmd( cmd = 0x00BD, data=self.lineEdit_dev_sn.text().split()[0].encode("utf8") )
self.ser_close()
+ def on_cfg_timer( self ):
+ self.trigger_ctrl_write.emit( ("timer", "read" ) )
+
def on_btn_cfg_read( self, cfg ):
if self.connected != 0 or self.ser_opened:
return
if cfg == 1 or cfg == 2:
- #B6 read cfg, 节气因子4B,工艺4B,前气开度4B,流量计补偿值4B,流量计气体修正系数4B
+ #B6 read cfg, 节气因子4B,工艺4B,前气开度4B,流量计补偿值4B,流量计气体修正系数4B, bypass_save 4B, bypass 4B
cmd = 0x00B6
elif cfg == 3:
cmd = 0x00B8
if cfg == 1:
#B6 read cfg, 节气因子4B,工艺4B,前气开度4B,流量计补偿值4B,流量计气体修正系数4B, 气路选择掉电保存
cmd = 0x00B7
- d = struct.pack( '>LLLlLL',
+ d = struct.pack( '>LLLlLLL',
#int(self.lineEdit_cfg_method.text()),
self.cb_cfg_method.currentIndex(),
int(self.lineEdit_cfg_factor.text()),
int(self.lineEdit_cfg_prev.text()),
- 100000, #填无效值
- 100000, #填无效值
- 1 if self.cb_path_save.isChecked() else 0
+ 0x7FFFFFFF, #填无效值 comp
+ 0x7FFFFFFF, #填无效值 coeff 修正系数
+ 1 if self.cb_path_save.isChecked() else 0,
+ 0x7FFFFFFF #填无效值 bypass
)
print( "write cfg cmd:%04X"%cmd, d.hex())
elif cfg == 2:
cmd = 0x00B7
- d = struct.pack( '>LLLlLL',
- 100000, #填无效值
- 100000, #填无效值
- 100000, #填无效值
+ d = struct.pack( '>LLLlLLL',
+ 0x7FFFFFFF, #填无效值
+ 0x7FFFFFFF, #填无效值
+ 0x7FFFFFFF, #填无效值
int(self.lineEdit_flow_comp.text()),
- #int(self.lineEdit_flow_coeff.text())
gas_coefficient[ self.cb_flow_coeff.currentIndex()][1],
- 0xFFFFFFFF, #填无效值
+ 0x7FFFFFFF, #填无效值
+ 0x7FFFFFFF #填无效值
)
elif cfg == 3:
cmd = 0x00B9
if self.ser_opened:
print( "write cmd close debug_mode ")
self.ser.write( self.wrap_close_debug_mode_pkt() )
- def on_cb_debug_mode( self, idx ):
- if idx == 0:
- self.label_debug_curr_unit.setText( "A")
+ def on_cb_weld_curr_debug(self):
+ self.label_debug_curr_unit.setText( "A")
+ if self.cb_weld_curr_debug.isChecked():
+ self.btn_debug_write.setEnabled(1)
+ self.debug_mode = 1
+ else:
self.close_debug_mode()
self.btn_debug_write.setEnabled(0)
- elif idx == 1:
- self.label_debug_curr_unit.setText( "A")
- self.btn_debug_write.setEnabled(1)
- elif idx == 2:
- self.label_debug_curr_unit.setText( "mA")
- self.btn_debug_write.setEnabled(1)
- self.debug_mode = idx
+ self.debug_mode = 0
def on_btn_debug_write( self ):
if self.ser_opened:
curr = int( self.lineEdit_debug_value.text() )
elif self.debug_mode == 2:
cmd = self.wrap_valve_curr_pkt( curr )
self.ser.write( cmd )
+
def on_table_select( self, index ):
print( "on table select ", index )
- self.tabWidget.setCurrentIndex( index-1 )
+ curr_tab = self.tabWidget.currentIndex() +1 # tab : 1/2/3/4/5
+ if index == curr_tab:
+ return
+ if index == 5:
+ try:
+ if self.ser_opened:
+ self.ser_close()
+ if self.ser_open():
+ if self.connected:
+ self.tx_cmd( 0x0022, struct.pack( '>L', 0 ))
+ self.connected = index
+ self.tabWidget.setCurrentIndex( index-1 )
+ self.cfg_timer.start( 1000 )
+ except serial.serialutil.SerialException:
+ msg = popup.Msg( self )
+ msg.show_msg( text="打开串口失败...")
+
+ else:
+ if curr_tab == 5:
+ if self.ser_opened:
+ self.ser_close()
+ self.connected = 0
+ self.cfg_timer.stop()
+ self.tabWidget.setCurrentIndex( index-1 )
+
+ def on_tab_changed( self ):
+ index = self.tabWidget.currentIndex()+1
self.btn_devinfo.setStyleSheet( "background-color: green" if index==1 else "background-color: lightgray" )
self.btn_curr.setStyleSheet( "background-color: green" if index==2 else "background-color: lightgray" )
self.btn_update.setStyleSheet( "background-color: green" if index==3 else "background-color: lightgray" )
self.btn_cfg.setStyleSheet( "background-color: green" if index==4 else "background-color: lightgray" )
+ self.btn_ctrl.setStyleSheet( "background-color: green" if index==5 else "background-color: lightgray" )
- def tx_cmd( self, cmd, data=b'', resp_cb=None ):
+ def tx_cmd( self, cmd, data=b'', resp_cb=None, wait=True ):
pkt = self.wrap_pkt( cmd, data )
#print( "tx pkt[%04X]:"%cmd, pkt.hex() )
self.ser.write( pkt )
-
self.wait_resp = ( cmd, False, resp_cb ) # wait resp cmd, rx cmd, rx result
+ if not wait:
+ return True
retry = 10
while not self.wait_resp[1] and retry>0 :
time.sleep( 0.1)
self.curve_valve_curr.setData( np.array( self.flow_x), np.array( self.valve_curr_y))
self.curve_flow.setData( np.array( self.flow_x), np.array( self.flow_y))
self.curve_flow_target.setData( np.array( self.flow_x), np.array( self.flow_target_y))
- elif cmd == 0x00B6 and len(data)>=20: #参数读取
+ elif (cmd == 0x00B6 or cmd==0x10B7) and len(data)>=20: #参数读取
print( "B6 resp:", data.hex() )
- #//节气因子4B,工艺4B,前气开度4B,流量计补偿值4B,流量计气体修正系数4B
- method, factor, prev, comp, coeff, bypass_save = struct.unpack( '>LLLlLL', data )
+ #//节气因子4B,工艺4B,前气开度4B,流量计补偿值4B,流量计气体修正系数4B, 气路选择断电保存4B, 气路选择4B
+ method, factor, prev, comp, coeff, bypass_save, bypass = struct.unpack( '>LLLlLLL', data[:28] )
#self.lineEdit_cfg_method.setText( "%d"%method )
self.lineEdit_cfg_factor.setText( "%d"%factor )
self.lineEdit_cfg_prev.setText( "%d"%prev )
self.lineEdit_flow_comp.setText( "%d"%comp )
self.lineEdit_flow_coeff.setText( "%d"%coeff)
self.cb_cfg_method.setCurrentIndex( method )
+
+ self.btn_tig.setStyleSheet( "background-color: green" if method==0 else "background-color: lightgray" )
+ self.btn_mig.setStyleSheet( "background-color: green" if method==1 else "background-color: lightgray" )
+ self.btn_mag.setStyleSheet( "background-color: green" if method==2 else "background-color: lightgray" )
+ self.label_factor.setText( "%d"%factor )
+ self.label_prev.setText( "%d"%prev )
+ self.btn_bypass_on.setStyleSheet( "background-color: green" if bypass==1 else "background-color: lightgray" )
+ self.btn_bypass_off.setStyleSheet( "background-color: green" if bypass==0 else "background-color: lightgray" )
+
for idx in range(len(gas_coefficient)):
if gas_coefficient[idx][1] == coeff:
self.cb_flow_coeff.setCurrentIndex(idx)
elif cmd == 0x00BE and len(data)==4: #上报周期读取
self.lineEdit_rpt_period.setText( str( struct.unpack( '>L', data )[0] ) )
elif cmd == 0x00C0 and len(data)>=2: #读取参数2
- flow, gas = struct.unpack( ">BB", data )
+ flow, gas, alarm_x1000 = struct.unpack( ">BBL", data )
self.cb_flow_sel.setCurrentIndex( flow )
self.cb_gas_sel.setCurrentIndex( gas )
+ self.lineEdit_flow_low_alarm.setText( "%.1f"%(alarm_x1000/1000))
+ elif cmd == 0x00C2 and len(data)>=1: #读取参数2
+ self.btn_bypass_on.setStyleSheet( "background-color: green" if data[0]==1 else "background-color: lightgray" )
+ self.btn_bypass_off.setStyleSheet( "background-color: green" if data[0]==0 else "background-color: lightgray" )
if cmd == self.wait_resp[0]:
self.wait_resp = ( cmd, True, data[0] )
<rect>
<x>0</x>
<y>0</y>
- <width>1535</width>
+ <width>1333</width>
<height>845</height>
</rect>
</property>
<property name="geometry">
<rect>
<x>10</x>
- <y>20</y>
+ <y>280</y>
<width>121</width>
<height>81</height>
</rect>
<property name="geometry">
<rect>
<x>10</x>
- <y>110</y>
+ <y>370</y>
<width>121</width>
<height>81</height>
</rect>
<property name="geometry">
<rect>
<x>10</x>
- <y>300</y>
+ <y>100</y>
<width>121</width>
<height>81</height>
</rect>
</property>
<property name="text">
- <string>参数配置</string>
+ <string>参数读写</string>
</property>
<property name="autoDefault">
<bool>false</bool>
<property name="geometry">
<rect>
<x>10</x>
- <y>210</y>
+ <y>10</y>
<width>121</width>
<height>81</height>
</rect>
<bool>false</bool>
</property>
</widget>
+ <widget class="QPushButton" name="btn_ctrl">
+ <property name="geometry">
+ <rect>
+ <x>10</x>
+ <y>190</y>
+ <width>121</width>
+ <height>81</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>在线操作</string>
+ </property>
+ <property name="autoDefault">
+ <bool>false</bool>
+ </property>
+ </widget>
</widget>
<widget class="QGroupBox" name="groupBox_2">
<property name="geometry">
<rect>
<x>160</x>
<y>10</y>
- <width>1201</width>
+ <width>1171</width>
<height>831</height>
</rect>
</property>
</rect>
</property>
<property name="currentIndex">
- <number>3</number>
+ <number>2</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<enum>Qt::Horizontal</enum>
</property>
</widget>
- <widget class="QComboBox" name="cb_debug_mode">
+ <widget class="QLabel" name="label_debug_curr_unit">
<property name="geometry">
<rect>
- <x>10</x>
+ <x>200</x>
<y>20</y>
- <width>121</width>
+ <width>21</width>
<height>31</height>
</rect>
</property>
- <property name="editable">
- <bool>true</bool>
- </property>
- <property name="duplicatesEnabled">
- <bool>false</bool>
- </property>
- <property name="frame">
- <bool>true</bool>
+ <property name="text">
+ <string>A</string>
</property>
- <item>
- <property name="text">
- <string>关闭模拟调试</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string>模拟焊接电流</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string>比例阀控制电流</string>
- </property>
- </item>
</widget>
- <widget class="QLabel" name="label_debug_curr_unit">
+ <widget class="QCheckBox" name="cb_weld_curr_debug">
<property name="geometry">
<rect>
- <x>200</x>
- <y>20</y>
- <width>21</width>
- <height>31</height>
+ <x>10</x>
+ <y>10</y>
+ <width>101</width>
+ <height>41</height>
</rect>
</property>
<property name="text">
- <string>A</string>
+ <string>模拟焊接电流</string>
</property>
</widget>
</widget>
</item>
</widget>
</widget>
+ <widget class="QGroupBox" name="groupBox_18">
+ <property name="geometry">
+ <rect>
+ <x>490</x>
+ <y>510</y>
+ <width>421</width>
+ <height>151</height>
+ </rect>
+ </property>
+ <property name="title">
+ <string>报警阈值</string>
+ </property>
+ <widget class="QPushButton" name="btn_flow_alarm_write">
+ <property name="geometry">
+ <rect>
+ <x>330</x>
+ <y>40</y>
+ <width>81</width>
+ <height>71</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>写入</string>
+ </property>
+ </widget>
+ <widget class="QPushButton" name="btn_flow_alarm_read">
+ <property name="geometry">
+ <rect>
+ <x>250</x>
+ <y>40</y>
+ <width>81</width>
+ <height>71</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>读取</string>
+ </property>
+ </widget>
+ <widget class="QLineEdit" name="lineEdit_flow_low_alarm">
+ <property name="geometry">
+ <rect>
+ <x>120</x>
+ <y>80</y>
+ <width>111</width>
+ <height>31</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>0</string>
+ </property>
+ <property name="readOnly">
+ <bool>false</bool>
+ </property>
+ </widget>
+ <widget class="QLabel" name="label_34">
+ <property name="geometry">
+ <rect>
+ <x>10</x>
+ <y>30</y>
+ <width>131</width>
+ <height>31</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>低流量报警值(L/min)</string>
+ </property>
+ </widget>
+ <widget class="QLabel" name="label_35">
+ <property name="geometry">
+ <rect>
+ <x>140</x>
+ <y>30</y>
+ <width>101</width>
+ <height>31</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>设为0则关闭报警</string>
+ </property>
+ </widget>
+ </widget>
</widget>
</widget>
</widget>
+ <widget class="QWidget" name="tab_9">
+ <attribute name="title">
+ <string>页</string>
+ </attribute>
+ <widget class="QGroupBox" name="groupBox_20">
+ <property name="geometry">
+ <rect>
+ <x>20</x>
+ <y>30</y>
+ <width>251</width>
+ <height>91</height>
+ </rect>
+ </property>
+ <property name="title">
+ <string>焊接工艺</string>
+ </property>
+ <widget class="QPushButton" name="btn_tig">
+ <property name="geometry">
+ <rect>
+ <x>30</x>
+ <y>30</y>
+ <width>51</width>
+ <height>51</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>TIG</string>
+ </property>
+ </widget>
+ <widget class="QPushButton" name="btn_mig">
+ <property name="geometry">
+ <rect>
+ <x>100</x>
+ <y>30</y>
+ <width>51</width>
+ <height>51</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>MIG</string>
+ </property>
+ </widget>
+ <widget class="QPushButton" name="btn_mag">
+ <property name="geometry">
+ <rect>
+ <x>170</x>
+ <y>30</y>
+ <width>51</width>
+ <height>51</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>MAG</string>
+ </property>
+ </widget>
+ </widget>
+ <widget class="QGroupBox" name="groupBox_21">
+ <property name="geometry">
+ <rect>
+ <x>20</x>
+ <y>140</y>
+ <width>251</width>
+ <height>91</height>
+ </rect>
+ </property>
+ <property name="title">
+ <string>节气因子</string>
+ </property>
+ <widget class="QPushButton" name="btn_factor_sub">
+ <property name="geometry">
+ <rect>
+ <x>30</x>
+ <y>30</y>
+ <width>51</width>
+ <height>51</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>-</string>
+ </property>
+ </widget>
+ <widget class="QPushButton" name="btn_factor_add">
+ <property name="geometry">
+ <rect>
+ <x>170</x>
+ <y>30</y>
+ <width>51</width>
+ <height>51</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>+</string>
+ </property>
+ </widget>
+ <widget class="QLabel" name="label_factor">
+ <property name="geometry">
+ <rect>
+ <x>100</x>
+ <y>30</y>
+ <width>54</width>
+ <height>41</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>0</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ </widget>
+ <widget class="QGroupBox" name="groupBox_22">
+ <property name="geometry">
+ <rect>
+ <x>20</x>
+ <y>250</y>
+ <width>251</width>
+ <height>91</height>
+ </rect>
+ </property>
+ <property name="title">
+ <string>前后气调节</string>
+ </property>
+ <widget class="QPushButton" name="btn_prev_sub">
+ <property name="geometry">
+ <rect>
+ <x>30</x>
+ <y>30</y>
+ <width>51</width>
+ <height>51</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>-</string>
+ </property>
+ </widget>
+ <widget class="QPushButton" name="btn_prev_add">
+ <property name="geometry">
+ <rect>
+ <x>170</x>
+ <y>30</y>
+ <width>51</width>
+ <height>51</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>+</string>
+ </property>
+ <property name="autoRepeat">
+ <bool>false</bool>
+ </property>
+ </widget>
+ <widget class="QLabel" name="label_prev">
+ <property name="geometry">
+ <rect>
+ <x>100</x>
+ <y>30</y>
+ <width>54</width>
+ <height>41</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>0</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ </widget>
+ <widget class="QGroupBox" name="groupBox_23">
+ <property name="geometry">
+ <rect>
+ <x>20</x>
+ <y>360</y>
+ <width>251</width>
+ <height>91</height>
+ </rect>
+ </property>
+ <property name="title">
+ <string>气路选择</string>
+ </property>
+ <widget class="QPushButton" name="btn_bypass_off">
+ <property name="geometry">
+ <rect>
+ <x>30</x>
+ <y>20</y>
+ <width>71</width>
+ <height>61</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>智能节气</string>
+ </property>
+ </widget>
+ <widget class="QPushButton" name="btn_bypass_on">
+ <property name="geometry">
+ <rect>
+ <x>140</x>
+ <y>20</y>
+ <width>81</width>
+ <height>61</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>旁路直通</string>
+ </property>
+ </widget>
+ </widget>
+ </widget>
+ <widget class="QWidget" name="tab_10">
+ <attribute name="title">
+ <string>页</string>
+ </attribute>
+ </widget>
</widget>
</widget>
</widget>
self.rx_pkt = pkt
self.rx_event.set()
- def transmit(self, tx, timeout = 5, retry=1 ):
+ def transmit(self, tx, timeout = 5, retry=1, verbose=1 ):
while retry>0:
retry -= 1
self.rx_event.clear()
if self.rx_event.wait( timeout= timeout ):
print( "接收[%d]: %s ..."%( len(self.rx_pkt), self.rx_pkt[:64].hex() ) )
return True
- else:
+ elif verbose:
self.log_add( '数据传输超时!', 'error')
except:
- self.log_add( '数据发送失败!', 'error')
- #TODO : raise excpection
+ if verbose:
+ self.log_add( '数据发送失败!', 'error')
return False
def connect(self):
self.log_add( u"连接设备 ... ")
#read uuid
print( "++++++++++++++++++++++++++++++++++")
- resp = self.transmit( self.wrap_query_pkt(), timeout = 2, retry = 5 )
- if resp:
+ err = 0
+
+ if self.transmit( self.wrap_query_pkt(), timeout = 2, retry = 3 ):
if len(self.rx_pkt)>=32:
if self.rx_pkt[7]==0x42:
self.log_add( u'连接成功', 'info')
self.log_add( '-'*50 + '\n' )
- return True
+ return 1
elif self.rx_pkt[7]==0x41:
#app , reboot to download
#resp = self.transmit( self.wrap_reboot_pkt( mode =0x544F4F42 ), timeout = 2, retry = 5 )
print( "reboot to download mode -------------------------------------")
- resp = self.transmit( self.wrap_pkt( 0x00A0 ), timeout = 2, retry = 5 )
- pass
- else:
- self.log_add( u'连接错误', 'error' )
- else:
- self.log_add( '连接超时', 'error')
- return False
+ self.log_add( u'当前工作模式,切换到下载模式...', 'info')
+ resp = self.transmit( self.wrap_pkt( 0x00A0 ), timeout = 2, retry = 1, verbose=0 )
+ return 0
+ self.log_add( '连接超时', 'error')
+ return -1
def run(self ):
self.log_clear()
pkgs = self.parse_image()
#if self.pbar:
# self.pbar['maximum'] = len(pkgs)
- self.s = ser.ser()
- try:
- self.s.open( self.port, self.baudrate, self.rx_handler)
- except:
- self.log_add( '打开串口失败!', 'error')
- self.trigger_end.emit()
- return
- if not self.connect():
- self.s.close()
- self.trigger_end.emit()
- return
+ connect_result = 0
+ while connect_result==0:
+ self.s = ser.ser()
+ try:
+ self.s.open( self.port, self.baudrate, self.rx_handler)
+ except:
+ self.log_add( '打开串口失败!', 'error')
+ self.trigger_end.emit()
+ return
+ connect_result = self.connect()
+ if connect_result < 0:
+ self.s.close()
+ self.trigger_end.emit()
+ return
self.log_add( '下载开始 ... %s'%(time.strftime('%H:%M:%S')), 'info' )
t0 = time.time()
self.log_add( "下载时间: \t%d 秒"%( time.time()-t0 ), 'info' )
self.transmit( self.wrap_readcrc_pkt(), timeout = 2 )
self.log_add( "重启系统 ... ", 'info' )
- if self.transmit( self.wrap_reboot_pkt(), timeout=2 ):
- pass
- else:
- pass
+ self.transmit( self.wrap_reboot_pkt(), timeout=0, retry=1, verbose=0 )
+ # pass
+ #else:
+ # pass
+ print( "xxx" )
else:
self.log_add( "校验错误, 固件CRC:%04X, 读取CRC:%04X"%( img_crc, flash_crc), "error" )
else:
SCREENDSIZE=480X272
SPADDRESS=5000
[IMG]
-0=0.png
-1=1.png
-2=2.png
-3=3.png
-5=5.png
-20=20.jpg
-21=21.jpg
-22=22.jpg
-23=23.jpg
-6=6.png
-7=7.png
-4=4.png
+0=10.png
+1=0.png
+2=1.png
+3=2.png
+4=3.png
+5=4.png
+6=5.png
+7=6.png
+8=7.png
+9=20.jpg
+10=21.jpg
+11=22.jpg
+12=23.jpg
#include "gpio.h"
//#include "fmc.h"
//--------------------
+#define APP_VER_MAJOR 2
+#define APP_VER_MINOR 13
+
+
+#define FLOW_SPEED_FS 50 //流量计满量程50L/min
+#define PRESSURE_KPA_FS 700 //气压最大量程 700Kpa
+
#define VALVE_CTRL_200MA 1 //比例阀控制电流最大按200mA ( 规格书定义为最大165mA)
+#if VALVE_CTRL_200MA
+#define VALVE_MAX_CURR_FLOAT 0.200f //0.2A
+#else
+#define VALVE_MAX_CURR_FLOAT 0.165f //0.165A
+#endif
#define FLOWMETER_SCAN 0 //自动检查流量计
#define FLOWMETER_AFM0750 1 //奥松流量计
#define GAS_MAX 3
-#define APP_VER_MAJOR 2
-#define APP_VER_MINOR 13
-
#define DEVICE_SN_DEFAULT "A" "02" "01" "240506" "000001"
#define DEVICE_SN_SIZE 17
#define USER_LFS_PART_ADDR 0x00100000 //1M
#define USER_LFS_PART_SIZE 0x00300000 //+3M
+/*
+2024/5/13 新增需求如下
+产品优化的几点建议:
+1、氩弧焊要求最低18L/min,考虑上位机增加最低流量参数设置;
+2、流量过低,增加报警提示音,控制比例阀仍达不到效果,考虑切换为直通模式;
+3、流量过大(超过95%FS),增加报警提示音,并控制比例阀将流量控制在95%FS以内,以保护流量计;
+4、气压过大(超过最大压力的95%,当前选型最大压力是0.7MPa),增加报警提示音(目前无法控制气压,后续产品规划再优化)
+
+软件设计:
+1. 增加报警阈值参数,单位0.001 L/min, 0忽略,不为0则生效
+2. 焊接时目标流量大于阈值,而实际流量低于阈值 10秒后报警,再10秒报警音后切换直通阀,
+3. 流量超过 50L/min * 0.95,10秒后报警,不论节气或旁路,算法计算目标流量值按0.95*50L/min为上限最大值。
+4. 气压大于 0.7Mpa*.95 10秒后报警
+5. 报警音:
+ 气压高报警:报警音 1长 -- 响2秒,停0.5秒
+ 流量高报警:报警音 1长 1短 -- 响2秒,停0.2秒,响0.2秒,停0.5s
+ 流量低报警:报警音 1长 2短 -- 响2秒,停0.2秒,响0.2秒,停0.2s,响0.2秒,停0.5s
+ 以上报警音优先级:气压报警 > 高流量报警 > 低流量报警 > 设备原来的故障报警
+*/
typedef struct{
uint32_t id;
}dev_cfg_t;
#if 1
-//TODO
//新增配置项放到这个里面, 避免原配置结构修改,避免升级固件后原参数被清掉。
-
#define DEV_CFG_V2_FLAG 0xA0
typedef struct{
- uint32_t flowmeter; //流量计类型, 0:自动, 1:奥松, 2:MF 3:SMC 4: 其他
- uint32_t gas; //气体类型, 0:未指定, 1:氩气, 2:二氧化碳, 3: 混合气1, 4:混合气2, 5: 其他
+ uint32_t flow_low_alarm_x1000; //最低流量报警阈值, 单位0.001L/min
+ uint8_t flowmeter; //流量计类型, 0:自动, 1:奥松, 2:MF 3:SMC 4: 其他
+ uint8_t gas; //气体类型, 0:未指定, 1:氩气, 2:二氧化碳, 3: 混合气1, 4:混合气2, 5: 其他
uint8_t bl; //0-4 5级
- uint8_t reserved[30];
+ uint8_t reserved[24];
uint8_t flag;
}dev_cfg_v2_t;
#endif
+typedef struct{ //表示设备报警状态
+ uint32_t flow_low; //1:流量低报警,
+ uint32_t flow_high; //1: 流量高报警
+ uint32_t pressure_high; //1:气压高报警
+}alarm_t;
+
//故障码bit位定义
#define CURR_SENSOR_ERR ( 1<<0 ) //电流传感器故障
#define FLOWMETER_ERR ( 1<<1 ) //流量计故障
#define TEMP_ERR ( 1<<3 ) //超温故障
#define SFLASH_ERR ( 1<<4 ) //spi flash 故障
#define VALVE_CTRL_ERR ( 1<<5 ) //比例阀电流控制 AD5245 故障
-#define WIFI_ERR ( 1<<6 )
+#define WIFI_ERR ( 1<<6 ) //WIFI模块故障
typedef struct {
//调试功能
uint32_t debug_report; //主动上报数据, 0:关闭, 1:上报控制信息, 2:上报焊接电流信息
- uint32_t debug_curr; //模拟数据, 0:关闭, 1:模拟焊接电流,2:设置比例阀输出电流
+ uint32_t debug_curr; //模拟数据, 0:关闭, 1:模拟焊接电流
float debug_welding_curr; //模拟焊接电流 A
- float debug_valve_curr; //设置比例阀输出电流 A
-
+
uint32_t wifi_connected; //0:disconnect, 1:wifi connected, 2:tcp connected
uint32_t eth_connected; //0: eth disconnect, 1:eth connected, 2::tcp connected
char serial_number[32];
+ alarm_t alarm;
}dev_info_t;
extern TIM_HandleTypeDef htim2; //htim2 用于触发DMA ADC采集
extern void debug_task_start( void );
extern void wifi_task_start( void );
extern void eth_task_start( void );
-
+
void StartDefaultTask(void *argument)
{
/* init code for USB_DEVICE */
if( cfg->gas > GAS_MAX ){
cfg->gas = GAS_DEFAULT;
}
+
+ if( cfg->flow_low_alarm_x1000 == 0xffffffff ){
+ cfg->flow_low_alarm_x1000 = 0;
+ }
+
return 0;
}
void user_beep_task( void* unused )
{
int i;
- GPIO_InitTypeDef GPIO_InitStruct = {0};
+ GPIO_InitTypeDef GPIO_InitStruct = {0};
#if 0
//beep off
//无源蜂鸣器,PWM控制频率
osDelay( 500);
HAL_TIM_PWM_Stop( &htim13, TIM_CHANNEL_1 );
#endif
-
+
//有源蜂鸣器,配置为输出脚
HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_RESET);
GPIO_InitStruct.Pin = PF8_PWM_SPK_TIM13_CH1_Pin;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, &GPIO_InitStruct);
+ //开机叫一下
HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_SET);
osDelay(50);
HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_RESET);
//TODO: 实际使用有源, 待修改代码
while(1){
+
+ //气压和流量报警优先, 以上报警音,优先级, 气压报警 > 高流量报警 > 低流量报警
+ //有以上报警, 后面的故障报警,暂停输出
+ if( g_dev.alarm.pressure_high ){
+ //气压高报警:报警音 1长 -- 响2秒,停0.5秒
+ HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_SET);
+ osDelay(2000);
+ HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_RESET);
+ osDelay(500);
+ continue;
+ }else if( g_dev.alarm.flow_high ){
+ //流量高报警:报警音 1长 1短 -- 响2秒,停0.2秒,响0.2秒,停0.5s
+ HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_SET);
+ osDelay(2000);
+ HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_RESET);
+ osDelay(200);
+ HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_SET);
+ osDelay(200);
+ HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_RESET);
+ osDelay(500);
+ continue;
+ }else if( g_dev.alarm.flow_low ){
+ //流量低报警:报警音 1长 2短 -- 响2秒,停0.2秒,响0.2秒,停0.2s,响0.2秒,停0.5s
+ HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_SET);
+ osDelay(2000);
+ HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_RESET);
+ osDelay(200);
+ HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_SET);
+ osDelay(200);
+ HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_RESET);
+ osDelay(200);
+ HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_SET);
+ osDelay(200);
+ HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_RESET);
+ osDelay(500);
+ continue;
+ }
+
//TODO: 按需要增加提示音管理
if( g_dev.state & FLOWMETER_ERR ){
HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_SET);
g_dev.debug_curr = 1;
break;
case 0x00f2:
- //写比例阀控制电流
- g_dev.debug_valve_curr = get_u32_big( pkt->pdata )/1000.0f;
- g_dev.debug_curr = 2;
+ //写比例阀控制电流, 取消
+ //g_dev.debug_valve_curr = get_u32_big( pkt->pdata )/1000.0f;
+ //g_dev.debug_curr = 2;
break;
case 0x0022:
if( pkt->data_len >=4 ){
case 0xB5: //焊接数据清0
break;
case 0xB6: //设备参数读取
- //工艺4B,节气因子4B,前气开度4B,流量计补偿值4B,流量计气体修正系数4B, bypas断电保存 4B
+ //工艺4B,节气因子4B,前气开度4B,流量计补偿值4B,流量计气体修正系数4B, bypas断电保存 4B bypass 4B
put_u32_big( &resp[0], g_dev.cfg.welding_method );
put_u32_big( &resp[4], g_dev.cfg.save_gas_factor );
put_u32_big( &resp[8], g_dev.cfg.valve_open_default );
put_u32_big( &resp[12], g_dev.cfg.cal.flow_comp_x1000 );
put_u32_big( &resp[16], g_dev.cfg.cal.flow_coeff_x1000 );
put_u32_big( &resp[20], g_dev.cfg.bypass_save );
- tx_n = wrap_resp_pkt( tx_pkt, pkt->cmd, resp, 24 );
+ put_u32_big( &resp[24], g_dev.cfg.bypass );
+ tx_n = wrap_resp_pkt( tx_pkt, pkt->cmd, resp, 28 );
break;
case 0xB7: //设备参数写入
- //工艺4B,节气因子4B,前气开度4B,流量计补偿值4B,流量计气体修正系数4B, bypas断电保存 4B
+ //工艺4B,节气因子4B,前气开度4B,流量计补偿值4B,流量计气体修正系数4B, bypas断电保存 4B, bypass 4B
{
uint32_t method = get_u32_big( &pkt->pdata[0] );
uint32_t factor = get_u32_big( &pkt->pdata[4] );
int32_t comp = get_u32_big( &pkt->pdata[12] );
uint32_t coeff = get_u32_big( &pkt->pdata[16] );
uint32_t bypass_save = get_u32_big( &pkt->pdata[20] );
+ uint32_t bypass = get_u32_big( &pkt->pdata[24] );
if( factor >=2 && factor <= 30 )
g_dev.cfg.save_gas_factor = factor;
g_dev.cfg.cal.flow_coeff_x1000 = coeff;
if( bypass_save == 1 || bypass_save == 0 )
g_dev.cfg.bypass_save = bypass_save;
+ if( bypass == 1 || bypass == 0 )
+ g_dev.cfg.bypass = bypass;
+
dev_cfg_store( &g_dev.cfg );
ui_cfg_remote_update();
- put_u32_big( &resp[0], g_dev.cfg.save_gas_factor );
- put_u32_big( &resp[4], g_dev.cfg.welding_method );
+ put_u32_big( &resp[0], g_dev.cfg.welding_method );
+ put_u32_big( &resp[4], g_dev.cfg.save_gas_factor );
put_u32_big( &resp[8], g_dev.cfg.valve_open_default );
put_u32_big( &resp[12], g_dev.cfg.cal.flow_comp_x1000 );
put_u32_big( &resp[16], g_dev.cfg.cal.flow_coeff_x1000 );
- put_u32_big( &resp[20], g_dev.cfg.bypass_save );
- tx_n = wrap_resp_pkt( tx_pkt, pkt->cmd, resp, 24 );
+ put_u32_big( &resp[20], g_dev.cfg.bypass_save );
+ put_u32_big( &resp[24], g_dev.cfg.bypass );
+ tx_n = wrap_resp_pkt( tx_pkt, pkt->cmd, resp, 28 );
break;
}
case 0xB8: //WIFI参数读取
tx_n = wrap_resp_pkt( tx_pkt, pkt->cmd, resp, 1 );
break;
}
- case 0xC0: //参数v2 读取 -- 流量计选择1B ...
+ case 0xC0: //参数v2 读取 -- 流量计选择1B 气体1B, 流量低报阈值 4B...
resp[0] = g_dev.cfg2.flowmeter;
resp[1] = g_dev.cfg2.gas;
- tx_n = wrap_resp_pkt( tx_pkt, pkt->cmd, resp, 2 );
+ put_u32_big( &resp[2], g_dev.cfg2.flow_low_alarm_x1000 );
+ tx_n = wrap_resp_pkt( tx_pkt, pkt->cmd, resp, 6 );
break;
- case 0xC1: //参数v2 写入 -- 流量计选择1B,气体选择1B 背光 1B -- ...
+ case 0xC1: //参数v2 写入 -- 流量计选择1B,气体选择1B 流量低报阈值 4B -- ...
if( pkt->pdata[0] <= FLOWMETER_MAX )
g_dev.cfg2.flowmeter = pkt->pdata[0];
if( pkt->pdata[1] <= GAS_MAX )
g_dev.cfg2.gas = pkt->pdata[1];
+ if( get_u32_big( &pkt->pdata[2] ) != 0xFFFFFFFF )
+ g_dev.cfg2.flow_low_alarm_x1000 = get_u32_big( &pkt->pdata[2] );
dev_cfg_v2_store( &g_dev.cfg2 );
resp[0] = 1;
tx_n = wrap_resp_pkt( tx_pkt, pkt->cmd, resp, 1 );
break;
+#if 0
+ case 0xC2: //气路读取 1B 0:bypass_off, 1:bypass_on
+ resp[0] = g_dev.cfg.bypass;
+ tx_n = wrap_resp_pkt( tx_pkt, pkt->cmd, resp, 1 );
+ break;
+ case 0xC3: //气路选择 1B 0:bypass_off, 1:bypass_on
+ if( pkt->pdata[0] == 1 || pkt->pdata[0] == 0 ){
+ g_dev.cfg.bypass = pkt->pdata[0];
+ dev_cfg_store( &g_dev.cfg );
+ resp[0] = 1;
+ lcd_update_cfg();
+ }else{
+ resp[0] = 0;
+ }
+ tx_n = wrap_resp_pkt( tx_pkt, pkt->cmd, resp, 1 );
+ break;
+#endif
#endif
}
if( g_dev.flowmeter.ad_vol > 0.5f && g_dev.flowmeter.ad_vol < 5.5f ){
flow_raw = g_dev.flowmeter.flow_speed_raw_ad;
total_raw = g_flow_total;
+
+ //SMC启用气体修正系数, 2024/05/17
+ if( g_dev.cfg.cal.flow_coeff_x1000 > 100 && g_dev.cfg.cal.flow_coeff_x1000 < 3000 ){
+ float flow_coeff = g_dev.cfg.cal.flow_coeff_x1000/1000.0f;
+ //瞬时流量进行修正,
+ flow_raw *= flow_coeff;
+ //累计流量通过软件实现不需要修正
+ }
+
flow_err = 0;
}else{
flow_err++;
#define lcd_tcp_port_size 6
#define lcd_net_cfg_size (lcd_wifi_ssid_size+lcd_wifi_passwd_size+lcd_tcp_server_size+lcd_tcp_port_size)
+#define lcd_eth_connected_addr 0x5300 //连接标志 0:未连接, 1: 以太网连接, 2:建立TCP连接
+#define lcd_msg_1_addr 0x5400 //预留通用信息
+#define lcd_msg_1_size 32 //32Byte, 占16个变量
+#define lcd_msg_2_addr 0x5420 //预留通用信息
+#define lcd_msg_2_size 32 //32Byte, 占16个变量
typedef struct{
uint8_t cmd;
uint8_t addr[2];
#else
#define valve_overheat( temp_v ) ( 0 )
#endif
+
+//气压高报警
+static void pressure_alarm_check( void );
+//流量低报检查
+static void flow_low_alarm_check( void );
+//流量高报检查
+static void flow_high_alarm_check( void );
+
//------------------------------------------------
//比例阀电流计算方式更新
//通过压力和流量计算对应控制电流
if( caculate( (WeldMethod)g_dev.cfg.welding_method, welding_current, g_dev.cfg.save_gas_factor, &flowspeed ) == 0 ){
//控制流量输出, 按焊接电流和节气因子计算目标流量
+ if( flowspeed > FLOW_SPEED_FS*0.95f )
+ flowspeed = FLOW_SPEED_FS*0.95f;
*target_flowspeed = flowspeed;
return 0;
}
//1. 按压力计算对应启动电流和流量最大值
calc_valve_curr_range( g_dev.pressure, &curr_start, &flow_max );
-#if VALVE_CTRL_200MA
- //按百分比计算比例阀控制电流
+
+ //按百分比计算比例阀控制电流, 这里最大值按200mA/165mA计算
if( open_percent == 0 )
curr = 0;
else if( open_percent >= 99 )
- curr = 0.200;
+ curr = VALVE_MAX_CURR_FLOAT;
else
- curr = curr_start + ( 0.200f-curr_start )*open_percent/100.0f;
-#else
- //按百分比计算比例阀控制电流
- if( open_percent == 0 )
- curr = 0;
- else
- curr = curr_start + ( 0.165f-curr_start )*open_percent/100.0f;
-#endif
+ curr = curr_start + ( VALVE_MAX_CURR_FLOAT-curr_start )*open_percent/100.0f;
return curr;
}
curr_add/=2.0f;
}
//加到原来控制值上输出
-#if VALVE_CTRL_200MA
- if( g_pidctrl.valve_current_out+curr_add > 0.200f )
- g_pidctrl.valve_current_out = 0.200f; //max 200mA
+ if( g_pidctrl.valve_current_out+curr_add > VALVE_MAX_CURR_FLOAT )
+ g_pidctrl.valve_current_out =VALVE_MAX_CURR_FLOAT; //max 200mA/165mA
else if( g_pidctrl.valve_current_out+curr_add < 0.06f-0.01f )
g_pidctrl.valve_current_out = 0.06f-0.01f;
else
g_pidctrl.valve_current_out += curr_add;
-#else
- if( g_pidctrl.valve_current_out+curr_add > 0.165f )
- g_pidctrl.valve_current_out = 0.165f; //max 165mA
- else if( g_pidctrl.valve_current_out+curr_add < 0.06f-0.01f )
- g_pidctrl.valve_current_out = 0.06f-0.01f;
- else
- g_pidctrl.valve_current_out += curr_add;
-#endif
}
}
uint32_t tem_restore_tick=0;
uint32_t tem_err_state = 0;
float valve_curr;
-
-// float target_flowspeed = 0;
+ double target_flowspeed;
uint32_t tem_state_last = 0;
uint32_t now;
g_dev.state &= ~(TEMP_ERR);
}
#endif
- if( !bypass && (g_dev.cfg.bypass || tem_err_state ) ){
- //屏上点击旁路或温度故障,开启旁路
- bypass = 1;
- }else if( bypass && !g_dev.cfg.bypass && !tem_err_state ){
- //恢复正常,关闭旁路
- bypass = 0;
+ if( g_dev.cfg.remote_locked || welding_current < 10.0f ){ //焊接电流大于10A 认为开始焊接,小于10A认为焊接停止。
+ //未开始焊接
+ //按比例阀开度设置电流, 最小0.7v 最大1.0v, 按开度百分比计算电流
+ static float dbg_curr = 0;
+
+ if( g_dev.cfg.valve_open_default > 0 ){
+ //g_dev.valve_curr_out = g_dev.cfg.valve_open_default*(0.16f-0.06f)/100 + 0.06f;
+ g_dev.valve_curr_out = calc_valve_open_default(g_dev.cfg.valve_open_default );
+ }else{
+ g_dev.valve_curr_out = 0;
+ }
+
+ if( dbg_curr - g_dev.valve_curr_out > 0.001f || dbg_curr - g_dev.valve_curr_out < -0.001f ){
+ printf( "open %d%%, curr:%0.3fA -> %0.3fA\n", g_dev.cfg.valve_open_default, dbg_curr, g_dev.valve_curr_out );
+ dbg_curr = g_dev.valve_curr_out;
+ }
+ if( g_dev.welding_start == 1 ){
+ g_dev.welding_start = 0;
+ g_dev.welding_time = 0;
+ }
+ //未焊接,调用这个函数不存储记录仅通过USB发送数据到上位机
+// welding_data_store( 0 );
+ }else{
+ //焊接状态
+ if( g_dev.welding_start == 0 ){
+ //焊接启动
+ g_dev.welding_start = 1;
+ pid_ctrl_init(); //pid 初始化
+ g_dev.welding_time = 0; //计时
+ }else{
+ g_dev.welding_time += 100; //0.1秒扫描一次
+ }
+
+ if( calc_target_flow( &target_flowspeed )== 0 ){
+ //控制流量输出, 按焊接电流和节气因子计算目标流量
+ g_dev.target_flowspeed = target_flowspeed;
+ }
+
+ //根据目标流量,和实际流量,使用pid调整比例阀
+ pid_ctrl_update();
+ g_dev.valve_curr_out = g_pidctrl.valve_current_out;
+
+ //焊接中,记录数据到spiflash,0.1秒一条
+ // welding_data_store( g_dev.welding_time/100 );
}
- if( bypass ){
- //比例阀温度故障
+ if( g_dev.cfg.bypass || tem_err_state ){
+ //屏上点击旁路或温度故障,开启旁路
valve_bypass( 1 ); //旁路电磁阀开启
g_dev.valve_curr_out = 0; //比例电磁阀关闭
-
- //旁路时也更新焊接状态,修复旁路时上报平台为未焊接状态的问题 2024/5/9
- if( g_dev.cfg.remote_locked || welding_current < 10.0f ){ //焊接电流大于10A 认为开始焊接,小于10A认为焊接停止。
- //未开始焊接
- if( g_dev.welding_start == 1 ){
- g_dev.welding_start = 0;
- g_dev.welding_time = 0;
- }
- }else{
- if( g_dev.welding_start == 0 ){
- //焊接启动
- g_dev.welding_start = 1;
- g_dev.welding_time = 0;
- }
- }
-
- }else{
+ }else if( !g_dev.cfg.bypass && !tem_err_state ){
+ //恢复正常,关闭旁路
valve_bypass( 0 ); //旁路电磁阀关闭
- //检查焊接电流,判断是否开始焊接
- if( g_dev.cfg.remote_locked || welding_current < 10.0f ){ //焊接电流大于10A 认为开始焊接,小于10A认为焊接停止。
- //未开始焊接
-
- //按比例阀开度设置电流, 最小0.7v 最大1.0v, 按开度百分比计算电流
- static float dbg_curr = 0;
-
- if( g_dev.cfg.valve_open_default > 0 ){
- //g_dev.valve_curr_out = g_dev.cfg.valve_open_default*(0.16f-0.06f)/100 + 0.06f;
- g_dev.valve_curr_out = calc_valve_open_default(g_dev.cfg.valve_open_default );
- }else{
- g_dev.valve_curr_out = 0;
- }
+ }
- if( dbg_curr - g_dev.valve_curr_out > 0.001f || dbg_curr - g_dev.valve_curr_out < -0.001f ){
- printf( "open %d%%, curr:%0.3fA -> %0.3fA\n", g_dev.cfg.valve_open_default, dbg_curr, g_dev.valve_curr_out );
- dbg_curr = g_dev.valve_curr_out;
- }
- if( g_dev.welding_start == 1 ){
- g_dev.welding_start = 0;
- g_dev.welding_time = 0;
- }
- //未焊接,调用这个函数不存储记录仅通过USB发送数据到上位机
- welding_data_store( 0 );
- }else{
- //焊接状态
- if( g_dev.welding_start == 0 ){
- //焊接启动
- g_dev.welding_start = 1;
- pid_ctrl_init(); //pid 初始化
- g_dev.welding_time = 0; //计时
- }else{
- g_dev.welding_time += 100; //0.1秒扫描一次
- }
+ //更新比例阀驱动电流
+ user_valve_set_current( g_dev.valve_curr_out );
- double target_flowspeed;
- if( calc_target_flow( &target_flowspeed )== 0 ){
- //控制流量输出, 按焊接电流和节气因子计算目标流量
- g_dev.target_flowspeed = target_flowspeed;
- }
+ welding_data_store( g_dev.welding_time/100 ); //上报usb调试。
- //根据目标流量,和实际流量,使用pid调整比例阀
- pid_ctrl_update();
- g_dev.valve_curr_out = g_pidctrl.valve_current_out;
+ { //检查报警
+ static uint32_t count = 0;
+ if( count++ >= 9 ){ //1秒扫描一次
+ count = 0;
+ pressure_alarm_check();
+ flow_high_alarm_check();
+ flow_low_alarm_check();
+ }
+ }
+ }
+}
- //焊接中,记录数据到spiflash,0.1秒一条
- welding_data_store( g_dev.welding_time/100 );
+//流量高报检查
+void flow_high_alarm_check( void )
+{
+ static uint32_t alarm = 0; //0 不报警, 1 计时待报警, 2 报警
+ static uint32_t alarm_start;
+
+ //流量过大(超过95%FS)
+ if( !(g_dev.state & FLOWMETER_ERR ) && g_dev.flowmeter.flow_speed > (FLOW_SPEED_FS)*0.95f ){
+ if( alarm == 0 ){
+ alarm = 1;
+ alarm_start = xTaskGetTickCount(); //开始计时
+ }else if( alarm == 1 ){
+ if( xTaskGetTickCount() - alarm_start > 10*1000 ){ //计时到10秒,报警
+ alarm = 2;
+ g_dev.alarm.flow_high = 1;
}
}
+ }else{
+ alarm = 0;
+ g_dev.alarm.flow_high = 0;
+ }
+}
- if( g_dev.debug_curr == 2 ){
- valve_curr = g_dev.debug_valve_curr;
+//流量低报检查
+void flow_low_alarm_check( void )
+{
+ //2. 焊接时比例阀电流达到最大值 10秒后流量低于阈值,报警音 1长 -- 响2秒,停0.2秒
+ uint32_t now;
+ float low_alarm_value; //阈值
+ static uint32_t alarm = 0; //0 不报警, 1 计时待报警, 2 报警
+ static uint32_t alarm_start;
+
+ if( !(g_dev.state & FLOWMETER_ERR) && g_dev.cfg2.flow_low_alarm_x1000 ){
+ low_alarm_value = g_dev.cfg2.flow_low_alarm_x1000/1000.0f;
+
+ //报警条件判断: 焊接中, 目标流量大于阈值, 实际流量小于阈值
+ if( g_dev.welding_start
+ && g_dev.target_flowspeed > low_alarm_value
+ && g_dev.flowmeter.flow_speed < low_alarm_value
+ && g_dev.target_flowspeed > g_dev.flowmeter.flow_speed+0.2f ){
+
+ now = xTaskGetTickCount();
+ if( alarm == 0 ){
+ alarm = 1;
+ alarm_start = now; //开始计时,等待10秒报警
+ }else if( alarm == 1 ){
+ if( now - alarm_start > 10*1000 ){
+ //计时到10秒,报警
+ alarm = 2;
+ g_dev.alarm.flow_low = 1;
+ alarm_start = now; //开始计时,等待10秒开直通阀
+ }
+ }else if( alarm == 2){
+#if 0
+ if( now - alarm_start > 10*1000 ){
+ //计时到10秒,开直通阀
+ alarm = 3;
+ if( g_dev.cfg.bypass == 0 ){
+ g_dev.cfg.bypass = 1;
+ ui_cfg_remote_update(); //刷新lcd
+ }
+ }
+#endif
+ }
}else{
- valve_curr = g_dev.valve_curr_out;
+ alarm = 0;
+ g_dev.alarm.flow_low = 0;
}
+ }else{
+ alarm = 0;
+ g_dev.alarm.flow_low = 0;
+ }
+}
- //更新比例阀驱动电流
- user_valve_set_current( valve_curr );
+//气压高报警
+void pressure_alarm_check( void )
+{
+ static uint32_t alarm = 0; //0 不报警, 1 计时待报警, 2 报警
+ static uint32_t alarm_start;
+
+ //4. 气压传感器正常,气压大于 0.7Mpa*.95 10秒后报警
+ if( !(g_dev.state & PRESSURE_SENSOR_ERR ) && g_dev.pressure > (PRESSURE_KPA_FS)*0.95f ){
+ if( alarm == 0 ){
+ alarm = 1;
+ alarm_start = xTaskGetTickCount(); //开始计时
+ }else if( alarm == 1 ){
+ if( xTaskGetTickCount() - alarm_start > 10*1000 ){ //计时到10秒,报警
+ alarm = 2;
+ g_dev.alarm.pressure_high = 1;
+ }
+ }
+ }else{ //气压恢复,停止报警
+ alarm = 0;
+ g_dev.alarm.pressure_high = 0;
}
}
+
\ No newline at end of file