set_baudrate (not tested)

This commit is contained in:
Pascal Brisset
2006-10-18 05:57:43 +00:00
parent 77c388536c
commit f72a236695
3 changed files with 35 additions and 1 deletions
+28
View File
@@ -89,3 +89,31 @@ value c_set_dtr(value val_fd, value val_bit) {
ioctl(fd, TIOCMSET, &status);
return Val_unit;
}
/* From the gPhoto I/O library */
value c_serial_set_baudrate(value val_fd, value speed)
{
struct termios tio;
int fd = Int_val(val_fd);
if (tcgetattr(fd, &tio) < 0) {
failwith("tcgetattr");
}
tio.c_iflag = 0;
tio.c_oflag = 0;
tio.c_cflag = CS8 | CREAD | CLOCAL;
tio.c_cc[VMIN] = 1;
tio.c_cc[VTIME] = 5;
tio.c_lflag &= ~(ICANON | ISIG | ECHO | ECHONL | ECHOE | ECHOK);
int br = baudrates[Int_val(speed)];
cfsetispeed(&tio, br);
cfsetospeed(&tio, br);
if (tcsetattr(fd, TCSANOW | TCSAFLUSH, &tio) < 0) {
failwith("tcsetattr");
}
return Val_unit;
}
+6 -1
View File
@@ -77,8 +77,9 @@ let string_of_payload = fun x -> x
let payload_of_string = fun x -> x
external init_serial : string -> speed -> Unix.file_descr = "c_init_serial";;
external init_serial : string -> speed -> Unix.file_descr = "c_init_serial"
external set_dtr : Unix.file_descr -> bool -> unit = "c_set_dtr"
external set_speed : Unix.file_descr -> speed -> unit = "c_serial_set_baudrate"
let opendev device speed =
try
@@ -109,6 +110,10 @@ let input = fun f ->
(* Printf.fprintf stderr "n'=%d\n" nb_used; flush stderr; *)
if nb_used > 0 then
parse (start + nb_used) (n - nb_used)
else if n = buffer_len then
(* The buffer is full and the user does not consume any. We have to
discard one char to avoid a dead lock *)
parse (start + 1) (n - 1)
else
wait start n in
parse 0 n)
+1
View File
@@ -52,6 +52,7 @@ val speed_of_baudrate : string -> speed
val opendev : string -> speed -> Unix.file_descr
val close : Unix.file_descr -> unit
val set_dtr : Unix.file_descr -> bool -> unit
val set_speed : Unix.file_descr -> speed -> unit
val input : (string -> int) -> (Unix.file_descr -> unit) closure
(** Buffered input. [input f] Returns a closure which must be called when