add serial code
This commit is contained in:
parent
09f666b39c
commit
63ba2dcdfe
2 changed files with 88 additions and 7 deletions
2
AnimeCon.Vlc.Scraper/Form1.Designer.cs
generated
2
AnimeCon.Vlc.Scraper/Form1.Designer.cs
generated
|
@ -170,7 +170,7 @@
|
||||||
this.btnClock.Name = "btnClock";
|
this.btnClock.Name = "btnClock";
|
||||||
this.btnClock.Size = new System.Drawing.Size(75, 23);
|
this.btnClock.Size = new System.Drawing.Size(75, 23);
|
||||||
this.btnClock.TabIndex = 12;
|
this.btnClock.TabIndex = 12;
|
||||||
this.btnClock.Text = "Send";
|
this.btnClock.Text = "Start";
|
||||||
this.btnClock.UseVisualStyleBackColor = true;
|
this.btnClock.UseVisualStyleBackColor = true;
|
||||||
this.btnClock.Click += new System.EventHandler(this.btnClock_Click);
|
this.btnClock.Click += new System.EventHandler(this.btnClock_Click);
|
||||||
//
|
//
|
||||||
|
|
|
@ -14,6 +14,8 @@ using System.IO;
|
||||||
using System.Xml.Serialization;
|
using System.Xml.Serialization;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using System.Dynamic;
|
using System.Dynamic;
|
||||||
|
using System.IO.Ports;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
namespace AnimeCon.Vlc.Scraper
|
namespace AnimeCon.Vlc.Scraper
|
||||||
{
|
{
|
||||||
|
@ -24,9 +26,22 @@ namespace AnimeCon.Vlc.Scraper
|
||||||
private int remainingTime { get;set; }
|
private int remainingTime { get;set; }
|
||||||
private string timeString { get; set; }
|
private string timeString { get; set; }
|
||||||
|
|
||||||
|
static SerialPort _serialPort;
|
||||||
|
|
||||||
public Form1()
|
public Form1()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
_serialPort = new SerialPort();
|
||||||
|
string[] portNames = SerialPort.GetPortNames();
|
||||||
|
|
||||||
|
// Add the port names to the ComboBox
|
||||||
|
cbCom.Items.AddRange(portNames);
|
||||||
|
|
||||||
|
// Select the first port if available
|
||||||
|
if (cbCom.Items.Count > 0)
|
||||||
|
{
|
||||||
|
cbCom.SelectedIndex = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void btnConnect_Click(object sender, EventArgs e)
|
private void btnConnect_Click(object sender, EventArgs e)
|
||||||
|
@ -95,16 +110,12 @@ namespace AnimeCon.Vlc.Scraper
|
||||||
Console.WriteLine($"Error: {ex.Message}");
|
Console.WriteLine($"Error: {ex.Message}");
|
||||||
lblStatus.Text = "ERROR!";
|
lblStatus.Text = "ERROR!";
|
||||||
lblStatus.ForeColor = System.Drawing.Color.Red;
|
lblStatus.ForeColor = System.Drawing.Color.Red;
|
||||||
|
btnConnect.Text = "Connect";
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void btnClock_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void tmrVlc_Tick(object sender, EventArgs e)
|
private void tmrVlc_Tick(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -113,13 +124,83 @@ namespace AnimeCon.Vlc.Scraper
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
btnConnect.Text = "Connect";
|
||||||
|
tmrVlc.Stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DoSendDataSerial()
|
||||||
|
{
|
||||||
|
|
||||||
|
// Allow the user to set the appropriate properties.
|
||||||
|
_serialPort.PortName = cbCom.Items[cbCom.SelectedIndex].ToString();
|
||||||
|
_serialPort.BaudRate = 9600;
|
||||||
|
_serialPort.Parity = Parity.None;
|
||||||
|
_serialPort.DataBits = 8;
|
||||||
|
_serialPort.StopBits = StopBits.One;
|
||||||
|
_serialPort.Handshake = Handshake.None;
|
||||||
|
|
||||||
|
// Set the read/write timeouts
|
||||||
|
_serialPort.ReadTimeout = 500;
|
||||||
|
_serialPort.WriteTimeout = 500;
|
||||||
|
|
||||||
|
_serialPort.Open();
|
||||||
|
_serialPort.WriteLine(timeString);
|
||||||
|
_serialPort.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void btnClock_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (lblRunning.Text != "Off")
|
||||||
|
{
|
||||||
|
lblRunning.Text = "Off";
|
||||||
|
lblStatus.ForeColor = System.Drawing.Color.Red;
|
||||||
|
btnClock.Text = "Start";
|
||||||
|
tmrClock.Stop();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
DoSendDataSerial();
|
||||||
|
tmrClock.Start();
|
||||||
|
btnClock.Text = "Stop";
|
||||||
|
lblStatus.Text = "On";
|
||||||
|
lblStatus.ForeColor = System.Drawing.Color.Green;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
tmrClock.Stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
DoSendDataSerial();
|
||||||
|
tmrVlc.Start();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
lblRunning.Text = "ERROR!";
|
||||||
|
lblRunning.ForeColor = System.Drawing.Color.Red;
|
||||||
|
btnClock.Text = "Start";
|
||||||
tmrVlc.Stop();
|
tmrVlc.Stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tmrClock_Tick(object sender, EventArgs e)
|
private void tmrClock_Tick(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
DoSendDataSerial();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
lblRunning.Text = "ERROR!";
|
||||||
|
lblRunning.ForeColor = System.Drawing.Color.Red;
|
||||||
|
btnClock.Text = "Start";
|
||||||
|
tmrVlc.Stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static dynamic ParseXml(string xmlContent)
|
static dynamic ParseXml(string xmlContent)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue