Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
GUI for logging - cutelog
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Avionics
Software Development
Third Party
GUI for logging - cutelog
Commits
6402a8f4
Commit
6402a8f4
authored
4 years ago
by
Luca Erbetta
Browse files
Options
Downloads
Patches
Plain Diff
Open serial port on startup & display it in a tab (2)
parent
8a7fd74a
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
cutelog/serial.py
+102
-0
102 additions, 0 deletions
cutelog/serial.py
with
102 additions
and
0 deletions
cutelog/serial.py
0 → 100644
+
102
−
0
View file @
6402a8f4
import
serial
import
pickle
import
struct
import
re
import
sys
from
datetime
import
datetime
from
qtpy.QtCore
import
QThread
,
Signal
from
qtpy.QtNetwork
import
QHostAddress
,
QTcpSocket
from
.config
import
CONFIG
class
SerialConnection
(
QThread
):
disconnected
=
False
re_line
=
re
.
compile
(
r
"
(?P<tsmin>\d{2,}):(?P<tssec>\d{2}.\d{3}) (?P<file>[\dA-Za-z/_\-.]+):(?P<line>\d+) (?P<func>[\dA-Za-z/_\-\.]+) (?P<level>[A-Za-z\d]+) \[(?P<name>[\dA-Za-z/_\-.]+)\] (?P<msg>.*)
"
)
def
__init__
(
self
,
parent
,
port
,
baud
):
super
().
__init__
(
parent
)
print
(
"
Opening serial port {}:{}
"
.
format
(
port
,
baud
))
self
.
ser
=
serial
.
Serial
(
port
,
baud
,
timeout
=
1
)
_
,
self
.
tcp_port
=
CONFIG
.
listen_address
self
.
tcp_host
=
QHostAddress
(
"
127.0.0.1
"
)
self
.
start
()
print
(
"
thread started
"
)
def
onDisconnect
(
self
):
disconnect
=
True
print
(
"
on disconnect
"
)
def
run
(
self
):
sock
=
QTcpSocket
(
None
)
sock
.
connectToHost
(
self
.
tcp_host
,
self
.
tcp_port
)
sock
.
disconnected
.
connect
(
self
.
onDisconnect
)
if
not
sock
.
waitForConnected
():
print
(
"
Socket error!
"
)
print
(
sock
.
errorString
())
return
if
self
.
ser
is
None
:
print
(
"
Error opening serial port
"
)
return
while
True
:
logline
=
self
.
ser
.
readline
().
decode
(
"
utf-8
"
).
strip
(
"
\n\r
"
)
match
=
self
.
re_line
.
fullmatch
(
logline
)
if
match
is
None
:
d
=
{
'
args
'
:
None
,
'
created
'
:
datetime
.
now
().
timestamp
(),
'
exc_info
'
:
None
,
'
filename
'
:
''
,
'
funcName
'
:
''
,
'
levelname
'
:
'
DEBUG
'
,
'
levelno
'
:
0
,
'
lineno
'
:
0
,
'
module
'
:
''
,
'
msecs
'
:
0
,
'
msg
'
:
logline
,
'
name
'
:
'
raw_serial
'
,
'
pathname
'
:
''
,
'
process
'
:
0
,
'
processName
'
:
''
,
'
relativeCreated
'
:
0
,
'
stack_info
'
:
None
,
'
thread
'
:
0
,
'
threadName
'
:
''
,
'
extra_column
'
:
''
}
else
:
d
=
{
'
args
'
:
None
,
'
created
'
:
int
(
match
.
group
(
'
tsmin
'
))
*
60
*
1000
+
float
(
match
.
group
(
'
tssec
'
))
*
1000
,
'
exc_info
'
:
None
,
'
filename
'
:
match
.
group
(
'
file
'
),
'
funcName
'
:
match
.
group
(
'
func
'
),
'
levelname
'
:
match
.
group
(
'
level
'
),
'
levelno
'
:
10
,
'
lineno
'
:
match
.
group
(
'
line
'
),
'
module
'
:
'
serial
'
,
'
msecs
'
:
0
,
'
msg
'
:
match
.
group
(
'
msg
'
),
'
name
'
:
match
.
group
(
'
name
'
),
'
pathname
'
:
match
.
group
(
'
file
'
),
'
process
'
:
0
,
'
processName
'
:
''
,
'
relativeCreated
'
:
0
,
'
stack_info
'
:
None
,
'
thread
'
:
0
,
'
threadName
'
:
''
,
'
extra_column
'
:
''
}
s
=
pickle
.
dumps
(
d
)
sock
.
write
(
struct
.
pack
(
"
>L
"
,
len
(
s
)))
sock
.
write
(
s
)
sock
.
flush
()
if
sock
.
state
()
!=
QTcpSocket
.
SocketState
.
ConnectedState
:
print
(
"
thread stop
"
)
self
.
ser
.
close
()
break
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment