串口调适

using System;
using System.Windows.Forms;
using System.IO.Ports;
using System.Drawing;
using System.IO;
using System.Text;
using System.Collections;
using System.Threading;
using System.Runtime.InteropServices;

namespace SerialPortAssistant
{
public partial class FrmMain : Form
{

class TextAndValue
{
private string _RealValue = "";
private string _DisplayText = "";
public string DisplayText
{
get
{
return _DisplayText;
}
}
public string RealValue
{
get
{
return _RealValue;
}
}
public TextAndValue(string ShowText, string RealVal)
{
_DisplayText = ShowText;
_RealValue = RealVal;
}
public override string ToString()
{
return _RealValue.ToString();
}
}
public FrmMain()
{
InitializeComponent();
}

public string msg = "";
public ArrayList commmand = new ArrayList();

private void FrmMain_Load(object sender, EventArgs e)
{
#region 加载配置
LoadCansu();
#endregion
}

#region 加载参数
//加载参数
public void LoadCansu()
{
//如果有配置 则读取配置文件
if (File.Exists(Application.StartupPath + @"\SerConfig.wjs"))
{
using (StreamReader sr = new StreamReader(Application.StartupPath + @"\SerConfig.wjs", Encoding.UTF8))
{
comboBox1.SelectedItem = sr.ReadLine();
comboBox2.SelectedItem = sr.ReadLine();
comboBox3.SelectedItem = sr.ReadLine();
comboBox4.SelectedItem = sr.ReadLine();
comboBox5.SelectedItem = sr.ReadLine();
}
}
else
{
comboBox1.SelectedIndex = 2;
comboBox2.SelectedIndex = 6;
comboBox3.SelectedIndex = 0;
comboBox4.SelectedIndex = 0;
comboBox5.SelectedIndex = 0;
}
FrmMain.CheckForIllegalCrossThreadCalls = false;

txt_csdy.Text = iniHelpers.ContentValue("f初始电压");
txt_jsdy.Text = iniHelpers.ContentValue("f结束电压");
txt_jxsj.Text = iniHelpers.ContentValue("f静息时间");
txt_jxdy.Text = iniHelpers.ContentValue("f静息电压");
txt_fjsj.Text = iniHelpers.ContentValue("f富集时间");
txt_fjdy.Text = iniHelpers.ContentValue("f富集电压");
txt_mczq.Text = iniHelpers.ContentValue("f脉冲周期");
txt_cyjg.Text = iniHelpers.ContentValue("f采样间隔");
txt_mckd.Text = iniHelpers.ContentValue("f脉冲宽度");
txt_bjdy.Text = iniHelpers.ContentValue("f步进电压");
txt_mcfd.Text = iniHelpers.ContentValue("f脉冲幅度");

text_csdy.Text = iniHelpers.ContentValue("g初始电压");
text_jsdy.Text = iniHelpers.ContentValue("g结束电压");
text_jxsj.Text = iniHelpers.ContentValue("g静息时间");
text_bjsd.Text = iniHelpers.ContentValue("g步进速度");
text_dgsj.Text = iniHelpers.ContentValue("g镀汞时间");
text_cybjdy.Text = iniHelpers.ContentValue("g采样步进电压");
text_jxsj.Text = iniHelpers.ContentValue("g静息时间");
text_jxdw.Text = iniHelpers.ContentValue("g静息点位");

//连通阀加载
ArrayList al = new ArrayList();
al.Add(new TextAndValue("系统1", iniHelpers.ContentValue("系统1")));
al.Add(new TextAndValue("系统2", iniHelpers.ContentValue("系统2")));
al.Add(new TextAndValue("系统3", iniHelpers.ContentValue("系统3")));
cmb_yq.DataSource = al;
cmb_yq.DisplayMember = "DisplayText";
cmb_yq.ValueMember = "RealValue";

}
#endregion

//打开串口
private void button1_Click(object sender, EventArgs e)
{
if (button1.Text == "打开串口")
{
//打开串口
try
{
serialPort1.PortName = comboBox1.SelectedItem.ToString();
serialPort1.BaudRate = Convert.ToInt32(comboBox2.SelectedItem.ToString());
switch (comboBox3.SelectedIndex)
{
case 0:
serialPort1.Parity = Parity.None;
break;
case 1:
serialPort1.Parity = Parity.Odd;
break;
case 2:
serialPort1.Parity = Parity.Even;
break;
case 3:
serialPort1.Parity = Parity.Mark;
break;
case 4:
serialPort1.Parity = Parity.Space;
break;
}

serialPort1.DataBits = Convert.ToInt32(comboBox4.SelectedItem.ToString());

switch (comboBox5.SelectedIndex)
{
case 0:
serialPort1.StopBits = StopBits.One;
break;
case 1:
serialPort1.StopBits = StopBits.Two;
break;
case 2:
serialPort1.StopBits = StopBits.OnePointFive;
break;
}
serialPort1.Open();
panel1.BackColor = Color.LawnGreen;
comboBox1.Enabled = false;
comboBox2.Enabled = false;
comboBox3.Enabled = false;
comboBox4.Enabled = false;
comboBox5.Enabled = false;
tssl01.Text = "串口" + comboBox1.SelectedItem.ToString() + "已经打开";
button1.Text = "关闭串口";
// timer2.Start();
}
catch (Exception)
{
MessageBox.Show("串口打开失败" + "\n" + "1.请检查配置的参数是否正确" + "\n" + "2.外围设备是否没有连接" + "\n" + "3.串口是否已经打开或被占用" + "\n" + "4.串口驱动是否没有安装");
}
}
else
{
serialPort1.Close();
panel1.BackColor = Color.Red;
comboBox1.Enabled = true;
comboBox2.Enabled = true;
comboBox3.Enabled = true;
comboBox4.Enabled = true;
comboBox5.Enabled = true;
tssl01.Text = "串口" + comboBox1.SelectedItem.ToString() + "已经关闭";
button1.Text = "打开串口";
}
}

#region 清空缓存区
//清空缓存区
private void button4_Click(object sender, EventArgs e)
{
if (serialPort1.IsOpen)
{
serialPort1.DiscardInBuffer();
textBox1.Text = "";
}
}

private void button3_Click(object sender, EventArgs e)
{
if (serialPort1.IsOpen)
{
serialPort1.DiscardOutBuffer();
}
}
#endregion

#region 保存配置
private void button6_Click(object sender, EventArgs e)
{
if (serialPort1.IsOpen)
{
using (StreamWriter sw = new StreamWriter(Application.StartupPath + @"\SerConfig.wjs", false, Encoding.UTF8))
{
sw.WriteLine(comboBox1.SelectedItem.ToString());
sw.WriteLine(comboBox2.SelectedItem.ToString());
sw.WriteLine(comboBox3.SelectedItem.ToString());
sw.WriteLine(comboBox4.SelectedItem.ToString());
sw.WriteLine(comboBox5.SelectedItem.ToString());
sw.Flush();
}
MessageBox.Show("配置已成功保存 下次程序启动后会自动读取配置");
}
else
{
MessageBox.Show("只有成功打开了串口 才能保存配置");
}
}
#endregion

private void button2_Click(object sender, EventArgs e)
{
OpenFileDialog openFile = new OpenFileDialog();
openFile.Filter = "存储有命令的文本文件|*.txt";
openFile.ShowDialog();

if (openFile.FileName.Length > 0)
{
using (StreamReader sr = new StreamReader(openFile.FileName, Encoding.UTF8))
{
while (!sr.EndOfStream)
{
commmand.Add(sr.ReadLine());
}
}
}
}

public int type = 0;
//发送命令
private void button5_Click(object sender, EventArgs e)
{

string msg = "SMS" + cmb_yq.SelectedValue.ToString() + ":" + textBox2.Text;
serialPort1.Write(msg);
MessageBox.Show("命令发送完成!!!");
//if (serialPort1.IsOpen)
//{
// if (button5.Text == "开始发送")
// {
// if (checkBox1.Checked == true)
// {
// type = 1;
// timer1.Interval = Convert.ToInt32(numericUpDown1.Value) * 1000;
// timer1.Enabled = true;
// button1.Enabled = false;
// }
// else
// {
// TimerAction.timerAction(this,type);
// }
// }
// else if (button5.Text == "停止发送")
// {
// timer1.Enabled = false;
// button1.Enabled = true;
// textBox1.Text = "";
// groupBox2.Enabled = true;
// button5.Text = "开始发送";
// }
//}
//else
//{
// timer1.Enabled = false;
// groupBox2.Enabled = true;
// textBox1.Text = "";
// button5.Text = "开始发送";
// MessageBox.Show("请先打开串口 再发送数据");
//}
}

private void timer1_Tick(object sender, EventArgs e)
{
TimerAction.timerAction(this,type);
}

//check改变事件
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked == true)
{
numericUpDown1.Enabled = true;
}
else
{
numericUpDown1.Enabled = false;
}
}

