add serial code
This commit is contained in:
parent
09f666b39c
commit
63ba2dcdfe
2 changed files with 88 additions and 7 deletions
|
@ -14,6 +14,8 @@ using System.IO;
|
|||
using System.Xml.Serialization;
|
||||
using System.Xml;
|
||||
using System.Dynamic;
|
||||
using System.IO.Ports;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace AnimeCon.Vlc.Scraper
|
||||
{
|
||||
|
@ -24,9 +26,22 @@ namespace AnimeCon.Vlc.Scraper
|
|||
private int remainingTime { get;set; }
|
||||
private string timeString { get; set; }
|
||||
|
||||
static SerialPort _serialPort;
|
||||
|
||||
public Form1()
|
||||
{
|
||||
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)
|
||||
|
@ -95,16 +110,12 @@ namespace AnimeCon.Vlc.Scraper
|
|||
Console.WriteLine($"Error: {ex.Message}");
|
||||
lblStatus.Text = "ERROR!";
|
||||
lblStatus.ForeColor = System.Drawing.Color.Red;
|
||||
btnConnect.Text = "Connect";
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void btnClock_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void tmrVlc_Tick(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
|
@ -113,13 +124,83 @@ namespace AnimeCon.Vlc.Scraper
|
|||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue