Function: serial-read-name
serial-read-name is a byte-compiled function defined in term.el.gz.
Signature
(serial-read-name)
Documentation
Read a serial port name from the user.
Try to be nice by providing useful defaults and history. On Windows, prepend \.to the port name unless it already contains a backslash. This handles the legacy ports COM1-COM9 as well as the newer ports COM10 and higher.
Source Code
;; Defined in /usr/src/emacs/lisp/term.el.gz
(defun serial-read-name ()
"Read a serial port name from the user.
Try to be nice by providing useful defaults and history.
On Windows, prepend \\.\ to the port name unless it already
contains a backslash. This handles the legacy ports COM1-COM9 as
well as the newer ports COM10 and higher."
(serial-supported-or-barf)
(let* ((file-name-history serial-name-history)
(h (car file-name-history))
(x (if (serial-port-is-file-p)
(read-file-name
;; `prompt': The most recently used port is provided as
;; the default value, which is used when the user
;; simply presses return.
(format-prompt "Serial port" h)
;; `directory': Most systems have their serial ports
;; in the same directory, so start in the directory
;; of the most recently used port, or in a reasonable
;; default directory.
(or (and h (file-name-directory h))
(and (file-exists-p "/dev/") "/dev/")
(and (file-exists-p "/") "/"))
;; `default': This causes (read-file-name) to return
;; the empty string if he user simply presses return.
;; Using nil here may result in a default directory
;; of the current buffer, which is not useful for
;; serial port.
"")
(read-from-minibuffer
(format-prompt "Serial port" h)
nil nil nil '(file-name-history . 1) nil nil))))
(if (or (null x) (and (stringp x) (zerop (length x))))
(setq x h)
(setq serial-name-history file-name-history))
(when (or (null x) (and (stringp x) (zerop (length x))))
(error "No serial port selected"))
(when (not (or (serial-port-is-file-p)
(string-search "\\" x)))
(setq x (concat "\\\\.\\" x)))
x))