Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
permocar
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
Model registry
Operate
Environments
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
Robert Hedman
permocar
Commits
da6af740
Commit
da6af740
authored
7 years ago
by
Robert Hedman
Browse files
Options
Downloads
Patches
Plain Diff
readExact addition
parent
a9caa438
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
src/main.rs
+24
-6
24 additions, 6 deletions
src/main.rs
with
24 additions
and
6 deletions
src/main.rs
+
24
−
6
View file @
da6af740
...
@@ -9,7 +9,7 @@ use serial::prelude::*;
...
@@ -9,7 +9,7 @@ use serial::prelude::*;
fn
main
()
{
fn
main
()
{
let
device
=
String
::
from
(
"/dev/cu.usbmodem
141
1"
);
let
device
=
String
::
from
(
"/dev/cu.usbmodem
4
1"
);
let
mut
port
=
serial
::
open
(
&
device
)
.unwrap
();
let
mut
port
=
serial
::
open
(
&
device
)
.unwrap
();
interact
(
&
mut
port
)
.unwrap
();
interact
(
&
mut
port
)
.unwrap
();
...
@@ -29,19 +29,37 @@ fn interact<T: SerialPort>(port: &mut T) -> io::Result<()> {
...
@@ -29,19 +29,37 @@ fn interact<T: SerialPort>(port: &mut T) -> io::Result<()> {
//let mut buf: Vec<u8> = (0..255).collect();
//let mut buf: Vec<u8> = (0..255).collect();
let
mut
buf
:
[
u8
;
255
]
=
[
0
;
255
];
let
mut
buf
:
[
u8
;
8
]
=
[
0
;
8
];
let
mut
count
:
usize
=
0
;
let
mut
count
:
usize
=
0
;
loop
{
match
port
.read_exact
(
&
mut
buf
){
Ok
(
_
)
=>
{
print!
(
"A: {}, "
,
((
buf
[
0
]
as
u32
)
<<
24
)
+
((
buf
[
1
]
as
u32
)
<<
16
)
+
((
buf
[
2
]
as
u32
)
<<
8
)
+
(
buf
[
3
]
as
u32
));
println!
(
"B: {}"
,
((
buf
[
4
]
as
u32
)
<<
24
)
+
((
buf
[
5
]
as
u32
)
<<
16
)
+
((
buf
[
6
]
as
u32
)
<<
8
)
+
(
buf
[
7
]
as
u32
));
},
Err
(
e
)
=>
{
println!
(
"Could not read all bytes: {:?}"
,
e
);
break
;
},
}
}
for
c
in
port
.bytes
()
{
for
c
in
port
.bytes
()
{
match
c
{
match
c
{
Ok
(
c
)
=>
{
Ok
(
c
)
=>
{
buf
[
count
]
=
c
;
buf
[
count
]
=
c
;
count
+=
1
;
count
+=
1
;
if
c
as
char
==
'\n'
{
if
count
==
8
{
for
i
in
0
..
count
{
print!
(
"{}"
,
buf
[
i
]
as
char
);
print!
(
"A: {}, "
,
((
buf
[
0
]
as
u32
)
<<
24
)
+
((
buf
[
1
]
as
u32
)
<<
16
)
+
((
buf
[
2
]
as
u32
)
<<
8
)
+
(
buf
[
3
]
as
u32
));
}
println!
(
"B: {}"
,
((
buf
[
4
]
as
u32
)
<<
24
)
+
((
buf
[
5
]
as
u32
)
<<
16
)
+
((
buf
[
6
]
as
u32
)
<<
8
)
+
(
buf
[
7
]
as
u32
));
//for i in 0..count {
// print!("{} ", buf[i]);
//}
count
=
0
;
count
=
0
;
//println!();
}
}
},
},
Err
(
e
)
=>
println!
(
"{:?}"
,
e
),
Err
(
e
)
=>
println!
(
"{:?}"
,
e
),
...
...
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