//串中接收事件
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
//try
//{
// string text = string.Empty;
// byte[] result = new byte[serialPort1.BytesToRead];

// serialPort1.Read(result, 0, serialPort1.BytesToRead);

// foreach (byte b in result)
// {
// text = text + Convert.ToString(b, 16);
// }
// textBox1.Text = text;

// if (text.Length==10)
// {
// string[] getSz = GetArrayFromString(text);
// txt_zn.Text = getSz[0];
// txt_cd.Text = getSz[1];
// txt_pb.Text = getSz[2];
// txt_cu.Text = getSz[3];
// }

//}
//catch (Exception err)
//{
// MessageBox.Show(err.Message);
//}
}

//保存循环伏安法参数
private void btn_save_xhfaf_Click(object sender, EventArgs e)
{
iniHelpers.write("f", "----------------f代表循环伏安法参数----------------------");
iniHelpers.write("f初始电压", txt_csdy.Text.Trim());
iniHelpers.write("f结束电压", txt_jsdy.Text.Trim());
iniHelpers.write("f静息时间", txt_jxsj.Text.Trim());
iniHelpers.write("f静息电压", txt_jxdy.Text.Trim());
iniHelpers.write("f富集时间", txt_fjsj.Text.Trim());
iniHelpers.write("f富集电压", txt_fjdy.Text.Trim());
iniHelpers.write("f脉冲周期", txt_mczq.Text.Trim());
iniHelpers.write("f采样间隔", txt_cyjg.Text.Trim());
iniHelpers.write("f脉冲宽度", txt_mckd.Text.Trim());
iniHelpers.write("f步进电压", txt_bjdy.Text.Trim());
iniHelpers.write("f脉冲幅度", txt_mcfd.Text.Trim());
MessageBox.Show("循环伏安法参数保存成功!!!");
}

