资源简介
串口通信相关,帮助初学者尽快了解串口和网口通信!!!
代码片段和文件信息
using System;
using System.Timers;
using System.Globalization;
using System.IO;
using System.IO.Ports;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Threading;
namespace HaierDataCollecing
{
public partial class Form1 : Form
{
byte[] sendBytes = new byte[8];
byte[] clearBytes = new byte[10];
byte slaveAddress = 2;
byte[] regAddress = new byte[2];
byte[] CRC = new byte[2];
float[] para = new float[8];
byte[] tmp = new byte[4];
byte functionCode;
byte paraCount;
string Modeler;
System.Timers.Timer timer = new System.Timers.Timer();
SqlConnection conn = new SqlConnection();
SqlCommand cmd = new SqlCommand();
string sql = ““;
public Form1()
{
InitializeComponent();
timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
}
private void Form1_Load(object sender EventArgs e)
{
string[] ports = SerialPort.GetPortNames();
if (ports.Length == 0)
{
radLabelElement1.Text = “ 没有找到任何串口设备!“;
radButton1.Enabled = false;
}
else
{
radDropDownList1.DataSource = ports;
radDropDownList1.SelectedIndex = ports.Length - 1;
radLabelElement1.Text = “ Get ready to read PLC“;
}
radDropDownList2.SelectedIndex = 2;
radDropDownList3.SelectedIndex = 2;
radDropDownList4.SelectedIndex = 3;
radDropDownList5.SelectedIndex = 0;
radTextBox2.Text = “0000“;
radDropDownList6.DataSource = new int[] { 1 2 3 4 5 6 7 8 9 10 };
radDropDownList6.SelectedIndex = 8;
radDropDownList7.DataSource = new int[] { 100 200 300 400 500 800 1000 1500 2000 };
radDropDownList7.SelectedIndex = 6;
radTextBox1.Text = “d:\\PLCData\\PLCData.mdf“;
radRichTextBox1.Text = ““;
//byte[] c = new byte[] { 2 6 0 0 0 1 0 1 };
//CRC16(c ref CRC);
}
void timer_Elapsed(object sender ElapsedEventArgs e)
{
PollFunction();
}
private void PollFunction()
{
regAddress[1] = (Byte)int.Parse(radTextBox2.Text.Substring(0 2) Numberstyles.AllowHexSpecifier);
regAddress[0] = (Byte)int.Parse(radTextBox2.Text.Substring(2 2) Numberstyles.AllowHexSpecifier);
paraCount = Convert.ToByte(radDropDownList6.SelectedItem.ToString());
functionCode = 3;
try
{
DataTransfer();
}
catch (Exception e)
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 20992 2015-05-22 11:48 DataCollecing\HaierDataCollecing\bin\Debug\app.publish\Application Files\HaierDataCollecing_1_0_0_0\HaierDataCollecing.exe.deploy
文件 7942 2015-05-22 11:48 DataCollecing\HaierDataCollecing\bin\Debug\app.publish\Application Files\HaierDataCollecing_1_0_0_0\HaierDataCollecing.exe.manifest
文件 5639 2015-05-22 11:48 DataCollecing\HaierDataCollecing\bin\Debug\app.publish\HaierDataCollecing.application
文件 428952 2015-05-22 11:48 DataCollecing\HaierDataCollecing\bin\Debug\app.publish\setup.exe
文件 297472 2015-05-27 15:05 DataCollecing\HaierDataCollecing\bin\Debug\HaierDataCollecing.exe
文件 38400 2015-05-27 15:03 DataCollecing\HaierDataCollecing\bin\Debug\HaierDataCollecing.pdb
文件 11600 2015-05-27 14:56 DataCollecing\HaierDataCollecing\bin\Debug\HaierDataCollecing.vshost.exe
文件 490 2014-07-09 19:40 DataCollecing\HaierDataCollecing\bin\Debug\HaierDataCollecing.vshost.exe.manifest
文件 13552 2015-05-27 15:03 DataCollecing\HaierDataCollecing\Form1.cs
文件 25991 2015-05-27 15:03 DataCollecing\HaierDataCollecing\Form1.Designer.cs
文件 211430 2015-05-27 15:03 DataCollecing\HaierDataCollecing\Form1.resx
文件 4428 2015-05-25 13:39 DataCollecing\HaierDataCollecing\HaierDataCollecing.csproj
文件 452 2015-05-22 12:04 DataCollecing\HaierDataCollecing\HaierDataCollecing.csproj.user
文件 1652 2015-05-22 11:47 DataCollecing\HaierDataCollecing\HaierDataCollecing_TemporaryKey.pfx
文件 32861 2015-05-26 08:42 DataCollecing\HaierDataCollecing\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
文件 6978 2015-05-27 15:04 DataCollecing\HaierDataCollecing\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
文件 606 2015-05-22 13:53 DataCollecing\HaierDataCollecing\obj\x86\Debug\GenerateResource.read.1.tlog
文件 1498 2015-05-22 13:53 DataCollecing\HaierDataCollecing\obj\x86\Debug\GenerateResource.write.1.tlog
文件 5203 2015-05-27 15:03 DataCollecing\HaierDataCollecing\obj\x86\Debug\HaierDataCollecing.csproj.FileListAbsolute.txt
文件 1015 2015-05-27 15:03 DataCollecing\HaierDataCollecing\obj\x86\Debug\HaierDataCollecing.csproj.GenerateResource.Cache
文件 35453 2015-05-26 10:55 DataCollecing\HaierDataCollecing\obj\x86\Debug\HaierDataCollecing.csprojResolveAssemblyReference.cache
文件 297472 2015-05-27 15:05 DataCollecing\HaierDataCollecing\obj\x86\Debug\HaierDataCollecing.exe
文件 137172 2015-05-27 15:03 DataCollecing\HaierDataCollecing\obj\x86\Debug\HaierDataCollecing.Form1.resources
文件 38400 2015-05-27 15:03 DataCollecing\HaierDataCollecing\obj\x86\Debug\HaierDataCollecing.pdb
文件 137164 2015-05-25 23:08 DataCollecing\HaierDataCollecing\obj\x86\Debug\HaierDataCollecing.Properties.Resources.resources
文件 32480 2015-05-22 04:18 DataCollecing\HaierDataCollecing\obj\x86\Debug\ResolveAssemblyReference.cache
文件 4608 2015-05-25 13:39 DataCollecing\HaierDataCollecing\obj\x86\Debug\TempPE\Properties.Resources.Designer.cs.dll
文件 510 2015-05-18 16:17 DataCollecing\HaierDataCollecing\Program.cs
文件 1448 2015-05-18 16:17 DataCollecing\HaierDataCollecing\Properties\AssemblyInfo.cs
文件 3250 2015-05-25 13:39 DataCollecing\HaierDataCollecing\Properties\Resources.Designer.cs
............此处省略32个文件信息
- 上一篇:银行排队系统
- 下一篇:STM8S207R8(DS18B20)源代码
评论
共有 条评论