using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Ports;
using System.Threading;
namespace ConsoleApplication1
{
class Program
{
private SerialPort port;
private int step = 1;
private int pgm;
private int delay = 200;
static void Main(string[] args)
{
new Program(1);
}
public Program(int program)
{
Console.WriteLine("COMPort?");
port = new SerialPort(Console.ReadLine(), 9600, Parity.None, 8, StopBits.One);
port.Handshake = Handshake.RequestToSend;
pgm = program;
port.Open();
Thread.Sleep(delay);
// the order of these calls cannot be changed.
NewPGM(); // start a new program (delete what ever is in prm# and make a new one)
PGMStep(10, "OFF", -1, "OFF", 1, 0); // these steps must be in order of step 1 to step n
PGMStep(50, "ON", -1, "OFF", 1, 0);
PGMStep(60, "OFF", -1, "OFF", 1, 0);
PGMStep(70, "OFF", -1, "OFF", 1, 0);
PGMStep(80, "OFF", -1, "OFF", 1, 0);
PGMStep(100, "ON", -1, "OFF", 1, 0);
counter(2, 5, 10); // setup the counter here (optional)
EndPGM("Test", "CONSTANT"); // set the name then the end mode IN ORDER (optional) then close the program
Console.Write("PGM uploaded hit enter to exit");
Console.ReadLine();
port.Close();
}
// just the basics here can the extra settings needed ect.
public void PGMStep(double Temp, string TRamp, int Humi, string HRamp, int hour, int min)
{
string HSTR, HRSTR;
// The chamber will throw an error if hramp is sent in the command string when humi is off regardless of its value ie:
// "...humi off, hrampoff" will throw an error!
if (Humi >= 0 || Humi <= 100)
{
HRSTR = String.Format("HRAMP{0}, ", HRamp);
HSTR = String.Format("{0}", Humi);
}
else
{
HSTR = " OFF";
HRSTR = "";
}
// send the step, note that item #5 is the humidity ramp control as defined above.
port.Write(String.Format("PRGM DATA WRITE, PGM{0}, STEP{1}, TEMP{2:0.0}, TRAMP{3}, HUMI{4}, {5}TIME {6}:{7}\r\n",pgm,step,Temp,TRamp,HSTR,HRSTR,hour,min));
Console.WriteLine(port.ReadLine());
step++;
}
// setup a new program.
public void NewPGM()
{
port.Write(String.Format("PRGM DATA WRITE, PGM{0}, EDIT START\r\n",pgm));
Console.WriteLine(port.ReadLine());
}
// setup counter a note that the documentation on the scp220 communications manual has an error:
// ... pgm1,count, a(settings), b(settings) is the correct method omit either as needed.
public void counter(int StartStep, int EndStep, int Count)
{
port.Write(String.Format("PRGM DATA WRITE, PGM{0}, COUNTA({1}. {2}. {3}\r\n",pgm,StartStep,EndStep,Count));
Console.WriteLine(port.ReadLine());
}
// name the program, set the end mode, then close the program edit.
public void EndPGM(string Name, string EndMode)
{
port.Write(String.Format("PRGM DATA WRITE, PGM{0}, NAME, {1}\r\n", pgm,Name));
Console.WriteLine(port.ReadLine());
port.Write(String.Format("PRGM DATA WRITE, PGM{0}, END, {1}\r\n", pgm, EndMode));
Console.WriteLine(port.ReadLine());
port.Write(String.Format("PRGM DATA WRITE, PGM{0}, EDIT END\r\n", pgm));
Console.WriteLine(port.ReadLine());
}
}
}