沈明明
級(jí)別: 正式會(huì)員
|
圖片:
圖片:
本人新手,SetDevice()函數(shù)不會(huì)用,圖中字體變藍(lán)說(shuō)明賦值不成功 |
---|---|
|
langui
級(jí)別: 論壇先鋒
|
牛A啊,很早以前就想玩了,可惜C51學(xué)一半就沒(méi)興趣了,能不能給個(gè)程序。407875069@qq.com |
---|---|
|
nightblueblu
道阻且長(zhǎng),窮且益堅(jiān)。
級(jí)別: 論壇先鋒
|
不知道這個(gè)控件 按道理說(shuō) 通信不應(yīng)該要寫(xiě)波特率 奇偶校驗(yàn)位 停止位嗎 感覺(jué)就像是檢測(cè)通信成功沒(méi)有 如果沒(méi)有通信程序 檢測(cè)程序肯定是通信失敗的 |
|
---|---|---|
|
fengyyy
級(jí)別: 家園常客
|
自己做了個(gè)小程序玩的,代碼寫(xiě)的不嚴(yán)謹(jǐn),沒(méi)改控件名。我沒(méi)用這個(gè)控件,我是直接寫(xiě)協(xié)議的。FX3U+232BD+4AD。實(shí)時(shí)讀取采集的溫度,存入SQL數(shù)據(jù)庫(kù)中。 for (int i=0; i<99;i++ ) { comboBox1.Items.Add("COM"+i.ToString ()); } foreach (string com in comboBox1.Items ) { try { serialPort1.PortName = com; serialPort1.Open(); if(serialPort1 .IsOpen ==true) { break; } } catch { continue; } } timer1.Enabled = true; comboBox1.SelectedIndex = 0; private void timer2_Tick(object sender, EventArgs e)//D0 讀取 { try { textBox1.Text = W_Reveive(serialPort1.ReadExisting()); timer3.Enabled = true; timer2.Enabled = false; } catch(Exception ex) { timer1.Enabled = false; timer2.Enabled = false; timer3.Enabled = false; timer3.Enabled = false; timer4.Enabled = false; timer5.Enabled = false; timer6.Enabled = false; MessageBox.Show(ex.Message.ToString()); this.Close(); } private string W_Reveive(string text)//字讀取 { try { if (text.Length == 12) { string a = text.Substring(1, 4); string b = text.Substring(5, 4); if (a == "00FF" && b != "0000") { int c = Convert.ToInt32(b, 16); return c.ToString(); } else { return null; } } else { return null; } } catch { return""; } } private void timer9_Tick(object sender, EventArgs e)//讀取表內(nèi)容 { string conn = "server=.;database=wenducaiji;integrated Security=True;"; string Sql = "select time as '時(shí)間',temperature as '溫度' from temperature order by time desc,temperature desc;"; using(SqlConnection con =new SqlConnection(conn)) { con.Open(); DataSet dataset=new DataSet (); SqlDataAdapter dataadapter = new SqlDataAdapter(Sql,con); dataadapter.Fill(dataset); dataGridView1.DataSource = dataset.Tables[0]; dataGridView1.Columns["時(shí)間"].DefaultCellStyle.Format = "yyyy/MM/dd HH:mm:ss"; dataadapter.Dispose(); } button6.Visible= true; } |
---|---|
|