Browse Source

Initialisierung verbessert

develop
Flo Smilari 1 year ago
parent
commit
1d69c1ff92
4 changed files with 178 additions and 97 deletions
  1. BIN
      .vs/FSRemotePowerSwitch/v16/.suo
  2. 71
    13
      Form1.Designer.cs
  3. 106
    84
      Form1.cs
  4. 1
    0
      Message.cs

BIN
.vs/FSRemotePowerSwitch/v16/.suo View File


+ 71
- 13
Form1.Designer.cs View File

this.button1 = new System.Windows.Forms.Button(); this.button1 = new System.Windows.Forms.Button();
this.webCamRotatorPowerSwitch = new FSRemotePowerSwitch.SButton(); this.webCamRotatorPowerSwitch = new FSRemotePowerSwitch.SButton();
this.powerSwitchButton = new FSRemotePowerSwitch.SButton(); this.powerSwitchButton = new FSRemotePowerSwitch.SButton();
this.webCamRotVelocityLbl = new System.Windows.Forms.Label();
this.webCamRotatorVelocitySwitch = new FSRemotePowerSwitch.SButton();
this.webCamRotatorVelocitySlowLbl = new System.Windows.Forms.Label();
this.webCamRotatorVelocityFastLbl = new System.Windows.Forms.Label();
this.statusBar.SuspendLayout(); this.statusBar.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.powerStateLed)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.powerStateLed)).BeginInit();
this.label1.AutoSize = true; this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("Bahnschrift SemiBold SemiConden", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label1.Font = new System.Drawing.Font("Bahnschrift SemiBold SemiConden", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label1.ForeColor = System.Drawing.SystemColors.HotTrack; this.label1.ForeColor = System.Drawing.SystemColors.HotTrack;
this.label1.Location = new System.Drawing.Point(44, 219);
this.label1.Location = new System.Drawing.Point(44, 230);
this.label1.Name = "label1"; this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(135, 19); this.label1.Size = new System.Drawing.Size(135, 19);
this.label1.TabIndex = 13; this.label1.TabIndex = 13;
this.powerStateLed.BackgroundImage = global::FSRemotePowerSwitch.Properties.Resources.blue_led_off; this.powerStateLed.BackgroundImage = global::FSRemotePowerSwitch.Properties.Resources.blue_led_off;
this.powerStateLed.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; this.powerStateLed.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.powerStateLed.InitialImage = null; this.powerStateLed.InitialImage = null;
this.powerStateLed.Location = new System.Drawing.Point(92, 258);
this.powerStateLed.Location = new System.Drawing.Point(92, 269);
this.powerStateLed.Name = "powerStateLed"; this.powerStateLed.Name = "powerStateLed";
this.powerStateLed.Size = new System.Drawing.Size(40, 40); this.powerStateLed.Size = new System.Drawing.Size(40, 40);
this.powerStateLed.TabIndex = 12; this.powerStateLed.TabIndex = 12;
this.webCamRotator.KnobBackColor = System.Drawing.Color.Silver; this.webCamRotator.KnobBackColor = System.Drawing.Color.Silver;
this.webCamRotator.KnobPointerStyle = KnobControl.KnobControl.KnobPointerStyles.circle; this.webCamRotator.KnobPointerStyle = KnobControl.KnobControl.KnobPointerStyles.circle;
this.webCamRotator.LargeChange = 5; this.webCamRotator.LargeChange = 5;
this.webCamRotator.Location = new System.Drawing.Point(247, 122);
this.webCamRotator.Location = new System.Drawing.Point(234, 133);
this.webCamRotator.Maximum = 180; this.webCamRotator.Maximum = 180;
this.webCamRotator.Minimum = -180; this.webCamRotator.Minimum = -180;
this.webCamRotator.Name = "webCamRotator"; this.webCamRotator.Name = "webCamRotator";
this.rotatorActValue.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this.rotatorActValue.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.rotatorActValue.Font = new System.Drawing.Font("Bahnschrift", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.rotatorActValue.Font = new System.Drawing.Font("Bahnschrift", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.rotatorActValue.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(151)))), ((int)(((byte)(156))))); this.rotatorActValue.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(151)))), ((int)(((byte)(156)))));
this.rotatorActValue.Location = new System.Drawing.Point(309, 264);
this.rotatorActValue.Location = new System.Drawing.Point(296, 275);
this.rotatorActValue.Name = "rotatorActValue"; this.rotatorActValue.Name = "rotatorActValue";
this.rotatorActValue.Size = new System.Drawing.Size(40, 20); this.rotatorActValue.Size = new System.Drawing.Size(40, 20);
this.rotatorActValue.TabIndex = 18; this.rotatorActValue.TabIndex = 18;
this.webCamRotatorLbl.AutoSize = true; this.webCamRotatorLbl.AutoSize = true;
this.webCamRotatorLbl.Font = new System.Drawing.Font("Bahnschrift SemiBold SemiConden", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.webCamRotatorLbl.Font = new System.Drawing.Font("Bahnschrift SemiBold SemiConden", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.webCamRotatorLbl.ForeColor = System.Drawing.SystemColors.HotTrack; this.webCamRotatorLbl.ForeColor = System.Drawing.SystemColors.HotTrack;
this.webCamRotatorLbl.Location = new System.Drawing.Point(261, 96);
this.webCamRotatorLbl.Location = new System.Drawing.Point(248, 96);
this.webCamRotatorLbl.Name = "webCamRotatorLbl"; this.webCamRotatorLbl.Name = "webCamRotatorLbl";
this.webCamRotatorLbl.Size = new System.Drawing.Size(137, 19); this.webCamRotatorLbl.Size = new System.Drawing.Size(137, 19);
this.webCamRotatorLbl.TabIndex = 19; this.webCamRotatorLbl.TabIndex = 19;
this.webCamRotPowerLbl.AutoSize = true; this.webCamRotPowerLbl.AutoSize = true;
this.webCamRotPowerLbl.Font = new System.Drawing.Font("Bahnschrift SemiBold SemiConden", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.webCamRotPowerLbl.Font = new System.Drawing.Font("Bahnschrift SemiBold SemiConden", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.webCamRotPowerLbl.ForeColor = System.Drawing.SystemColors.HotTrack; this.webCamRotPowerLbl.ForeColor = System.Drawing.SystemColors.HotTrack;
this.webCamRotPowerLbl.Location = new System.Drawing.Point(412, 219);
this.webCamRotPowerLbl.Location = new System.Drawing.Point(400, 230);
this.webCamRotPowerLbl.Name = "webCamRotPowerLbl"; this.webCamRotPowerLbl.Name = "webCamRotPowerLbl";
this.webCamRotPowerLbl.Size = new System.Drawing.Size(157, 19); this.webCamRotPowerLbl.Size = new System.Drawing.Size(157, 19);
this.webCamRotPowerLbl.TabIndex = 21; this.webCamRotPowerLbl.TabIndex = 21;
this.webCamRotatorPowerStatusLed.BackgroundImage = global::FSRemotePowerSwitch.Properties.Resources.blue_led_off; this.webCamRotatorPowerStatusLed.BackgroundImage = global::FSRemotePowerSwitch.Properties.Resources.blue_led_off;
this.webCamRotatorPowerStatusLed.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; this.webCamRotatorPowerStatusLed.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.webCamRotatorPowerStatusLed.InitialImage = null; this.webCamRotatorPowerStatusLed.InitialImage = null;
this.webCamRotatorPowerStatusLed.Location = new System.Drawing.Point(525, 258);
this.webCamRotatorPowerStatusLed.Location = new System.Drawing.Point(512, 269);
this.webCamRotatorPowerStatusLed.Name = "webCamRotatorPowerStatusLed"; this.webCamRotatorPowerStatusLed.Name = "webCamRotatorPowerStatusLed";
this.webCamRotatorPowerStatusLed.Size = new System.Drawing.Size(40, 40); this.webCamRotatorPowerStatusLed.Size = new System.Drawing.Size(40, 40);
this.webCamRotatorPowerStatusLed.TabIndex = 20; this.webCamRotatorPowerStatusLed.TabIndex = 20;
this.webCamRotPwrStatusLbl.AutoSize = true; this.webCamRotPwrStatusLbl.AutoSize = true;
this.webCamRotPwrStatusLbl.Font = new System.Drawing.Font("Bahnschrift SemiBold SemiConden", 10F, System.Drawing.FontStyle.Bold); this.webCamRotPwrStatusLbl.Font = new System.Drawing.Font("Bahnschrift SemiBold SemiConden", 10F, System.Drawing.FontStyle.Bold);
this.webCamRotPwrStatusLbl.ForeColor = System.Drawing.SystemColors.HotTrack; this.webCamRotPwrStatusLbl.ForeColor = System.Drawing.SystemColors.HotTrack;
this.webCamRotPwrStatusLbl.Location = new System.Drawing.Point(524, 241);
this.webCamRotPwrStatusLbl.Location = new System.Drawing.Point(511, 252);
this.webCamRotPwrStatusLbl.Name = "webCamRotPwrStatusLbl"; this.webCamRotPwrStatusLbl.Name = "webCamRotPwrStatusLbl";
this.webCamRotPwrStatusLbl.Size = new System.Drawing.Size(43, 17); this.webCamRotPwrStatusLbl.Size = new System.Drawing.Size(43, 17);
this.webCamRotPwrStatusLbl.TabIndex = 22; this.webCamRotPwrStatusLbl.TabIndex = 22;
this.webCamRotatorPowerOffLbl.AutoSize = true; this.webCamRotatorPowerOffLbl.AutoSize = true;
this.webCamRotatorPowerOffLbl.Font = new System.Drawing.Font("Bahnschrift SemiBold SemiConden", 12F, System.Drawing.FontStyle.Bold); this.webCamRotatorPowerOffLbl.Font = new System.Drawing.Font("Bahnschrift SemiBold SemiConden", 12F, System.Drawing.FontStyle.Bold);
this.webCamRotatorPowerOffLbl.ForeColor = System.Drawing.Color.Red; this.webCamRotatorPowerOffLbl.ForeColor = System.Drawing.Color.Red;
this.webCamRotatorPowerOffLbl.Location = new System.Drawing.Point(413, 267);
this.webCamRotatorPowerOffLbl.Location = new System.Drawing.Point(400, 278);
this.webCamRotatorPowerOffLbl.Name = "webCamRotatorPowerOffLbl"; this.webCamRotatorPowerOffLbl.Name = "webCamRotatorPowerOffLbl";
this.webCamRotatorPowerOffLbl.Size = new System.Drawing.Size(34, 19); this.webCamRotatorPowerOffLbl.Size = new System.Drawing.Size(34, 19);
this.webCamRotatorPowerOffLbl.TabIndex = 23; this.webCamRotatorPowerOffLbl.TabIndex = 23;
this.webCamRotatorPowerOnLbl.AutoSize = true; this.webCamRotatorPowerOnLbl.AutoSize = true;
this.webCamRotatorPowerOnLbl.Font = new System.Drawing.Font("Bahnschrift SemiBold SemiConden", 12F, System.Drawing.FontStyle.Bold); this.webCamRotatorPowerOnLbl.Font = new System.Drawing.Font("Bahnschrift SemiBold SemiConden", 12F, System.Drawing.FontStyle.Bold);
this.webCamRotatorPowerOnLbl.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(151)))), ((int)(((byte)(156))))); this.webCamRotatorPowerOnLbl.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(151)))), ((int)(((byte)(156)))));
this.webCamRotatorPowerOnLbl.Location = new System.Drawing.Point(491, 268);
this.webCamRotatorPowerOnLbl.Location = new System.Drawing.Point(478, 279);
this.webCamRotatorPowerOnLbl.Name = "webCamRotatorPowerOnLbl"; this.webCamRotatorPowerOnLbl.Name = "webCamRotatorPowerOnLbl";
this.webCamRotatorPowerOnLbl.Size = new System.Drawing.Size(30, 19); this.webCamRotatorPowerOnLbl.Size = new System.Drawing.Size(30, 19);
this.webCamRotatorPowerOnLbl.TabIndex = 24; this.webCamRotatorPowerOnLbl.TabIndex = 24;
this.label2.AutoSize = true; this.label2.AutoSize = true;
this.label2.Font = new System.Drawing.Font("Bahnschrift SemiBold SemiConden", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label2.Font = new System.Drawing.Font("Bahnschrift SemiBold SemiConden", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label2.ForeColor = System.Drawing.SystemColors.HotTrack; this.label2.ForeColor = System.Drawing.SystemColors.HotTrack;
this.label2.Location = new System.Drawing.Point(427, 135);
this.label2.Location = new System.Drawing.Point(400, 96);
this.label2.Name = "label2"; this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(128, 19); this.label2.Size = new System.Drawing.Size(128, 19);
this.label2.TabIndex = 26; this.label2.TabIndex = 26;
// //
// button1 // button1
// //
this.button1.Location = new System.Drawing.Point(456, 165);
this.button1.Location = new System.Drawing.Point(403, 123);
this.button1.Name = "button1"; this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 26); this.button1.Size = new System.Drawing.Size(75, 26);
this.button1.TabIndex = 27; this.button1.TabIndex = 27;
// //
// webCamRotatorPowerSwitch // webCamRotatorPowerSwitch
// //
this.webCamRotatorPowerSwitch.Location = new System.Drawing.Point(447, 267);
this.webCamRotatorPowerSwitch.Location = new System.Drawing.Point(434, 278);
this.webCamRotatorPowerSwitch.MinimumSize = new System.Drawing.Size(45, 22); this.webCamRotatorPowerSwitch.MinimumSize = new System.Drawing.Size(45, 22);
this.webCamRotatorPowerSwitch.Name = "webCamRotatorPowerSwitch"; this.webCamRotatorPowerSwitch.Name = "webCamRotatorPowerSwitch";
this.webCamRotatorPowerSwitch.OffBackColor = System.Drawing.Color.Gray; this.webCamRotatorPowerSwitch.OffBackColor = System.Drawing.Color.Gray;
this.powerSwitchButton.UseVisualStyleBackColor = true; this.powerSwitchButton.UseVisualStyleBackColor = true;
this.powerSwitchButton.CheckStateChanged += new System.EventHandler(this.onSwitchCheckStateChanged); this.powerSwitchButton.CheckStateChanged += new System.EventHandler(this.onSwitchCheckStateChanged);
// //
// webCamRotVelocityLbl
//
this.webCamRotVelocityLbl.AutoSize = true;
this.webCamRotVelocityLbl.Font = new System.Drawing.Font("Bahnschrift SemiBold SemiConden", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.webCamRotVelocityLbl.ForeColor = System.Drawing.SystemColors.HotTrack;
this.webCamRotVelocityLbl.Location = new System.Drawing.Point(400, 165);
this.webCamRotVelocityLbl.Name = "webCamRotVelocityLbl";
this.webCamRotVelocityLbl.Size = new System.Drawing.Size(170, 19);
this.webCamRotVelocityLbl.TabIndex = 28;
this.webCamRotVelocityLbl.Text = "WebCam Geschwindigkeit";
//
// webCamRotatorVelocitySwitch
//
this.webCamRotatorVelocitySwitch.Location = new System.Drawing.Point(447, 194);
this.webCamRotatorVelocitySwitch.MinimumSize = new System.Drawing.Size(45, 22);
this.webCamRotatorVelocitySwitch.Name = "webCamRotatorVelocitySwitch";
this.webCamRotatorVelocitySwitch.OffBackColor = System.Drawing.Color.Gray;
this.webCamRotatorVelocitySwitch.OffToggleColor = System.Drawing.Color.Gainsboro;
this.webCamRotatorVelocitySwitch.OnBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(151)))), ((int)(((byte)(156)))));
this.webCamRotatorVelocitySwitch.OnToggleColor = System.Drawing.Color.WhiteSmoke;
this.webCamRotatorVelocitySwitch.Size = new System.Drawing.Size(45, 22);
this.webCamRotatorVelocitySwitch.TabIndex = 31;
this.webCamRotatorVelocitySwitch.UseVisualStyleBackColor = true;
//
// webCamRotatorVelocitySlowLbl
//
this.webCamRotatorVelocitySlowLbl.AutoSize = true;
this.webCamRotatorVelocitySlowLbl.Font = new System.Drawing.Font("Bahnschrift SemiBold SemiConden", 12F, System.Drawing.FontStyle.Bold);
this.webCamRotatorVelocitySlowLbl.ForeColor = System.Drawing.Color.Red;
this.webCamRotatorVelocitySlowLbl.Location = new System.Drawing.Point(400, 194);
this.webCamRotatorVelocitySlowLbl.Name = "webCamRotatorVelocitySlowLbl";
this.webCamRotatorVelocitySlowLbl.Size = new System.Drawing.Size(45, 19);
this.webCamRotatorVelocitySlowLbl.TabIndex = 29;
this.webCamRotatorVelocitySlowLbl.Text = "SLOW";
//
// webCamRotatorVelocityFastLbl
//
this.webCamRotatorVelocityFastLbl.AutoSize = true;
this.webCamRotatorVelocityFastLbl.Font = new System.Drawing.Font("Bahnschrift SemiBold SemiConden", 12F, System.Drawing.FontStyle.Bold);
this.webCamRotatorVelocityFastLbl.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(151)))), ((int)(((byte)(156)))));
this.webCamRotatorVelocityFastLbl.Location = new System.Drawing.Point(494, 195);
this.webCamRotatorVelocityFastLbl.Name = "webCamRotatorVelocityFastLbl";
this.webCamRotatorVelocityFastLbl.Size = new System.Drawing.Size(38, 19);
this.webCamRotatorVelocityFastLbl.TabIndex = 30;
this.webCamRotatorVelocityFastLbl.Text = "FAST";
//
// MainForm // MainForm
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 18F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 18F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(584, 361); this.ClientSize = new System.Drawing.Size(584, 361);
this.Controls.Add(this.webCamRotatorVelocitySwitch);
this.Controls.Add(this.webCamRotatorVelocitySlowLbl);
this.Controls.Add(this.webCamRotatorVelocityFastLbl);
this.Controls.Add(this.webCamRotVelocityLbl);
this.Controls.Add(this.button1); this.Controls.Add(this.button1);
this.Controls.Add(this.label2); this.Controls.Add(this.label2);
this.Controls.Add(this.webCamRotatorPowerSwitch); this.Controls.Add(this.webCamRotatorPowerSwitch);
private System.Windows.Forms.Label webCamRotatorPowerOnLbl; private System.Windows.Forms.Label webCamRotatorPowerOnLbl;
private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label webCamRotVelocityLbl;
private SButton webCamRotatorVelocitySwitch;
private System.Windows.Forms.Label webCamRotatorVelocitySlowLbl;
private System.Windows.Forms.Label webCamRotatorVelocityFastLbl;
} }
} }

