Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Mart Lubbers
CleanSerial
Commits
6b74b1d6
Commit
6b74b1d6
authored
Sep 23, 2016
by
Mart Lubbers
Browse files
add write operation
parent
60e89ab8
Changes
3
Hide whitespace changes
Inline
Side-by-side
TTY.dcl
View file @
6b74b1d6
...
...
@@ -30,4 +30,6 @@ TTYreadc :: !*TTY -> (!Char, !*TTY)
TTYreadline
::
!*
TTY
->
(!
String
,
!*
TTY
)
TTYwrite
::
!*
TTY
!
String
->
!*
TTY
TTYerror
::
!*
env
->
(!
String
,
!*
env
)
TTY.icl
View file @
6b74b1d6
implementation
module
TTY
import
Data
.
Maybe
import
StdFunc
...
...
@@ -56,11 +55,6 @@ TTYclose f w = code {
ccall
ttyclose
"I:I:A"
}
TTYerror
::
!*
env
->
(!
String
,
!*
env
)
TTYerror
w
=
code {
ccall
ttyerror
":S:A"
}
TTYreadc
::
!*
TTY
->
(!
Char
,
!*
TTY
)
TTYreadc
w
=
code {
ccall
ttyreadc
"I:VII"
...
...
@@ -71,11 +65,22 @@ TTYreadline t = code {
ccall
ttyreadline
"I:VSI"
}
TTYwrite
::
!*
TTY
!
String
->
!*
TTY
TTYwrite
s
e
=
code {
ccall
ttywrite
"IS:I"
}
TTYerror
::
!*
env
->
(!
String
,
!*
env
)
TTYerror
w
=
code {
ccall
ttyerror
":S:A"
}
Start
::
*
World
->
(!
String
,
*
World
)
Start
w
#!
(
ok
,
tty
,
w
)
=
TTYopen
"/dev/ttyUSB0"
zero
w
|
not
ok
=
TTYerror
w
#!
(
c
,
tty
)
=
TTYreadline
tty
#!
tty
=
TTYwrite
tty
"Hello World"
#!
(
ok
,
w
)
=
TTYclose
tty
w
|
not
ok
=
TTYerror
w
#!
(
s
,
w
)
=
TTYerror
w
...
...
tty.c
View file @
6b74b1d6
...
...
@@ -29,7 +29,8 @@ static char *cleanStringToCString(CleanString s)
return
cs
;
}
void
ttyopen
(
CleanString
fn
,
int
baudrate
,
int
bytesize
,
int
parity
,
int
stopbits
,
int
xonoff
,
int
*
status
,
FILE
**
f
)
void
ttyopen
(
CleanString
fn
,
int
baudrate
,
int
bytesize
,
int
parity
,
int
stopbits
,
int
xonoff
,
int
*
status
,
FILE
**
f
)
{
struct
termios
tio
;
char
*
cs_fn
=
cleanStringToCString
(
fn
);
...
...
@@ -49,15 +50,14 @@ void ttyopen(CleanString fn, int baudrate, int bytesize, int parity, int stopbit
//Parity
tio
.
c_cflag
|=
PARENB
|
PARODD
|
CMSPAR
;
tio
.
c_cflag
-=
PARENB
|
PARODD
|
CMSPAR
;
if
(
parity
==
1
)
{
if
(
parity
==
1
)
tio
.
c_cflag
|=
PARENB
|
PARODD
;
}
else
if
(
parity
==
2
)
{
else
if
(
parity
==
2
)
tio
.
c_cflag
|=
PARENB
;
}
else
if
(
parity
==
3
)
{
else
if
(
parity
==
3
)
tio
.
c_cflag
|=
PARODD
|
PARENB
|
CMSPAR
;
}
else
if
(
parity
==
4
)
{
else
if
(
parity
==
4
)
tio
.
c_cflag
|=
PARENB
|
CMSPAR
;
}
//Stopbits
tio
.
c_cflag
|=
CSTOPB
;
tio
.
c_cflag
-=
stopbits
==
0
?
0
:
CSTOPB
;
...
...
@@ -121,6 +121,15 @@ void ttyreadline(FILE *fd, CleanString *result, FILE **fdo)
free
(
buf
);
}
int
ttywrite
(
FILE
*
fd
,
CleanString
s
,
FILE
**
fdo
)
{
char
*
cs_s
=
cleanStringToCString
(
s
);
fwrite
(
s
,
1
,
strlen
(
cs_s
),
fd
);
free
(
cs_s
);
*
fdo
=
fd
;
}
int
ttyclose
(
FILE
*
fd
)
{
return
fclose
(
fd
)
==
0
?
1
:
0
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment