using System;
using System.IO.Ports;
namespace SerialToParallel
{
class Program
{
static SerialPort ms_oSerialPort = null;
static void Main(string[] args)
{
try
{
ms_oSerialPort = new SerialPort( "COM3", 9600, Parity.None, 8, StopBits.One );
ms_oSerialPort.Open();
}
catch(Exception e)
{
System.Console.WriteLine( e.ToString() );
}
if(ms_oSerialPort != null && ms_oSerialPort.IsOpen)
{
try
{
for(int nLoops = 0; nLoops < 100; nLoops++)
{
for(int n = 0; n < 255; n++)
{
byte[] aBytes = GetSignalBytes( (byte)n );
ms_oSerialPort.Write( aBytes, 0, 2 );
System.Threading.Thread.Sleep( 200 );
}
}
}
catch(Exception e)
{
System.Console.WriteLine( e.ToString() );
}
ms_oSerialPort.Close();
}
}
private static byte[] GetSignalBytes(byte n)
{
byte[] aBytes = new byte[2];
aBytes[0] = (byte)((n & 0x0F) | 0x80);
aBytes[1] = (byte)(((n & 0xF0) >> 4) | 0x80);
return aBytes;
}
}