+ 106
- 84
Form1.cs View File

set { connected = value; } set { connected = value; }
} }
private bool requestPending;
private Boolean RequestPending {
private static bool requestPending;
private static Boolean RequestPending {
[MethodImpl(MethodImplOptions.Synchronized)] [MethodImpl(MethodImplOptions.Synchronized)]
get { return requestPending; } get { return requestPending; }
[MethodImpl(MethodImplOptions.Synchronized)] [MethodImpl(MethodImplOptions.Synchronized)]
set { requestPending = value; System.Console.WriteLine(value); }
set { requestPending = value; }
} }
private Boolean initializing; private Boolean initializing;
public MainForm() { public MainForm() {
initializing = false; initializing = false;
Connected = false; Connected = 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; timerCount = 0;
InitializeComponent(); InitializeComponent();
while (stopwatch.ElapsedMilliseconds < 3000) { while (stopwatch.ElapsedMilliseconds < 3000) {
Thread.Sleep(50); Thread.Sleep(50);
if (Connected) { if (Connected) {
reconnectBtn.Visible = false;
waitForPendingRequest();
sendRelayStatusCmd();
waitForPendingRequest();
sendWebCamStatusCmd();
waitForPendingRequest();
sendWebCamActualAzimutCmd();
BeginInvoke(new EventHandler(delegate {
reconnectBtn.Visible = false;
}));
break; break;
} }
} }
Cursor.Position = Cursor.Position; Cursor.Position = Cursor.Position;
} }
private void waitForPendingRequest() {
while(RequestPending) {
Thread.Sleep(2);
}
}
private void initializeSerialPortComboBox() { private void initializeSerialPortComboBox() {
initializing = true; initializing = true;
string[] ports = SerialPort.GetPortNames(); string[] ports = SerialPort.GetPortNames();
} }
private void onSerialPortDataReceived(object sender, SerialDataReceivedEventArgs e) { private void onSerialPortDataReceived(object sender, SerialDataReceivedEventArgs e) {
string s = readSerialPortData((SerialPort)sender);
try {
while (serialPort.IsOpen && serialPort.BytesToRead > 0) {
string s = readSerialPortData((SerialPort)sender);
Message msg = JsonConvert.DeserializeObject<Message>(s); Message msg = JsonConvert.DeserializeObject<Message>(s);
if (msg.Sender.Equals(Message.CMD_SENDER_AN) && msg.Cmd.Equals(Message.CMD_VER) && msg.Val.Equals(firmwareVersion)) {
RequestPending = false;
BeginInvoke(new EventHandler(delegate {
sendRelayStatusCmd();
Connected = true;
initStatusLbl.Text = "Verbunden";
connectedSerialPortLbl.Text = "Port: " + ((SerialPort)sender).PortName;
fwVersionLbl.Text = "Ver: " + firmwareVersion;
initProgressBar.Style = ProgressBarStyle.Continuous;
initProgressBar.Value = 100;
openBtn.Enabled = false;
closeBtn.Enabled = true;
powerSwitchButton.Enabled = true;
statusTimer.Enabled = true;
}));
} else if (msg.Sender.Equals(Message.CMD_SENDER_AN) && msg.Cmd.Equals(Message.CMD_STATUS_RELAY)) {
RequestPending = false;
BeginInvoke(new EventHandler(delegate {
if (msg.Val.Equals(Message.CMD_VAL_ON)) {
powerStateLed.BackgroundImage = FSRemotePowerSwitch.Properties.Resources.blue_led_on;
powerSwitchButton.CheckStateChanged -= onSwitchCheckStateChanged;
powerSwitchButton.Checked = true;
powerSwitchButton.CheckStateChanged += onSwitchCheckStateChanged;
} else if (msg.Val.Equals(Message.CMD_VAL_OFF)) {
powerStateLed.BackgroundImage = FSRemotePowerSwitch.Properties.Resources.blue_led_off;
powerSwitchButton.CheckStateChanged -= onSwitchCheckStateChanged;
powerSwitchButton.Checked = false;
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);
}));
try {
if (msg.Sender.Equals(Message.CMD_SENDER_AN) && msg.Cmd.Equals(Message.CMD_VER) && msg.Val.Equals(firmwareVersion)) {
BeginInvoke(new EventHandler(delegate {
Connected = true;
initStatusLbl.Text = "Verbunden";
connectedSerialPortLbl.Text = "Port: " + ((SerialPort)sender).PortName;
fwVersionLbl.Text = "Ver: " + firmwareVersion;
initProgressBar.Style = ProgressBarStyle.Continuous;
initProgressBar.Value = 100;
openBtn.Enabled = false;
closeBtn.Enabled = true;
powerSwitchButton.Enabled = true;
statusTimer.Enabled = true;
}));
} else if (msg.Sender.Equals(Message.CMD_SENDER_AN) && msg.Cmd.Equals(Message.CMD_STATUS_RELAY)) {
RequestPending = false;
BeginInvoke(new EventHandler(delegate {
if (msg.Val.Equals(Message.CMD_VAL_ON)) {
powerStateLed.BackgroundImage = FSRemotePowerSwitch.Properties.Resources.blue_led_on;
powerSwitchButton.CheckStateChanged -= onSwitchCheckStateChanged;
powerSwitchButton.Checked = true;
powerSwitchButton.CheckStateChanged += onSwitchCheckStateChanged;
} else if (msg.Val.Equals(Message.CMD_VAL_OFF)) {
powerStateLed.BackgroundImage = FSRemotePowerSwitch.Properties.Resources.blue_led_off;
powerSwitchButton.CheckStateChanged -= onSwitchCheckStateChanged;
powerSwitchButton.Checked = false;
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)) {
BeginInvoke(new EventHandler(delegate {
webCamRotator.Value = int.Parse(msg.Val);
}));
} else if (msg.Sender.Equals(Message.CMD_SENDER_AN) && msg.Cmd.Equals(Message.CMD_ACT_AZIMUT_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) {
initStatusLbl.Text = "Json Deserialize Exception!";
serialPort.DiscardInBuffer();
serialPort.DiscardOutBuffer();
serialPort.Dispose();
} }
} catch (Exception ex) /*when (ex is Newtonsoft.Json.JsonReaderException ||
ex is Newtonsoft.Json.JsonSerializationException)*/ {
RequestPending = false;
initStatusLbl.Text = "Json Deserialize Exception!";
serialPort.DiscardInBuffer();
serialPort.DiscardOutBuffer();
serialPort.Dispose();
} }
} }
private String readSerialPortData(SerialPort serialPort) { private String readSerialPortData(SerialPort serialPort) {
string data = ""; string data = "";
while (serialPort.BytesToRead > 0) {
data += serialPort.ReadExisting();
Thread.Sleep(50);
}
int character = 0; ;
do {
if (serialPort.IsOpen) {
character = serialPort.ReadByte();
data += (char)character;
}
} while ((char)character != '}');
return data; return data;
} }
msg.Cmd = Message.CMD_VER; msg.Cmd = Message.CMD_VER;
msg.Val = null; msg.Val = null;
string msJson = JsonConvert.SerializeObject(msg); string msJson = JsonConvert.SerializeObject(msg);
if (serialPort.IsOpen && !RequestPending) {
if (serialPort.IsOpen) {
serialPort.Write(msJson); serialPort.Write(msJson);
RequestPending = true;
} }
} }
msg.Cmd = Message.CMD_POWER_RELAY; msg.Cmd = Message.CMD_POWER_RELAY;
msg.Val = value; msg.Val = value;
string msJson = JsonConvert.SerializeObject(msg); string msJson = JsonConvert.SerializeObject(msg);
if (serialPort.IsOpen && !RequestPending) {
if (serialPort.IsOpen) {
serialPort.Write(msJson); serialPort.Write(msJson);
RequestPending = true;
} }
} }
msg.Cmd = Message.CMD_STATUS_RELAY; msg.Cmd = Message.CMD_STATUS_RELAY;
msg.Val = null; msg.Val = null;
string msJson = JsonConvert.SerializeObject(msg); string msJson = JsonConvert.SerializeObject(msg);
if (serialPort.IsOpen && !RequestPending) {
if (serialPort.IsOpen) {
serialPort.Write(msJson); serialPort.Write(msJson);
RequestPending = true; RequestPending = true;
} }
msg.Cmd = Message.CMD_STATUS_CAM; msg.Cmd = Message.CMD_STATUS_CAM;
msg.Val = null; msg.Val = null;
string msJson = JsonConvert.SerializeObject(msg); string msJson = JsonConvert.SerializeObject(msg);
if (serialPort.IsOpen && !RequestPending) {
if (serialPort.IsOpen) {
serialPort.Write(msJson); serialPort.Write(msJson);
RequestPending = true; RequestPending = true;
} }
msg.Cmd = Message.CMD_POWER_CAM; msg.Cmd = Message.CMD_POWER_CAM;
msg.Val = value; msg.Val = value;
string msJson = JsonConvert.SerializeObject(msg); string msJson = JsonConvert.SerializeObject(msg);
if (serialPort.IsOpen && !RequestPending) {
if (serialPort.IsOpen) {
serialPort.Write(msJson); serialPort.Write(msJson);
RequestPending = true;
} }
} }
msg.Cmd = Message.CMD_ZERO_CAM; msg.Cmd = Message.CMD_ZERO_CAM;
msg.Val = "0"; msg.Val = "0";
string msJson = JsonConvert.SerializeObject(msg); string msJson = JsonConvert.SerializeObject(msg);
if (serialPort.IsOpen && !RequestPending) {
if (serialPort.IsOpen) {
serialPort.Write(msJson); serialPort.Write(msJson);
RequestPending = true;
} }
} }
msg.Cmd = Message.CMD_AZIMUT_CAM; msg.Cmd = Message.CMD_AZIMUT_CAM;
msg.Val = webCamRotator.Value.ToString(); msg.Val = webCamRotator.Value.ToString();
string msJson = JsonConvert.SerializeObject(msg); string msJson = JsonConvert.SerializeObject(msg);
if (serialPort.IsOpen && !RequestPending) {
if (serialPort.IsOpen) {
serialPort.Write(msJson); serialPort.Write(msJson);
} }
} }
private void sendWebCamActualAzimutCmd() {
Message msg = new Message();
msg.Sender = Message.CMD_SENDER_PC;
msg.Cmd = Message.CMD_ACT_AZIMUT_CAM;
msg.Val = "";
string msJson = JsonConvert.SerializeObject(msg);
if (serialPort.IsOpen) {
serialPort.Write(msJson);
RequestPending = true;
}
}
private void onStatusTimerTick(object sender, EventArgs e) { private void onStatusTimerTick(object sender, EventArgs e) {
if (timerCount % 2 == 0) { if (timerCount % 2 == 0) {
sendWebCamStatusCmd(); sendWebCamStatusCmd();
} }
private void onMainFormClosing(object sender, FormClosingEventArgs e) { private void onMainFormClosing(object sender, FormClosingEventArgs e) {
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
while (RequestPending && stopwatch.ElapsedMilliseconds < 2000) {
Thread.Sleep(50);
}
if (serialPort.IsOpen) { if (serialPort.IsOpen) {
serialPort.DiscardInBuffer(); serialPort.DiscardInBuffer();
serialPort.DiscardOutBuffer(); serialPort.DiscardOutBuffer();

+ 1
- 0
Message.cs View File

public static string CMD_STATUS_CAM = "Status_Cam"; public static string CMD_STATUS_CAM = "Status_Cam";
public static string CMD_POWER_CAM = "Power_Cam"; public static string CMD_POWER_CAM = "Power_Cam";
public static string CMD_AZIMUT_CAM = "Azimut_Cam"; public static string CMD_AZIMUT_CAM = "Azimut_Cam";
public static string CMD_ACT_AZIMUT_CAM = "Actual_Azimut_Cam";
public static string CMD_ZERO_CAM = "Zero_Cam"; public static string CMD_ZERO_CAM = "Zero_Cam";
public static string CMD_VAL_ON = "On"; public static string CMD_VAL_ON = "On";
public static string CMD_VAL_OFF = "Off"; public static string CMD_VAL_OFF = "Off";

Loading…
Cancel
Save