//镀汞参数设置
private void btn_save_dg_Click(object sender, EventArgs e)
{
iniHelpers.write("g", "-----------------g代表镀汞参数--------------------");
iniHelpers.write("g初始电压", text_csdy.Text.Trim());
iniHelpers.write("g结束电压", text_jsdy.Text.Trim());
iniHelpers.write("g步进速度", text_bjsd.Text.Trim());
iniHelpers.write("g镀汞时间", text_dgsj.Text.Trim());
iniHelpers.write("g采样步进电压", text_cybjdy.Text.Trim());
iniHelpers.write("g静息时间", text_jxsj.Text.Trim());
iniHelpers.write("g静息点位", text_jxdw.Text.Trim());

MessageBox.Show("镀汞参数保存成功!!!");
}

//循环伏安法
private void btn_faf_send_Click(object sender, EventArgs e)
{
//int i = 11;
//string s = i.ToString("X").PadLeft(4, ‘0‘); //转16进制
//MessageBox.Show(s);

string csdy = Convert.ToInt32(txt_csdy.Text.Trim()).ToString("X").PadLeft(4, ‘0‘);
string jsdy = Convert.ToInt32(txt_jsdy.Text.Trim()).ToString("X").PadLeft(4, ‘0‘);
string jxsj = Convert.ToInt32(txt_jxsj.Text.Trim()).ToString("X").PadLeft(4, ‘0‘);
string fjsj = Convert.ToInt32(txt_fjsj.Text.Trim()).ToString("X").PadLeft(4, ‘0‘);
string fjdy = Convert.ToInt32(txt_fjdy.Text.Trim()).ToString("X").PadLeft(4, ‘0‘);
string mczq = Convert.ToInt32(txt_mczq.Text.Trim()).ToString("X").PadLeft(4, ‘0‘);
string cyjg = Convert.ToInt32(txt_cyjg.Text.Trim()).ToString("X").PadLeft(2, ‘0‘);
string mckd = Convert.ToInt32(txt_mckd.Text.Trim()).ToString("X").PadLeft(4, ‘0‘);
string bjdy = Convert.ToInt32(txt_bjdy.Text.Trim()).ToString("X").PadLeft(4, ‘0‘);
string mcfd = Convert.ToInt32(txt_mcfd.Text.Trim()).ToString("X").PadLeft(4, ‘0‘);
string jxdy = Convert.ToInt32(txt_jxdy.Text.Trim()).ToString("X").PadLeft(4, ‘0‘);
//循环伏安法(CMD=0x03):CMD(0xff)+富集时间(0xffff)+富集电压(0xffff)+静息时间(0xffff)+静息电压(0xffff)+初始电压(0xffff)+结束电压(0xffff)+步进电压(0xffff)+脉冲幅度(0xffff)+脉冲宽度(0xffff)+脉冲周期(0xffff)+采样间隔(0xff)+结束符(0xfefe)
if(serialPort1.IsOpen)
{
//MessageBox.Show("03" + fjsj + fjdy + jxsj + jsdy + csdy + jsdy + bjdy + mcfd + mckd + mczq + cyjg + "fe");
//serialPort1.Write("03" + fjsj + fjdy + jxsj + jsdy + csdy + jsdy + bjdy + mcfd + mckd + mczq + cyjg + "fe");
string msg = "SMS" + cmb_yq.SelectedValue.ToString() + ":" + "03" + fjsj + fjdy + jxsj + jxdy + csdy + jsdy + bjdy + mcfd + mckd + mczq + cyjg + "fe";
if (MessageBox.Show("指令:03" + fjsj + fjdy + jxsj + jxdy + csdy + jsdy + bjdy + mcfd + mckd + mczq + cyjg + "fefe", "是否向 "+cmb_yq.SelectedValue.ToString()+" 发送指令",
MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
{
serialPort1.Write(msg);
}
}

}

//镀汞命令发送
private void btn_dg_send_Click(object sender, EventArgs e)
{
string csdy = Convert.ToInt32(text_csdy.Text.Trim()).ToString("X").PadLeft(4, ‘0‘);
string jsdy = Convert.ToInt32(text_jsdy.Text.Trim()).ToString("X").PadLeft(4, ‘0‘);
string jxsj = Convert.ToInt32(text_jxsj.Text.Trim()).ToString("X").PadLeft(4, ‘0‘);
string bjsd = Convert.ToInt32(text_bjsd.Text.Trim()).ToString("X").PadLeft(4, ‘0‘);
string dgsj = Convert.ToInt32(text_dgsj.Text.Trim()).ToString("X").PadLeft(4, ‘0‘);
string cybjdy = Convert.ToInt32(text_cybjdy.Text.Trim()).ToString("X").PadLeft(2, ‘0‘);
string jxdw = Convert.ToInt32(text_jxdw.Text.Trim()).ToString("X").PadLeft(4, ‘0‘);
//镀汞(CMD=0x05):CMD(0xff)+初始电压(0xffff)+结束电压(0xffff)+步进速度(0xffff)+镀汞时间(0xffff)+采样步进电压(0xff)+静息时间Time_silent(0xffff)+静息电位Voltage_silent(0xffff)+结束符(0xfefe);
if (serialPort1.IsOpen)
{
string msg = "SMS" + cmb_yq.SelectedValue.ToString() + ":" + "05" + csdy + jsdy + bjsd + dgsj + cybjdy + jxsj + jxdw + "fefe";
if (MessageBox.Show("指令:05" + csdy + jsdy + bjsd + dgsj + cybjdy + jxsj + jxdw + "fe", "是否向 " + cmb_yq.SelectedValue.ToString() + " 发送指令",
MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
{
serialPort1.Write(msg);
MessageBox.Show("命令发送完成!!!");
}
}

}

#region 连通阀,命令发送
//连通阀,命令发送
private void btn_liangtong_Click(object sender, EventArgs e)
{
string[] sen = new string[6];
sen[0] = "474F30310D00";
sen[1] = "474F30320D00";
sen[2] = "474F30330D00";
sen[3] = "474F30340D00";
sen[4] = "474F30350D00";
sen[5] = "474F30360D00";
if (serialPort1.IsOpen)
{
string msg = "SMS" + cmb_yq.SelectedValue.ToString() + ":01" + sen[(cmb_ltz.SelectedIndex)];
serialPort1.Write(msg);
MessageBox.Show("命令发送完成!!!");
}
else
{
MessageBox.Show("串口未打开");
}
}
#endregion

#region 系统设置按钮,保存配置
//系统设置按钮,保存配置,并加载新数据
private void btn_xtSeting_Click(object sender, EventArgs e)
{
SetSystem.SetSystemM(this);
MessageBox.Show("系统设置成功!!!");

// cmb_yq.Items.Clear();
ArrayList al = new ArrayList();
al.Add(new TextAndValue("系统1", iniHelpers.ContentValue("系统1")));
al.Add(new TextAndValue("系统2", iniHelpers.ContentValue("系统2")));
al.Add(new TextAndValue("系统3", iniHelpers.ContentValue("系统3")));
cmb_yq.DataSource = al;
cmb_yq.DisplayMember = "DisplayText";
cmb_yq.ValueMember = "RealValue";
}
#endregion

#region 获取结果

//获取结果
private void btn_hqjg_Click(object sender, EventArgs e)
{
string msg = "SMS" + cmb_yq.SelectedValue.ToString() + ":" + "07fe";
serialPort1.Write(msg);

timer_mess.Start();

//string[] getSz = GetArrayFromString("01020304fe");
//txt_zn.Text = getSz[0];
//txt_cd.Text = getSz[1];
//txt_pb.Text = getSz[2];
//txt_cu.Text = getSz[3];
}

public string[] GetArrayFromString(string val)
{
var count = val.Length % 2 == 0 ? val.Length / 2 : (val.Length + 1) / 2;
var charVal = val.ToCharArray();
string[] result = new string[count];
for (var i = 1; i < val.Length; i++)
{
if ((i + 1) % 2 == 0)
{
result[(i - 1) / 2] = charVal[i - 1] + "" + charVal[i];
}
}
if (charVal.Length % 2 != 0)
{
result[count - 1] = "0" + charVal[val.Length - 1];
}
return result;
}

private void timer2_Tick(object sender, EventArgs e)
{
try
{
string text = string.Empty;
byte[] result = new byte[serialPort1.BytesToRead];

serialPort1.Read(result, 0, serialPort1.BytesToRead);

foreach (byte b in result)
{
text = text + Convert.ToString(b, 16);
}
textBox1.Text = text;

if (text.Length == 10)
{
string[] getSz = GetArrayFromString(text);
txt_zn.Text = getSz[0];
txt_cd.Text = getSz[1];
txt_pb.Text = getSz[2];
txt_cu.Text = getSz[3];
}
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}
}
#endregion

#region 抽满时间控件间隔发

private void btn_paikong_Click(object sender, EventArgs e)
{
//抽满:初始化+延时20s+输入阀+延时1s+抽满
//排空:输出阀+延时1s+排空
//初始化 0x2F,0x31,0x5A,0x30,0x52,0x0D,0x00
//输入阀 0x2F,0x31,0x49,0x52,0x0D,0x00
//输出阀 0x2F,0x31,0x4F,0x52,0x0D,0x00
//抽满 0x2F,0x31,0x41,0x33,0x30,0x30,0x30,0x52,0x0D,0x00
//排空 0x2F,0x31,0x41,0x30,0x52,0x0D,0x00
if (serialPort1.IsOpen)
{
btn_paikong.Enabled = false;
timer_pk1.Start();

}
else
{
MessageBox.Show("串口未打开");
}
}

private void timer_pa1_Tick(object sender, EventArgs e)
{
msg = "SMS" + cmb_yq.SelectedValue.ToString() + ":" + "2F315A30520D00";
serialPort1.Write(msg);
//MessageBox.Show("OK");
//Thread.Sleep(10000);
timer_pa2.Start();
timer_pa1.Stop();

}

private void timer_pa2_Tick(object sender, EventArgs e)
{
msg = "SMS" + cmb_yq.SelectedValue.ToString() + ":" + "2F3149520D00";
serialPort1.Write(msg);
//Thread.Sleep(10000);
// MessageBox.Show("")
timer_pa3.Start();
timer_pa2.Stop();
}

private void timer_pa3_Tick(object sender, EventArgs e)
{
msg = "SMS" + cmb_yq.SelectedValue.ToString() + ":" + "2F314133303030520D00";
serialPort1.Write(msg);
//Thread.Sleep(10000);
//MessageBox.Show("命令发送完成!!!");
btn_cm.Enabled = true;
timer_pa3.Stop();
}
#endregion

#region 排空时间控件间隔发

//抽满
private void btn_cm_Click(object sender, EventArgs e)
{
//抽满:初始化+延时20s+输入阀+延时1s+抽满
//排空:输出阀+延时1s+排空
//初始化 0x2F,0x31,0x5A,0x30,0x52,0x0D,0x00
//输入阀 0x2F,0x31,0x49,0x52,0x0D,0x00
//输出阀 0x2F,0x31,0x4F,0x52,0x0D,0x00
//抽满 0x2F,0x31,0x41,0x33,0x30,0x30,0x30,0x52,0x0D,0x00
//排空 0x2F,0x31,0x41,0x30,0x52,0x0D,0x00
if (serialPort1.IsOpen)
{
btn_cm.Enabled = false;
timer_pa1.Start();
//timer_pa1.Interval = 20000;
//msg = "SMS" + cmb_yq.SelectedValue.ToString() + ":" + "2F315A30520D00";
//serialPort1.Write(msg);
//Thread.Sleep(20000);
//msg = "";
//msg = "SMS" + cmb_yq.SelectedValue.ToString() + ":" + "2F3149520D00";
//serialPort1.Write(msg);
//Thread.Sleep(10000);
//msg = "";
//msg = "SMS" + cmb_yq.SelectedValue.ToString() + ":" + "2F314133303030520D00";
//serialPort1.Write(msg);
//MessageBox.Show("命令发送完成!!!");
}
else
{
MessageBox.Show("串口未打开");
}
}

private void timer_pk1_Tick(object sender, EventArgs e)
{
string msg = "SMS" + cmb_yq.SelectedValue.ToString() + ":" + "2F314F520D00";
serialPort1.Write(msg);
//Thread.Sleep(10000);
timer_pk2.Start();
timer_pk1.Stop();

}

private void timer_pk2_Tick(object sender, EventArgs e)
{

msg = "SMS" + cmb_yq.SelectedValue.ToString() + ":" + "2F314130520D00";
serialPort1.Write(msg);
//Thread.Sleep(10000);
btn_paikong.Enabled = true;
timer_pk2.Stop();
// MessageBox.Show("命令发送完成!!!");

}
#endregion

//提示消息
private void timer_mess_Tick(object sender, EventArgs e)
{
// Thread.Sleep(10000);
MessageBox.Show("未收到数据!!!");
timer_mess.Stop();
}

}

}

串口调适,布布扣,bubuko.com

时间: 2024-11-07 00:51:17

串口调适的相关文章

Linux 控制台下串口的基本操作

显示串口波特率等信息: stty -F /dev/ttyTHS2 -a  #dev/ttyTHS2为选择的端口号 参数设置: stty -F /dev/ ttyTHS2 ispeed 115200 ospeed 115200 cs8 配置波特率115200数据8bit,一般情况下设置这两个参数就可以了,如果显示数据乱码,可能还需要设置其它参数,使用man查看stty其它设置选项. 发送串口数据: echo 123> /dev/ttyTHS2 读取串口数据: cat /dev/ttyTHS2 读取

Linux下串口编制【转】

串行口是计算机一种常用的接口,具有连接线少,通讯简单,得到广泛的使用.常用的串口是RS-232-C接口(又称EIA RS-232-C)它是在1970年由美国电子工业协会(EIA)联合贝尔系统.调制解调器厂家及计算机终端生产厂家共同制定的用于串行通讯的标准.串口通讯指的是计算机依次以位(bit)为单位来传送数据,串行通讯使用的范围很广,在嵌入式系统开发过程中串口通讯也经常用到通讯方式之一. Linux对所有设备的访问是通过设备文件来进行的,串口也是这样,为了访问串口,只需打开其设备文件即可操作串口

ubuntu下可用的串口调试工具--cutecom

今天在ubuntu下要用到串口发送16进制数据,百度了很多工具,觉得minicom和cutecom都不错,比较直观是cutecom,所以就介绍下cutecom. 安装: 输入 $ sudo apt-get install cutecom    便可安装 $ cutecom                                    便可执行 这是软件截图: Device:这里是串口名称,但有时识别的串口不能在这里选择,比如ttyUSB0,需要手动修改为 /dev/ttyUSB0 Bau

51单片机之串口通信(三)

51单片机之串口通信(三) 已有 47 次阅读2015-12-29 00:21 |个人分类:51单片机| 单片机, 通信 用串口实现发送和接收同时可操作: 电脑显示结果如图: 源程序: /*项目名称:串口发送接收实验项目内容:串口发送接收同时进行,计算机发送数据给单片机控制P0口,从而控制LED灯的亮灭,单片机发送数据到计算机,计算机显示出来时间:2015年12月23日项目负责人:YUAN*/#include <reg52.h>typedef unsigned char uChar8;type

【工业串口和网络软件通讯平台(SuperIO)教程】六.二次开发导出数据驱动

SuperIO相关资料下载:http://pan.baidu.com/s/1pJ7lZWf 1.1    导出数据接口的作用 在数据集成系统项目中,要么是自已集成其他厂家的设备,要么是其他厂家集成自己家的设备,在没有统一的标准前提下,就会有各种集成数据的格式.为了满足此类的场景,为设备输出数据专门设计了接口,开发者可以继承该接口,设备在处理完数据后,会把数据自动传输到该接口,可以按规定的数据格式进行输出了. 1.2    接口功能说明 开发设备输出接口,主要考虑到在集成项目中,集成过程中或被集成

VELT-0.1.5开发: gdb串口调试内核时信息丢失的问题

快乐虾 http://blog.csdn.net/lights_joy/(QQ群:Visual EmbedLinux Tools 375515651) 欢迎转载,但请保留作者信息 本文仅适用于vs2013 + velt-0.1.5 VELT的全称是Visual EmbedLinuxTools,它是一个与visual gdb类似的visual studio插件,用以辅助完成Linux开发.利用这个插件,将可以在visual studio的IDE中进行Linux应用程序的开发(包括编译和调试),也可

linux串口驱动分析——发送数据

一.应用程序中write函数到底层驱动历程 和前文提到的一样,首先先注册串口,使用uart_register_driver函数,依次分别为tty_register_driver,cdev_init函数,找到使用的file_operations,即应用程序与tty架构的统一接口.步骤不再赘述. static const struct file_operations tty_fops = { .llseek = no_llseek, .read = tty_read, .write = tty_wr

通过串口接收带有标识符的数据方法

在做串口通信过程中,下位机向上位机发送的串口数据有时候需要带有指定的标识符,便于上位机根据标识符判断后续几位数据是做什么用的.也就是下位机和上位机约定数据帧的传输格式,便于在上位机将数据分离,当然这种数据帧格式可以自定义. 今天用arduino作为下位机,模拟数据通过自定义格式发送数据帧,利用串口将数据帧发送到android上位机,上位机用java代码实现数据提取,并在界面实时显示接收数据,虽然是模拟数据通过串口发送,但在实际项目开发中,原理相通. 以下是arduino代码,通过设定定时器,当接

Linux串口IO模式的一些心得

众所周知,在Linux系统下所有设备都是以文件的形式存在,串口也一样. 通常I/O操作都是有阻塞与非阻塞的两种方式. 其中"超时"这个概念其实是阻塞中的一种处理手段,本质还是属于阻塞的I/O模式. 在Linux中串口的IO操作 本文将它分为三种状态: 阻塞状态 超时状态 非阻塞状态 这三种状态的转换组合有这么几种: 阻塞 --> 超时 阻塞 --> 非阻塞 超时 --> 阻塞 超时 --> 非阻塞 非阻塞 --> 阻塞 我们一个一个来分析 首先在一个串口的