89 lines
2.3 KiB
C#
89 lines
2.3 KiB
C#
using System;
|
|
using System.Windows.Forms;
|
|
using System.IO.Ports;
|
|
using TBF.BenchControl.Generic;
|
|
|
|
namespace TBF.BenchControl.Cameras.IdcCamera
|
|
{
|
|
public partial class IdcCameraCfgCtrl : UserControl, IComponentCfgCtrl
|
|
{
|
|
IdcCameraCfg config;
|
|
|
|
public IComponentCfg Config
|
|
{
|
|
get { return config as IComponentCfg; }
|
|
set
|
|
{
|
|
config = value as IdcCameraCfg;
|
|
Redraw();
|
|
}
|
|
}
|
|
|
|
public IdcCameraCfgCtrl()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void IdcCameraCfgCtrl_Load(object sender, EventArgs e)
|
|
{
|
|
baudRateComboBox.Items.Add("57600");
|
|
baudRateComboBox.Items.Add("115200");
|
|
|
|
Redraw();
|
|
}
|
|
|
|
void Redraw()
|
|
{
|
|
if (config == null) return; /// Control was not loaded, settings were not changed
|
|
|
|
classNameLabel.Text = config.Factory.ClassName;
|
|
nameTextBox.Text = config.Name;
|
|
comPortNrTextBox.Text = config.ComPortNr.ToString();
|
|
baudRateComboBox.Text = config.BaudRate.ToString();
|
|
brightnessTextBox.Text = (100.0f * config.BrightnessCam).ToString();
|
|
}
|
|
|
|
public void Unlock()
|
|
{
|
|
nameTextBox.Enabled = true;
|
|
comPortNrTextBox.Enabled = true;
|
|
baudRateComboBox.Enabled = true;
|
|
brightnessTextBox.Enabled = true;
|
|
}
|
|
|
|
public CfgVerifyFlags VerifyCfg(ref string message)
|
|
{
|
|
CfgVerifyFlags flags = CfgVerifyFlags.None;
|
|
|
|
int dummy;
|
|
if (!int.TryParse(comPortNrTextBox.Text, out dummy) || dummy < 1 || dummy > 999)
|
|
{
|
|
flags |= CfgVerifyFlags.Error;
|
|
message += Environment.NewLine + "'Serial Port Number' is not valid";
|
|
}
|
|
if (!int.TryParse(baudRateComboBox.Text, out dummy) || ((dummy != 57600) && (dummy != 115200)))
|
|
{
|
|
flags |= CfgVerifyFlags.Error;
|
|
message += Environment.NewLine + "'Baud Rate' should be 57600 or 115200 Bd";
|
|
}
|
|
if (!int.TryParse(brightnessTextBox.Text, out dummy) || dummy < 0 || dummy > 100)
|
|
{
|
|
flags |= CfgVerifyFlags.Error;
|
|
message += Environment.NewLine + "'Brightness' should be between 0 and 100 %";
|
|
}
|
|
|
|
return flags;
|
|
}
|
|
|
|
public void UpdateCfg()
|
|
{
|
|
if (config == null) return; /// Control was not loaded, settings were not changed
|
|
|
|
config.Name = nameTextBox.Text;
|
|
config.ComPortNr = int.Parse(comPortNrTextBox.Text);
|
|
config.BaudRate = int.Parse(baudRateComboBox.Text);
|
|
config.BrightnessCam = ((float)int.Parse(brightnessTextBox.Text) / 100.0f);
|
|
}
|
|
}
|
|
}
|