112 lines
4.9 KiB
Plaintext
112 lines
4.9 KiB
Plaintext
//if (!sp1.IsOpen)
|
||
//{
|
||
// sp1.DiscardInBuffer();//清空SerialPort控件的Buffer
|
||
// return;
|
||
//}
|
||
|
||
//ilen = sp1.BytesToRead;
|
||
//if (ilen > 0)
|
||
//{
|
||
// bytes = new byte[ilen];
|
||
// sp1.Read(bytes, 0, ilen);
|
||
// //tilen = ilen;
|
||
|
||
// //界面显示
|
||
// string receiveString = "";
|
||
|
||
// if (radioButton1.Checked == true)
|
||
// {
|
||
// receiveString = byteToHexStr(bytes) + System.Environment.NewLine;
|
||
// }
|
||
|
||
// if (radioButton2.Checked == true)
|
||
// {
|
||
// receiveString = Encoding.Default.GetString(bytes) + System.Environment.NewLine;
|
||
// }
|
||
// txtReceive.AppendText("接收:" + receiveString);
|
||
|
||
// sp1.DiscardInBuffer();//清空SerialPort控件的Buffer
|
||
|
||
|
||
|
||
//}
|
||
|
||
////接收7e指令
|
||
////DealCmd(bytes);
|
||
|
||
//int i = 0;
|
||
//int num = 0;
|
||
//int flag = 1;
|
||
////for (i = 0; i < bytes.Length; i++)
|
||
////{
|
||
//// if (bytes[i] == 0x05)
|
||
//// {
|
||
//// num = i;
|
||
//// flag = 1;
|
||
//// break;
|
||
//// }
|
||
////}
|
||
//if (flag == 1)
|
||
//{
|
||
// byte[] bytes2 = new byte[bytes.Length];
|
||
|
||
// for (i = 0; i < (bytes.Length - num); i++)
|
||
// {
|
||
// bytes2[i] = bytes[i + num];
|
||
// }
|
||
|
||
// //界面显示
|
||
// string receiveString = "";
|
||
|
||
// if(radioButton1.Checked == true)
|
||
// {
|
||
// receiveString = byteToHexStr(bytes2) + System.Environment.NewLine;
|
||
// }
|
||
|
||
// if(radioButton2.Checked == true)
|
||
// {
|
||
// receiveString = Encoding.Default.GetString(bytes2) + System.Environment.NewLine;
|
||
// }
|
||
// txtReceive.AppendText("接收:" + receiveString);
|
||
|
||
// try
|
||
// {
|
||
// //数据分析
|
||
// if (bytes2[7] == 0xf1 && bytes2[8] == 0x07)
|
||
// {
|
||
// //////save
|
||
// //{
|
||
// // OleDbConnection conn;
|
||
// // conn = new OleDbConnection(@"Provider=Microsoft.Jet.OleDb.4.0; Data Source=" + Directory.GetCurrentDirectory() + "\\rqdata.mdb");
|
||
// // conn.Open();
|
||
|
||
// // OleDbCommand cmd = conn.CreateCommand();
|
||
// // cmd.CommandText = @"INSERT INTO YunXin_ProductSort([Device_ID], [P1], [P2], [P3], [F], [AddTimers])VALUES('" + "Device_ID" + "', '";
|
||
// // cmd.CommandText += textBox3.Text + "', '" + textBox5.Text + "', '";
|
||
// // cmd.CommandText += textBox7.Text + "', '";
|
||
// // cmd.CommandText += textBox11.Text + "', '";
|
||
// // cmd.CommandText += DateTime.Now.ToString("G") + "')";
|
||
// // cmd.ExecuteNonQuery();
|
||
// // conn.Close();
|
||
// //}
|
||
// }
|
||
// }
|
||
// catch
|
||
// {
|
||
|
||
|
||
// }
|
||
//}
|
||
|
||
//////界面显示
|
||
////string receivStr = System.Text.Encoding.GetEncoding("GB18030").GetString(bytes); //xx="中文";
|
||
|
||
////txtReceive.AppendText(receivStr);
|
||
|
||
////txtReceive.SelectionStart = txtReceive.TextLength;
|
||
|
||
////txtReceive.SelectionStart = txtReceive.TextLength + 10;//设置选中文字的开始位置为文本框的文字的长度,如果超过了文本长度,则默认为文本的最后。
|
||
////txtReceive.SelectionLength = 0;//设置被选中文字的长度为0(将光标移动到文字最后)
|
||
////txtReceive.ScrollToCaret();//滚动条移动到光标位置
|
||
|
||
//sp1.DiscardInBuffer();//清空SerialPort控件的Buffer |