using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Ports;
using System.Diagnostics;

namespace WiPoMServer
{
    /// <summary>
    /// Interface for communicating over serial to zigbee.
    /// But only value will be sent (range 0-255)
    /// Actual Power value will be generated from sent value --> fake!
    /// </summary>
    public class DimmerInterface
    {
        SerialPort serial;

        public DimmerInterface()
        {
            this.serial = new SerialPort(Properties.Settings.Default.ComPort);
            serial.Encoding = Encoding.ASCII;
        }

        public void WriteValue(int no)
        {
            //Debug.WriteLine("Write value:\t" + (char)((byte)no));
            //this.serial.Write("set level:" + no.ToString() + ":");
            char[] chars = new char[1];
            chars[0] = (char)no;
            byte[] data = Encoding.ASCII.GetBytes( chars);
            //Debug.WriteLine("Data:\t" + data);
            this.serial.Write(data, 0, data.Length);
        }

        public void TestChars()
        {
            for (int i = 0; i < 256; i++)
            {
                Debug.WriteLine(i + "\t" + (char)((byte)i));
            }
        }
    }
}
