How to write a script to send to serial ports

Written by andy carr
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to write a script to send to serial ports
A traditional serial port. Modern serial ports use Universal Serial Bus (USB). (serial port image by jimcox40 from Fotolia.com)

It should be possible for important data to move to and from different digital devices. On computers, this can be achieved by either copying the data to an external drive and physically carrying it or by transmitting the data automatically via the serial or communications ports. It is generally safer to transmit data automatically from one device to another through serial communications ports. This can be achieved by writing a script to automate the process and by including commands to write and read to and from serial ports.

Skill level:
Moderate

Other People Are Reading

Things you need

  • List of serial ports on your system(s)

Show MoreHide

Instructions

  1. 1

    Identify the naming conventions for your serial ports. Before a script can be written, it is necessary to identify the standard names used for serial ports on your system(s). On Windows computers using Disk Operating Systems (DOS), most serial communications ports are named using the convention COM1, COM2 and COM3, but on Unix-type systems, serial ports are usually named similar to a directory structure, such as /dev/ttys1, /dev/ttys2 and so on.

    How to write a script to send to serial ports
    Physical ports are named in software according to the appropriate convention. (port replicator isolated on the white background image by Elnur from Fotolia.com)
  2. 2

    Learn or use the appropriate scripting language. Before a serial port can be accessed via a script, it is necessary to use the available language to achieve the task. On DOS systems, this can be achieved via the batch scripting language, but in Unix this is achieved via shell scripts.

    How to write a script to send to serial ports
    Learn the appropriate scripting language. (abc"s image by sonya etchison from Fotolia.com)
  3. 3

    Send data to the communications port via the correct command. When data has been processed and is ready to send via a serial port, it needs a suitable command to achieve the task. For example, on DOS systems writing to serial port COM1, the command "echo Hello > COM1" sends "Hello" to the communications port identified as COM1. On Unix systems, the command "echo Hello > /dev/ttys1" sends "Hello" to the serial port identified as /dev/ttys1.

Tips and warnings

  • In addition to standard output, it is also possible to output error messages to the serial port. This is achieved by a modification of the standard commands using a different parameter.
  • The standard scripting languages are only one method of writing to serial ports. However, any language having access to the serial ports and operating system can be used, such as Java and C++.
  • It is sometimes necessary to have a separate program to read the data coming from the serial port, otherwise the program may "hang."

Don't Miss

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.