Menu
Using PuTTY for Serial
PuTTY can replace HyperTerminal for serial communications. It provides logging, a large scroll back buffer, and many other features. You are probably already using PuTTY for SSH and Telnet, but you can also use it for Serial TTY console connections.
Note: Using PuTTY is illegal in countries where encryption is outlawed. If in doubt, seek legal advice before downloading it. The Telnet-only binary (PuTTYtel) is unrestricted by any cryptography laws.
How to call putty directly from matlab and write script that I can write on putty to. Is it operating as a virtual serial port (COM port), or is it emulating a network. How does one configure the scripts in the RaspberryPi to allow direct USB connection for PuTTY (in the same way that the BBB can be accessed via a USB cable)? NOTE: This question excludes the use of either ethernet via a UTP cable or a USB wireless adapter, or serial via a USB to TTL serial converter module.
If you use an Apple Mac computer, refer to: Mac's and serial TTY's.
Setup
1Plug in your USB to Serial adapter, and determine its COM port number by opening the Windows Device Manger (a driver must have previously been installed for the adapter).
- Start ➤ Control Panel ➤ Device Manager
- OR -
Right-Click My Computer, and select: Properties ➤ Device Manager - Expand: Ports (COM & LPT)
The serial adapter should be listed:
2Open PuTTY, and click Serial from the Category: Connection.
3Select Category: Session, click the Serial radio button,
4If you want to save this session, enter a name in Saved Sessions and click Save.
5Click Open and a serial session will start.
Session logging
To create a text log file, right click on the PuTTY menu bar, and select Change Settings.
- Click Logging from the Category: Session
- Click the Log All Session Output radio button.
- Click Browse and select a folder and filename for your log file, eg: C:UsersMikeDesktopputty.log
- Click Apply, and the log file should appear in your chosen location.
Scrollback Buffer
To lengthen the scrollback buffer size, right click on the PuTTY menu bar, and select Change Settings.
- Click the Category: Window
- Enter a large number at Lines of Scrollback
- Click Apply.
Downloads
PHP (PHP HyperText Preprocessor) is a server side scripting language popular with website developers. Typically PHP is used to generate web pages by interrogating a database and files. However PHP can also be used to control and communicate with other devices.
This article explains how to configure PHP in order to send and receive data over a serial port on a unix system or a windows system.
Prerequisites
- PHP installed on your computer
- An installed Brainboxes Serial port product
Steps In Brief
- Install PHP Direct IO extension
- Configure PHP to use the extension
- Use PHP file provided in the downloads
- Open terminal program at other end of serial connection
- Configure PHP file with correct local serial port settings
- Go!
In-depth
Install PHP Direct IO
PHP by default does not offer good COM port support however a PHP extension called Direct IO does offers low level access to IO. We will use this extension for serial port communication.
On unix system install the extension using PECL, open a terminal and type:
sudo pecl install dio-0.0.7
On windows download the latest php direct io extension dll from: http://pecl.php.net/package/dio. The dll file should be copied into your php_extension folder (often located in
ext
or libphpext
)Configure PHP to use the extension
Next the php.ini file needs to be updated to tell it to use the extension. To the bottom of the php.ini file add the following.
Unix:
extension=dio.so
Windows:
extension=php_dio.dll
Restart PHP
Unix: commands vary, on mac for example:
sudo apachectl restart
Windows: restart IIS webserver, or WAMP server
Use PHP file provided in the downloads
Download the file about and place it in your web-servers root directory. Navigate to the file the a web browser to confirm that an error is not produced which tells you to install PHP Direct IO.
Open terminal program at other end of serial connection
In order to test sending and receiving serial data in PHP, the other end of the serial port should be open. On a windows system we recommend using Putty and on Mac OSX CoolTerm (see this FAQ for more details) to configure a serial for for transmitting and recieving data. We also recommend opening the other side of the serial connection in the terminal initially to confirm that data is definitely able to be sent and received across the connection.
Configure PHP file with correct local serial port settings
The sample script has some settings to be configured at the top, most importantly the port name.
Windows the port name should be 'comX:' (X being the port number assigned name must be lower case and a colon at the end) this can be found by opening Device Manager.
Unix systems the port name is '/dev/cu.usbserial-XXXXXXXXX' where 'X' is a randomly assigned id. To find all the names of Brainboxes serial ports installed on UNIX type
ls /dev/cu.usbserial*
into the terminal.Go!
In a Web Browser open the file, the other end of the serial port should show 'HELLO WORLD!'. Then type into the terminal on the other end of the connection, this will be echoed back onto the web browser window.
Important note: PHP Direct IO does not currently implement a timeout on reads and is blocking. What this means is that if there is no data present when the read method is called then PHP will block (halt) until data is received or the PHP execution time is reached.
Links
PHP Direct IO manual - http://www.php.net/manual/en/book.dio.php