Posts match “ serialport ” tag:


To learn how to use node-serialport, I need to prepare an easy-to-verify development environment. So, I select VirtualBox + Vagrant + virtual serial port to setup the development environment. The article is to summarize how I setup step-by-step.

Environment Preparation

Before setup, following softwares need to be installed:

Note, it's very easy to install socat with homebrew:

brew install socat

VirtualBox Setup

I select precise64 as the basebox, and initiate the virtualbox:

vagrant init precise64

Next step is to add following lines into the Vagrantfile file at current path:

config.vm.provider :virtualbox do |vb|
    vb.customize ["modifyvm", :id, "--uart1", "0x3f8", "4"]
    vb.customize ["modifyvm", :id, "--uartmode1", "server", "/tmp/my_tty"]

The 1st line of modifyvm is to enable virtual serial port in virtualbox.
The 2nd line of modifyvm is to connect the virtual serial port to a software pipe on host OS (Mac). In this case, the local domain socket (/tmp/my_tty) is used.

Then, launch the box

touch /tmp/my_tty
vagrant up

Note, the first line is to make sure the socket file already exists before the virtual machine is started. The third line is to login the guest OS for manipulating virtual serial port.

VMWare Fusion Setup

(to-be-complete later...)

Test with SocketServer on Host OS

At the Guest OS (Ubuntu 12.04 64 bits), the virtual serial port can be found at /dev/ttyS0. Then, we use screen tool to manipulate the serial port. Let's open a terminal, name it as T1, and type following command:

vagrant ssh
screen /dev/ttyS0 38400

At the Host OS (Mac OSX), the file for local domain socket connected by virtual serial port is /tmp/my_tty. To monitor the domain socket, socat tool is used. Let's open another terminal, name it as T2, and type following command:

socat /tmp/my_tty tcp-listen:9000 &
telnet localhost 9000

Then, when you type some characters on T1 then T2 shows those characters, and vice versa.

At T1, to exit from screen, please press ctrl-a k to kill it.
At T2, after the telnet process is killed, the socat process is also terminated.

Test with Virtual SerialPort on Host OS

The steps are similar to previous section, but the steps for T2 (2nd terminal) are different. Let's type socat -d -d /tmp/my_tty PTY. It might output following messages on the terminal:

2013/09/14 18:41:27 socat[50862] N opening connection to LEN=17 AF=1 "/tmp/my_tty"
2013/09/14 18:41:27 socat[50862] N successfully connected from local address LEN=16 AF=1 ""
2013/09/14 18:41:27 socat[50862] N successfully connected via
2013/09/14 18:41:27 socat[50862] N PTY is /dev/ttys001
2013/09/14 18:41:27 socat[50862] N starting data transfer loop with FDs [3,3] and [4,4]
2013/09/14 18:42:37 socat[50862] N socket 2 (fd 4) is at EOF
2013/09/14 18:42:37 socat[50862] N socket 1 (fd 3) is at EOF
2013/09/14 18:42:37 socat[50862] N socket 2 (fd 4) is at EOF
2013/09/14 18:42:37 socat[50862] N exiting with status 0

socat indicates the named pipe for virtual serial port on host OS is created, and placed at /dev/ttys001. Then, type screen /dev/ttys001 38400. Finally, the virtual serial ports on both Guest and Host OSes are connected.