proto-debuger/protoDebuger/SerialSelect.qml

218 lines
5.9 KiB
QML
Raw Normal View History

2021-04-10 14:22:41 +00:00
import QtQuick 2.0
import QtQuick.Controls 2.14
import QtQuick.Layouts 1.0
Item {
2021-05-03 16:05:38 +00:00
id: serial_select_view
2021-04-12 15:39:06 +00:00
objectName: "SerialSelect"
2021-04-10 14:22:41 +00:00
width: parent.width - 80
height: parent.height
2021-04-12 15:39:06 +00:00
property var comlist: []
2021-04-10 14:22:41 +00:00
visible: true
2021-04-12 15:39:06 +00:00
property bool uart_open: false
2021-05-03 16:05:38 +00:00
signal notify(string message)
Component.onCompleted: {
//信号连接slot signal.connect(id.slot)
console.log(parent)
notify.connect(root.on_notify)
}
2021-04-10 14:22:41 +00:00
ColorAnimation {
from: "white"
to: "black"
duration: 200
}
Rectangle{
x: 0
y: 0
width: parent.width
height: parent.height
color: "#aeaeae"
scale: 1
transformOrigin: Item.Center
GridLayout {
x: 50
y: 41
rows: 6
columns: 2
Label {
id: label
text: qsTr("串口号: ")
verticalAlignment: Text.AlignVCenter
Layout.preferredHeight: 40
Layout.preferredWidth: 125
font.pointSize: 20
wrapMode: Text.NoWrap
renderType: Text.QtRendering
horizontalAlignment: Text.AlignHCenter
}
ComboBox {
2021-04-12 15:39:06 +00:00
id: comPort
2021-04-10 14:22:41 +00:00
width: 200
2021-04-12 15:39:06 +00:00
model: comlist
2021-04-10 14:22:41 +00:00
}
Label {
id: label1
text: qsTr("波特率: ")
verticalAlignment: Text.AlignVCenter
Layout.preferredHeight: 40
Layout.preferredWidth: 125
horizontalAlignment: Text.AlignHCenter
font.pointSize: 20
renderType: Text.QtRendering
wrapMode: Text.NoWrap
}
ComboBox {
id: baurate
width: 200
model:[
"300",
"600",
"1200",
"2400",
"4800",
"9600",
"14400",
"19200",
"38400",
"56000",
"57600",
"115200",
"128000",
"256000",
]
currentIndex: 6
}
Label {
id: label2
text: qsTr("数据位: ")
verticalAlignment: Text.AlignVCenter
Layout.preferredHeight: 40
Layout.preferredWidth: 125
horizontalAlignment: Text.AlignHCenter
font.pointSize: 20
renderType: Text.QtRendering
wrapMode: Text.NoWrap
}
ComboBox {
2021-04-12 15:39:06 +00:00
id: dataBits
2021-04-10 14:22:41 +00:00
width: 200
currentIndex: 3
model: [
"5",
"6",
"7",
"8",
]
}
Label {
id: label3
text: qsTr("停止位: ")
verticalAlignment: Text.AlignVCenter
Layout.preferredHeight: 40
Layout.preferredWidth: 125
horizontalAlignment: Text.AlignHCenter
font.pointSize: 20
renderType: Text.QtRendering
wrapMode: Text.NoWrap
}
ComboBox {
2021-04-12 15:39:06 +00:00
id: stopBits
2021-04-10 14:22:41 +00:00
width: 200
model: [
"1",
"1.5",
"2",
]
}
Label {
id: label4
text: qsTr("校验位: ")
verticalAlignment: Text.AlignVCenter
Layout.preferredHeight: 40
Layout.preferredWidth: 125
horizontalAlignment: Text.AlignHCenter
font.pointSize: 20
renderType: Text.QtRendering
wrapMode: Text.NoWrap
}
ComboBox {
2021-04-12 15:39:06 +00:00
id: verify
2021-04-10 14:22:41 +00:00
width: 200
model: [
"none",
"odd",
"even",
"mark",
"space"
]
}
Label {
id: label5
text: qsTr("流控: ")
verticalAlignment: Text.AlignVCenter
Layout.preferredHeight: 40
Layout.preferredWidth: 125
horizontalAlignment: Text.AlignHCenter
font.pointSize: 20
renderType: Text.QtRendering
wrapMode: Text.NoWrap
}
ComboBox {
2021-04-12 15:39:06 +00:00
id: flow
2021-04-10 14:22:41 +00:00
width: 200
model: [
"none",
"software",
"hardware",
]
}
}
Button {
id: button
x: 97
y: 339
text: qsTr("打开串口")
2021-04-12 15:39:06 +00:00
onClicked: {
if(!uart_open){
2021-04-24 17:21:31 +00:00
let ret = DataWrap.openUart(comPort.currentText,
2021-04-12 15:39:06 +00:00
baurate.currentText,
dataBits.currentText,
stopBits.currentText,
flow.currentText)
2021-08-29 08:13:50 +00:00
if(ret === 0){
2021-04-12 15:39:06 +00:00
uart_open = true
button.text = "关闭串口"
2021-05-03 16:05:38 +00:00
serial_select_view.notify("串口已经连接")
2021-04-12 15:39:06 +00:00
}
}else{
2021-04-24 17:21:31 +00:00
let ret = DataWrap.closeSerial();
2021-08-29 08:13:50 +00:00
if(ret === 0){
2021-04-13 17:28:19 +00:00
button.text = "打开串口"
uart_open = false
2021-05-03 16:05:38 +00:00
serial_select_view.notify("串口已经关闭")
2021-04-13 17:28:19 +00:00
}
2021-04-12 15:39:06 +00:00
}
}
2021-04-10 14:22:41 +00:00
}
}
}