C# Programming
05-19-2010, 06:17 AM
My Project:
http://rapidshare.com/files/388966495/bandwidth_meter.rar.html[^ (http://rapidshare.com/files/388966495/bandwidth_meter.rar.html)]
This program is working but my LCD doesnt show anything. By the way LCD is working a normal condition. I am waiting for your advice. Thank you...
public partial class MainForm : Form
{
/// /// Timer Update (every 1 sec)
/// private const double timerUpdate = 1000;
/// /// Interface Storage
/// private NetworkInterface[] nicArr;
/// /// Main Timer Object
/// (we could use something more efficient such
/// as interop calls to HighPerformanceTimers)
/// private System.Windows.Forms.Timer timer;
/// /// Constructor
///
public MainForm()
{
InitializeComponent();
InitializeNetworkInterface();
InitializeTimer();
}
public int data = 888;
public int control = 890;
/// /// Initialize all network interfaces on this computer
/// private void InitializeNetworkInterface()
{
// Grab all local interfaces to this computer
nicArr = NetworkInterface.GetAllNetworkInterfaces();
// Add each interface name to the combo box
for (int i = 0; i < nicArr.Length; i++)
cmbInterface.Items.Add(nicArr[i].Name);
// Change the initial selection to the first interface
cmbInterface.SelectedIndex = 0;
}
/// /// Initialize the Timer
/// private void InitializeTimer()
{
timer = new System.Windows.Forms.Timer();
timer.Interval = (int)timerUpdate;
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
}
/// /// Update GUI components for the network interfaces
///
private void UpdateNetworkInterface()
{
string title, duration;
// Grab NetworkInterface object that describes the current interface
NetworkInterface nic = nicArr[cmbInterface.SelectedIndex];
// Grab the stats for that interface
IPv4InterfaceStatistics interfaceStats = nic.GetIPv4Statistics();
int bytesSentSpeed = (int)(interfaceStats.BytesSent - double.Parse(lblBytesSent.Text)) / 1024;
int bytesReceivedSpeed = (int)(interfaceStats.BytesReceived - double.Parse(lblBytesReceived.Text)) / 1024;
// Update the labels
lblSpeed.Text = nic.Speed.ToString();
lblInterfaceType.Text = nic.NetworkInterfaceType.ToString();
lblSpeed.Text = nic.Speed.ToString();
lblBytesReceived.Text = interfaceStats.BytesReceived.ToString();
lblBytesSent.Text = interfaceStats.BytesSent.ToString();
lblUpload.Text = bytesSentSpeed.ToString() + " KB/s";
lblDownload.Text = bytesReceivedSpeed.ToString() + " KB/s";
title = lblDownload.Text;
duration = lblUpload.Text;
writetoLCD(title, duration);
}
/// /// The Timer event for each Tick (second) to update the UI
/// /// /// void timer_Tick(object sender, EventArgs e)
{
UpdateNetworkInterface();
}private void writetoLCD(string title, string duration)
{
PortAccess.Output(data, 1);
PortAccess.Output(control, 8); Thread.Sleep(1);
PortAccess.Output(control, 9); Thread.Sleep(1);
int a;
char[] line1_ch_buffer, line2_ch_buffer;
string line1_st_buffer, line2_st_buffer;
line1_st_buffer = title;
line1_ch_buffer = line1_st_buffer.ToCharArray();
line2_st_buffer = duration;
line2_ch_buffer = line2_st_buffer.ToCharArray();
HangiSatir(1, 1);
for (a = 0; a < line1_ch_buffer.Length; a++)
{
PortAccess.Output(control, 4); Thread.Sleep(1);
PortAccess.Output(data, (int)line1_ch_buffer[a]);
PortAccess.Output(control, 5); Thread.Sleep(1);
}
HangiSatir(2, line1_ch_buffer.Length);
for (a = 0; a < line2_ch_buffer.Length; a++)
{
PortAccess.Output(control, 5); Thread.Sleep(1);
PortAccess.Output(control, 4); Thread.Sleep(1);
PortAccess.Output(data, (int)line2_ch_buffer[a]);
PortAccess.Output(control, 5); Thread.Sleep(1);
}
}
private void HangiSatir(int line, int column)
{
PortAccess.Output(control, 8);
if (line == 1)
PortAccess.Output(data, 127 + column);
if (line == 2)
{
int sayi = 39 - column;
for (int i = 0; i
http://rapidshare.com/files/388966495/bandwidth_meter.rar.html[^ (http://rapidshare.com/files/388966495/bandwidth_meter.rar.html)]
This program is working but my LCD doesnt show anything. By the way LCD is working a normal condition. I am waiting for your advice. Thank you...
public partial class MainForm : Form
{
/// /// Timer Update (every 1 sec)
/// private const double timerUpdate = 1000;
/// /// Interface Storage
/// private NetworkInterface[] nicArr;
/// /// Main Timer Object
/// (we could use something more efficient such
/// as interop calls to HighPerformanceTimers)
/// private System.Windows.Forms.Timer timer;
/// /// Constructor
///
public MainForm()
{
InitializeComponent();
InitializeNetworkInterface();
InitializeTimer();
}
public int data = 888;
public int control = 890;
/// /// Initialize all network interfaces on this computer
/// private void InitializeNetworkInterface()
{
// Grab all local interfaces to this computer
nicArr = NetworkInterface.GetAllNetworkInterfaces();
// Add each interface name to the combo box
for (int i = 0; i < nicArr.Length; i++)
cmbInterface.Items.Add(nicArr[i].Name);
// Change the initial selection to the first interface
cmbInterface.SelectedIndex = 0;
}
/// /// Initialize the Timer
/// private void InitializeTimer()
{
timer = new System.Windows.Forms.Timer();
timer.Interval = (int)timerUpdate;
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
}
/// /// Update GUI components for the network interfaces
///
private void UpdateNetworkInterface()
{
string title, duration;
// Grab NetworkInterface object that describes the current interface
NetworkInterface nic = nicArr[cmbInterface.SelectedIndex];
// Grab the stats for that interface
IPv4InterfaceStatistics interfaceStats = nic.GetIPv4Statistics();
int bytesSentSpeed = (int)(interfaceStats.BytesSent - double.Parse(lblBytesSent.Text)) / 1024;
int bytesReceivedSpeed = (int)(interfaceStats.BytesReceived - double.Parse(lblBytesReceived.Text)) / 1024;
// Update the labels
lblSpeed.Text = nic.Speed.ToString();
lblInterfaceType.Text = nic.NetworkInterfaceType.ToString();
lblSpeed.Text = nic.Speed.ToString();
lblBytesReceived.Text = interfaceStats.BytesReceived.ToString();
lblBytesSent.Text = interfaceStats.BytesSent.ToString();
lblUpload.Text = bytesSentSpeed.ToString() + " KB/s";
lblDownload.Text = bytesReceivedSpeed.ToString() + " KB/s";
title = lblDownload.Text;
duration = lblUpload.Text;
writetoLCD(title, duration);
}
/// /// The Timer event for each Tick (second) to update the UI
/// /// /// void timer_Tick(object sender, EventArgs e)
{
UpdateNetworkInterface();
}private void writetoLCD(string title, string duration)
{
PortAccess.Output(data, 1);
PortAccess.Output(control, 8); Thread.Sleep(1);
PortAccess.Output(control, 9); Thread.Sleep(1);
int a;
char[] line1_ch_buffer, line2_ch_buffer;
string line1_st_buffer, line2_st_buffer;
line1_st_buffer = title;
line1_ch_buffer = line1_st_buffer.ToCharArray();
line2_st_buffer = duration;
line2_ch_buffer = line2_st_buffer.ToCharArray();
HangiSatir(1, 1);
for (a = 0; a < line1_ch_buffer.Length; a++)
{
PortAccess.Output(control, 4); Thread.Sleep(1);
PortAccess.Output(data, (int)line1_ch_buffer[a]);
PortAccess.Output(control, 5); Thread.Sleep(1);
}
HangiSatir(2, line1_ch_buffer.Length);
for (a = 0; a < line2_ch_buffer.Length; a++)
{
PortAccess.Output(control, 5); Thread.Sleep(1);
PortAccess.Output(control, 4); Thread.Sleep(1);
PortAccess.Output(data, (int)line2_ch_buffer[a]);
PortAccess.Output(control, 5); Thread.Sleep(1);
}
}
private void HangiSatir(int line, int column)
{
PortAccess.Output(control, 8);
if (line == 1)
PortAccess.Output(data, 127 + column);
if (line == 2)
{
int sayi = 39 - column;
for (int i = 0; i