using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Text.RegularExpressions;
using System.Globalization;
using System.IO.Ports;
namespace bol
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
byte[] byData;
int k = 0;
private void Form1_Shown(object sender, EventArgs e)
{
string[] ports = SerialPort.GetPortNames();
comboBox1.Items.AddRange(SerialPort.GetPortNames());
if (comboBox1.Items.Count > -1)
{
comboBox1.SelectedIndex = 0;
}
}
private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
if (serialPort1.IsOpen)
{
if (byData.Length - 2000 > k)
{
serialPort1.Write(byData, k, 2000);
k += 2000;
}
}
}
private void button2_Click(object sender, EventArgs e)
{
serialPort1.Close();
button1.Enabled = true;
try
{
serialPort1.BaudRate = Convert.ToInt32(textBox1.Text);
}
catch
{
MessageBox.Show("!!!!!!"); return;
}
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string fileNam = openFileDialog1.FileName;
FileStream fs = new FileStream(fileNam, FileMode.OpenOrCreate, FileAccess.Read);
int len = Convert.ToInt32(fs.Length);
byData = new byte[len];
try
{
fs.Read(byData, 44, len - 44 - 1);
fs.Dispose();
}
catch (IOException err)
{
MessageBox.Show(err.Message); return;
}
serialPort1.Open();
k = 0;
if (byData.Length - 2000 > k)
{
serialPort1.Write(byData, k, 2000);
k += 2000;
}
}
}
private void comboBox1_TextChanged(object sender, EventArgs e)
{
serialPort1.PortName = comboBox1.Text;
}
private void button3_Click(object sender, EventArgs e)
{
k = 0;
}
private void button1_Click_1(object sender, EventArgs e)
{
if (serialPort1.IsOpen)
{
serialPort1.Close();
}
else serialPort1.Open();
}
}
}