Lessons in Linux Serial Interfaces

This week our goal was to get the Linux box that we have set up for our Senior Design project to be able to interface with our 2 connected 8-port relays via the Serial (DB-9) Port, and we succeeded!A little background information:

  • Server OS - Ubuntu 6.06 LTS (Dapper Drake)
  • Computer Hardware -
    • Processor: 1GHz Pentium III
    • Memory: 256MB (single dimm)
    • Hard Disk: 20GB Wester Digital Caviar
    • Optical: CD-ROM (Slim)
    • Monitor: EloSystems 15″ TouchScreen (1024 x 768 resolution)
    • Relay(s): 2xK108 (Kit 108 8-port Serial Relays)

This system took a bit of work to get up and running. We started with Ubuntu Desktop 7.10 (Gutsy Gibbon) and quickly found that there was no easy way to install Apache Webserver with PHP and MySQL… so we scratched that version and went to Ubuntu 6.06 Server LTS (Long Term Support). This was ideal and I had it up and running in no time in command line (which is its default configuration). After configuring SSH and Apache I decided to install a GUI for easier Server Administration. I chose to install Gnome for the actual system GUI and also Webmin for Server Administration over IP.   

Serial Issues

Our first approach was to make a C program to send commands to the interface and that didn’t work… Next we tried to send commands straight from the Linux command line, yet again to no avail… After a bit of investigation and a good amount of “Googling” I found a tip that said I might have to actually “create” a device so that when we send commands to “Com Port 1″, the machine knows where to route that information. To do this we had to run the command(s):

root@scabms ~$ MAKEDEV ttyS0
root@scabms ~$ echo T00 > /dev/ttyS0

The first line essentially makes a virtual link or path within the system so that from now on when we do something in reference to ttyS0, the machine knows we’re talking about Com Port 1 or the Serial (DB-9) Port. The second line is an example of the syntax used in command line to send a command to the device we created called ttyS0. This particular command tells the system to send (echo) the command “T00″, which means to toggle each of the 16 ports on (>) Device, ttyS0. When I performed this command and for the first time heard my relays “pop” it was the most exciting point so far in building this system! 

Hardware Commands in a Web Based Language

Now we had the ability to interact with our relays via system calls and needed a way for our interface to control / send commands to these hardware devices. Enter PHP and its exec command. Using this built-in PHP command and the C code that Dave had written (he will write about this soon) I was able to call the compiled C program and cause the Ports on the relay to Toggle on and off at will! This is the key to our task of controlling hardware via a Web Language! 

Looking Forward

Next we will be looking to building a mockup using what we just accomplished to build a small scale prototype of our final project. This will include 2 of our 12VDC Valves, the CO2 system and tubing, and our Interface. We will design it and calibrate it to dispense a drink that is made up of 2 liquids. Keep checking back for updates! They will be coming fast and furious! 

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*