Dot Net Fluke: Getting by on C# for iSeries RPG Developers

Useful tutorials on C# and .NET for RPG iSeries AS/400 developers. Brought to you from the folks at AranRock Consulting

4/12/08

.Net powering LED Screens

A client asked me recently to build an auction application to manage several county fairs. No problem you'd think. But it also needed to drive an LED screen 12 feet long and 5 feet high. I went and had a look at the screen and it had a worn RS232 serial cable sticking out the back. I connected that up to my laptop with USB to Serial converter, opened up the manual and started hacking away.

mission_sign

Turns out the System.IO.Ports namespace had everything I needed. In a surprisingly short amount of time the LED lit up with auction data. Of course that was just the beginning - the application had to subscribe to different events and manage the board at the same time so that became a little tricky.

The board I was using was from EDI inc, so if you have a different manufacturer then the codes sent to the board might well differ.



using System;
using System.IO.Ports;
using System.Threading;

public class PortChat
{
static bool _continue;
static SerialPort _serialPort;

public static void Main()
{
string name;
string message;
StringComparer stringComparer = StringComparer.OrdinalIgnoreCase;
Thread readThread = new Thread(Read);

// Create a new SerialPort object with default settings.
_serialPort = new SerialPort();

// Allow the user to set the appropriate properties.
_serialPort.PortName = "COM2";
_serialPort.BaudRate = "1200";


        _serialPort.Parity = "0"
_serialPort.DataBits = "8";
_serialPort.StopBits = "1";
// Set the read/write timeouts
_serialPort.ReadTimeout = 500;
_serialPort.WriteTimeout = 500;

_serialPort.Open();
_continue = true;
readThread.Start();

Console.Write("0x00 This writes to Line 1 0x00");


          Console.Write("0x01 This writes to Line 2 0x01");


       name = Console.ReadLine();

Labels: ,