|
|
|
|
|
|
|
|
private static string SERIALPORT_KEY = "LastSerialPort";
|
|
|
private static string SERIALPORT_KEY = "LastSerialPort";
|
|
|
private static string EXP_FIRMWARE_VER = "ExpectedFirmwareVersion";
|
|
|
private static string EXP_FIRMWARE_VER = "ExpectedFirmwareVersion";
|
|
|
|
|
|
|
|
|
private static bool connected;
|
|
|
|
|
|
private static Boolean Connected {
|
|
|
|
|
|
|
|
|
private bool connected;
|
|
|
|
|
|
private Boolean Connected {
|
|
|
[MethodImpl(MethodImplOptions.Synchronized)]
|
|
|
[MethodImpl(MethodImplOptions.Synchronized)]
|
|
|
get { return connected; }
|
|
|
get { return connected; }
|
|
|
[MethodImpl(MethodImplOptions.Synchronized)]
|
|
|
[MethodImpl(MethodImplOptions.Synchronized)]
|
|
|
set { connected = value; }
|
|
|
set { connected = value; }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
private static bool requestPending;
|
|
|
|
|
|
private static Boolean RequestPending {
|
|
|
|
|
|
|
|
|
private bool requestPending;
|
|
|
|
|
|
private Boolean RequestPending {
|
|
|
[MethodImpl(MethodImplOptions.Synchronized)]
|
|
|
[MethodImpl(MethodImplOptions.Synchronized)]
|
|
|
get { return requestPending; }
|
|
|
get { return requestPending; }
|
|
|
[MethodImpl(MethodImplOptions.Synchronized)]
|
|
|
[MethodImpl(MethodImplOptions.Synchronized)]
|
|
|
set { requestPending = value; }
|
|
|
|
|
|
|
|
|
set { requestPending = value; System.Console.WriteLine(value); }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
private Boolean initializing;
|
|
|
private Boolean initializing;
|
|
|
private string firmwareVersion;
|
|
|
private string firmwareVersion;
|
|
|
|
|
|
|
|
|
|
|
|
private long timerCount;
|
|
|
|
|
|
|
|
|
public MainForm() {
|
|
|
public MainForm() {
|
|
|
initializing = false;
|
|
|
initializing = false;
|
|
|
Connected = false;
|
|
|
Connected = false;
|
|
|
RequestPending = false;
|
|
|
RequestPending = false;
|
|
|
firmwareVersion = new PropertiesHandler(SETTINGS_FILE).get(EXP_FIRMWARE_VER, "V0.0.1");
|
|
|
firmwareVersion = new PropertiesHandler(SETTINGS_FILE).get(EXP_FIRMWARE_VER, "V0.0.1");
|
|
|
|
|
|
timerCount = 0;
|
|
|
InitializeComponent();
|
|
|
InitializeComponent();
|
|
|
initializeSerialPortComboBox();
|
|
|
initializeSerialPortComboBox();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
while (stopwatch.ElapsedMilliseconds < 3000) {
|
|
|
while (stopwatch.ElapsedMilliseconds < 3000) {
|
|
|
Thread.Sleep(50);
|
|
|
Thread.Sleep(50);
|
|
|
if (Connected) {
|
|
|
if (Connected) {
|
|
|
|
|
|
reconnectBtn.Visible = false;
|
|
|
break;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
initializing = true;
|
|
|
initializing = true;
|
|
|
string[] ports = SerialPort.GetPortNames();
|
|
|
string[] ports = SerialPort.GetPortNames();
|
|
|
foreach (string port in ports) {
|
|
|
foreach (string port in ports) {
|
|
|
serialPortsCboBox.Items.Add(port);
|
|
|
|
|
|
|
|
|
if (!serialPortsCboBox.Items.Contains(port)) {
|
|
|
|
|
|
serialPortsCboBox.Items.Add(port);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
PropertiesHandler serialPortCfg = new PropertiesHandler(SETTINGS_FILE);
|
|
|
PropertiesHandler serialPortCfg = new PropertiesHandler(SETTINGS_FILE);
|
|
|
string lastselectedComPort = serialPortCfg.get(SERIALPORT_KEY, "");
|
|
|
string lastselectedComPort = serialPortCfg.get(SERIALPORT_KEY, "");
|
|
|
|
|
|
|
|
|
powerSwitchButton.CheckStateChanged += onSwitchCheckStateChanged;
|
|
|
powerSwitchButton.CheckStateChanged += onSwitchCheckStateChanged;
|
|
|
}
|
|
|
}
|
|
|
}));
|
|
|
}));
|
|
|
|
|
|
} else if (msg.Sender.Equals(Message.CMD_SENDER_AN) && msg.Cmd.Equals(Message.CMD_STATUS_CAM)) {
|
|
|
|
|
|
RequestPending = false;
|
|
|
|
|
|
BeginInvoke(new EventHandler(delegate {
|
|
|
|
|
|
if (msg.Val.Equals(Message.CMD_VAL_ON)) {
|
|
|
|
|
|
webCamRotatorPowerStatusLed.BackgroundImage = FSRemotePowerSwitch.Properties.Resources.blue_led_on;
|
|
|
|
|
|
webCamRotatorPowerSwitch.CheckStateChanged -= onWebCamPowerSwitchCheckStateChanged;
|
|
|
|
|
|
webCamRotatorPowerSwitch.Checked = true;
|
|
|
|
|
|
webCamRotatorPowerSwitch.CheckStateChanged += onWebCamPowerSwitchCheckStateChanged;
|
|
|
|
|
|
} else if (msg.Val.Equals(Message.CMD_VAL_OFF)) {
|
|
|
|
|
|
webCamRotatorPowerStatusLed.BackgroundImage = FSRemotePowerSwitch.Properties.Resources.blue_led_off;
|
|
|
|
|
|
webCamRotatorPowerSwitch.CheckStateChanged -= onWebCamPowerSwitchCheckStateChanged;
|
|
|
|
|
|
webCamRotatorPowerSwitch.Checked = false;
|
|
|
|
|
|
webCamRotatorPowerSwitch.CheckStateChanged += onWebCamPowerSwitchCheckStateChanged;
|
|
|
|
|
|
}
|
|
|
|
|
|
}));
|
|
|
|
|
|
} else if (msg.Sender.Equals(Message.CMD_SENDER_AN) && msg.Cmd.Equals(Message.CMD_ZERO_CAM)) {
|
|
|
|
|
|
RequestPending = false;
|
|
|
|
|
|
BeginInvoke(new EventHandler(delegate {
|
|
|
|
|
|
webCamRotator.Value = int.Parse(msg.Val);
|
|
|
|
|
|
}));
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception ex) when (ex is Newtonsoft.Json.JsonReaderException ||
|
|
|
|
|
|
ex is Newtonsoft.Json.JsonSerializationException) {
|
|
|
|
|
|
|
|
|
} catch (Exception ex) /*when (ex is Newtonsoft.Json.JsonReaderException ||
|
|
|
|
|
|
ex is Newtonsoft.Json.JsonSerializationException)*/ {
|
|
|
RequestPending = false;
|
|
|
RequestPending = false;
|
|
|
initStatusLbl.Text = "Json Deserialize Exception!";
|
|
|
initStatusLbl.Text = "Json Deserialize Exception!";
|
|
|
serialPort.DiscardInBuffer();
|
|
|
serialPort.DiscardInBuffer();
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
private void sendWebCamZeroCmd() {
|
|
|
|
|
|
|
|
|
private void sendWebCamStatusCmd() {
|
|
|
Message msg = new Message();
|
|
|
Message msg = new Message();
|
|
|
msg.Sender = Message.CMD_SENDER_PC;
|
|
|
msg.Sender = Message.CMD_SENDER_PC;
|
|
|
msg.Cmd = Message.CMD_ZERO_CAM;
|
|
|
|
|
|
msg.Val = "0";
|
|
|
|
|
|
|
|
|
msg.Cmd = Message.CMD_STATUS_CAM;
|
|
|
|
|
|
msg.Val = null;
|
|
|
string msJson = JsonConvert.SerializeObject(msg);
|
|
|
string msJson = JsonConvert.SerializeObject(msg);
|
|
|
if (serialPort.IsOpen && !RequestPending) {
|
|
|
if (serialPort.IsOpen && !RequestPending) {
|
|
|
serialPort.Write(msJson);
|
|
|
serialPort.Write(msJson);
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
private void sendWebCamAzimutCmd() {
|
|
|
|
|
|
|
|
|
private void sendWebCamPowerCmd(string value) {
|
|
|
Message msg = new Message();
|
|
|
Message msg = new Message();
|
|
|
msg.Sender = Message.CMD_SENDER_PC;
|
|
|
msg.Sender = Message.CMD_SENDER_PC;
|
|
|
msg.Cmd = Message.CMD_AZIMUT_CAM;
|
|
|
|
|
|
msg.Val = webCamRotator.Value.ToString();
|
|
|
|
|
|
|
|
|
msg.Cmd = Message.CMD_POWER_CAM;
|
|
|
|
|
|
msg.Val = value;
|
|
|
string msJson = JsonConvert.SerializeObject(msg);
|
|
|
string msJson = JsonConvert.SerializeObject(msg);
|
|
|
if (serialPort.IsOpen && !RequestPending) {
|
|
|
if (serialPort.IsOpen && !RequestPending) {
|
|
|
serialPort.Write(msJson);
|
|
|
serialPort.Write(msJson);
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
private void sendWebCamPowerCmd(string value) {
|
|
|
|
|
|
|
|
|
private void sendWebCamZeroCmd() {
|
|
|
Message msg = new Message();
|
|
|
Message msg = new Message();
|
|
|
msg.Sender = Message.CMD_SENDER_PC;
|
|
|
msg.Sender = Message.CMD_SENDER_PC;
|
|
|
msg.Cmd = Message.CMD_POWER_CAM;
|
|
|
|
|
|
msg.Val = value;
|
|
|
|
|
|
|
|
|
msg.Cmd = Message.CMD_ZERO_CAM;
|
|
|
|
|
|
msg.Val = "0";
|
|
|
string msJson = JsonConvert.SerializeObject(msg);
|
|
|
string msJson = JsonConvert.SerializeObject(msg);
|
|
|
if (serialPort.IsOpen && !RequestPending) {
|
|
|
if (serialPort.IsOpen && !RequestPending) {
|
|
|
serialPort.Write(msJson);
|
|
|
serialPort.Write(msJson);
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void sendWebCamAzimutCmd() {
|
|
|
|
|
|
Message msg = new Message();
|
|
|
|
|
|
msg.Sender = Message.CMD_SENDER_PC;
|
|
|
|
|
|
msg.Cmd = Message.CMD_AZIMUT_CAM;
|
|
|
|
|
|
msg.Val = webCamRotator.Value.ToString();
|
|
|
|
|
|
string msJson = JsonConvert.SerializeObject(msg);
|
|
|
|
|
|
if (serialPort.IsOpen && !RequestPending) {
|
|
|
|
|
|
serialPort.Write(msJson);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
private void onStatusTimerTick(object sender, EventArgs e) {
|
|
|
private void onStatusTimerTick(object sender, EventArgs e) {
|
|
|
sendRelayStatusCmd();
|
|
|
|
|
|
|
|
|
if (timerCount % 2 == 0) {
|
|
|
|
|
|
sendWebCamStatusCmd();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
sendRelayStatusCmd();
|
|
|
|
|
|
}
|
|
|
|
|
|
timerCount++;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
private void onMainFormClosing(object sender, FormClosingEventArgs e) {
|
|
|
private void onMainFormClosing(object sender, FormClosingEventArgs e) {
|