Liquid Hotdog

PHP, Adaptive LED Signs, and You

I'd like to provide a small example of interfacing with an Adaptive Alpha LED display bar via RS232. In this case, I'm working with an Alpha 215R although it should also work with anything else in the Alpha 200 series.

My reason for doing this was to provide a way for Winamp to update the Alpha sign with 'Now Playing' information. I plan to provide steps to accomplish that in a bit. For now, I'm just posting the code for com port communication.

PHP:
  1. <?
  2. // We need to make sure the local text file is updated before we run the script.
  3. // So, I'm putting a 1 second pause here to make sure winamp has updated the nowPlaying.txt file.
  4. sleep(1);
  5.  
  6.  
  7. // Set com port mode to match ALPHA 215R settings.
  8. $set_mode = "MODE COM1: BAUD=9600 PARITY=E DATA=7 STOP=1 TO=ON XON=OFF ODSR=ON OCTS=ON DTR=ON RTS=ON IDSR=ON";
  9. $output = array();
  10. exec($set_mode, $output, $result);
  11. //Uncomment the following line to debug MODE settings.
  12. //print_r($output);
  13.  
  14. #check exit status from MODE command
  15. switch ($result) {
  16.     case 0 :
  17.         echo("COM1 parameters set successfully.\n");
  18.         break;
  19.     default :
  20.         echo("Error while trying to set COM1 parameters - exiting.\n");
  21.         exit;
  22. }
  23.  
  24. // Open the com port to write to
  25. $fp = fopen("COM1", "wb");
  26.  
  27. if(!$fp)
  28. {
  29.     echo("ERROR OPENING COM1 FOR WRITING.\n");
  30.     return;
  31. }
  32.  
  33. // Read in 'now playing' information.
  34. $aNowPlaying = file("nowPlaying.txt");
  35. $sNowPlaying = $aNowPlaying[0];
  36.  
  37. // send control codes to copy a new TEXT line onto the display.
  38. // This is the point where you'd want to consult the alpha manual
  39. // for setting up all the display options you need.
  40. // Refer to Alpha document 9708-8061E
  41. fputs($fp, chr(1)."Z00");
  42. fputs($fp, chr(2)."AA".chr(27)."&a".$sNowPlaying.chr(4));
  43.  
  44. fclose($fp);
  45.  
  46. ?>

-- MrBlaQ
Filed under: Coding, Main — August 10, 2005 @ 7:19 pm
Valid XHTML 1.0 Valid CSS 2
eXTReMe Tracker