Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
namespace Bootloader
{
public class SerialClassThread
{
public System.IO.Ports.SerialPort serialPort1;
private SerialClassThread serial_thread = new SerialClassThread();
private Thread Serial_Thread;
private string _Serial_tx_send_string;
private bool _SerialStopRequest = true;
private bool _SerialTranmitRequest = false;
public bool StopRequest
{
set { serial_thread._SerialStopRequest = value; }
}
public bool TransmitRequest
{
set { serial_thread._SerialTranmitRequest = value; }
}
public string SerialStringRequest
{
set { serial_thread._Serial_tx_send_string = value; }
}
public void StartThread(string to_open_comport,int to_open_baudrate)
{
if ( Serial_Thread == null || ( Serial_Thread != null && !Serial_Thread.IsAlive ) )
{
serialPort1 = new SerialPort(to_open_comport, 9600, Parity.None, 8, StopBits.One);
serialPort1.Open();
serial_thread._SerialStopRequest = false;
serial_thread._SerialTranmitRequest = false;
Serial_Thread = new Thread( new ThreadStart(SerialLoop) );
Serial_Thread.Start();
while (!Serial_Thread.IsAlive);
}
}
protected void SerialLoop()
{
while( !serial_thread._SerialStopRequest )
{
if(serial_thread._SerialTranmitRequest)
{
serialPort1.Write(serial_thread._Serial_tx_send_string);
serial_thread._SerialTranmitRequest = false;
}
Thread.Sleep(10);
}
serialPort1.Close();
}
}
}
namespace Bootloader
{
public class TimerClassThread
{
public SerialClassThread timer_serial_rx_tx_thd = null;
private TimerClassThread timer_thread = new TimerClassThread();
private Thread Timer_Thread;
private bool _TimerStopRequest = true;
public bool TimerThreadStopRequest
{
set { _TimerStopRequest = value; }
}
public void StartThread()
{
if ( Timer_Thread == null || ( Timer_Thread != null && !Timer_Thread.IsAlive ) )
{
_TimerStopRequest = false;
Timer_Thread = new Thread( new ThreadStart(TimerLoop) );
Timer_Thread.Start();
while (!Timer_Thread.IsAlive);
}
}
private static Object lockvar = ""; // Lock-Variable
protected void TimerLoop()
{
while( !_TimerStopRequest )
{
if(timer_serial_rx_tx_thd != null)
{
lock(lockvar)
{
timer_serial_rx_tx_thd.SerialStringRequest = "Hallo\r";
timer_serial_rx_tx_thd.TransmitRequest = true;
}
}
else
{
if(timer_serial_rx_tx_thd == null)
{
timer_serial_rx_tx_thd.StartThread("COM6",9600);
}
}
Thread.Sleep(500);
}
}
}
}
namespace Bootloader
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class MainForm : Form
{
public SerialClassThread main_serial_rx_tx_thd = null;
public TimerClassThread main_timer_thd = null;
public MainForm()
{
InitializeComponent();
}
void Button1Click(object sender, EventArgs e)
{
main_serial_rx_tx_thd.StartThread("COM6",9600);
main_timer_thd.StartThread();
}
}
}
namespace Bootloader
{
public class SerialClassThread
{
public System.IO.Ports.SerialPort serialPort1;
private Thread Serial_Thread;
private string _Serial_tx_send_string;
private bool _SerialStopRequest = true;
private bool _SerialTranmitRequest = false;
public bool StopRequest
{
set { _SerialStopRequest = value; }
}
public bool TransmitRequest
{
set { _SerialTranmitRequest = value; }
}
public string SerialStringRequest
{
set { _Serial_tx_send_string = value; }
}
public void StartThread(string to_open_comport,int to_open_baudrate)
{
if ( Serial_Thread == null || ( Serial_Thread != null && !Serial_Thread.IsAlive ) )
{
serialPort1 = new SerialPort(to_open_comport, 9600, Parity.None, 8, StopBits.One);
serialPort1.Open();
_SerialStopRequest = false;
_SerialTranmitRequest = false;
Serial_Thread = new Thread( new ThreadStart(SerialLoop) );
Serial_Thread.Start();
while (!Serial_Thread.IsAlive);
}
}
protected void SerialLoop()
{
while( !_SerialStopRequest )
{
if(_SerialTranmitRequest)
{
serialPort1.Write(_Serial_tx_send_string);
_SerialTranmitRequest = false;
}
Thread.Sleep(10);
}
serialPort1.Close();
}
}
}
///////////////////////////////////////////////////////////////////////////////
namespace Bootloader
{
public class TimerClassThread
{
public SerialClassThread timer_serial_rx_tx_thd = null;
private Thread Timer_Thread;
private bool _TimerStopRequest = true;
private static Object lockvar = new Object(); // Lock-Variable
public bool TimerThreadStopRequest
{
set { _TimerStopRequest = value; }
}
public void StartThread(SerialClassThread main_serial_rx_tx_thd)
{
timer_serial_rx_tx_thd = main_serial_rx_tx_thd;
if ( Timer_Thread == null || ( Timer_Thread != null && !Timer_Thread.IsAlive ) )
{
_TimerStopRequest = false;
Timer_Thread = new Thread( new ThreadStart(TimerLoop) );
Timer_Thread.Start();
while (!Timer_Thread.IsAlive);
}
}
protected void TimerLoop()
{
while( !_TimerStopRequest )
{
if(timer_serial_rx_tx_thd != null)
{
lock(lockvar)
{
timer_serial_rx_tx_thd.SerialStringRequest = "Hallo\r";
timer_serial_rx_tx_thd.TransmitRequest = true;
}
}
Thread.Sleep(500);
}
}
}
}
///////////////////////////////////////////////////////////////////////////////
namespace Bootloader
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class MainForm : Form
{
public SerialClassThread main_serial_rx_tx_thd = null;
public TimerClassThread main_timer_thd = null;
public MainForm()
{
InitializeComponent();
}
void Button1Click(object sender, EventArgs e)
{
main_serial_rx_tx_thd.StartThread("COM6",9600);
main_timer_thd.StartThread(main_serial_rx_tx_thd);
}
}
}