fanuc cf卡加工

时间:2020-07-27 19:20:02 作者:租号谷

fanuc 0i-mc系统使用cf卡在线加工的同时如何通过RS232串口采集数据

//创建一个串口通讯

SerialPort CurrentPort = null;

CurrentPort = new SerialPort();

CurrentPort.ReadBufferSize = 128;

CurrentPort.PortName = comName; //端口号

CurrentPort.BaudRate = bandRate; //比特率

CurrentPort.Parity =parity;//奇偶校验

CurrentPort.StopBits = stop;//停止位

CurrentPort.DataBits = databit;//数据位

CurrentPort.ReadTimeout = 1000; //读超时,即在1000内未读到数据就引起超时异常

//绑定数据接收事件,因为发送是被动的,所以你无法主动去获取别人发送的代码,只能通过这个事件来处理

CurrentPort.DataReceived += Sp_DataReceived;

CurrentPort.Open();

定义一个变量 byte[] receiveStr;

//绑定的事件处理函数

{

SerialPort sp = sender as SerialPort;

if (sp == null)

return;

byte[] readBuffer = new byte[sp.ReadBufferSize];

sp.Read(readBuffer, 0, readBuffer.Length);

//赋值

receiveStr=readBuffer;//当然你可以通过转换将byte[]转换为字符串。

}

//你要求的按钮事件可以这么写

private void button1_Click(object sender, EventArgs e)

{

if(receiveStr!=null)

{

变量 xxx=receiveStr;

}

}

声明:本文内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现fanuc cf卡加工有涉嫌版权的内容,欢迎发送邮件至:2145784@qq.com 进行举报,并提供相关证据,工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。

相关推荐

5174租号

一、百度5174租号查询 5174租号百度关键词查询 编号 相关词 搜索量 相关结果 百度查询 优化价格 1 5174租号 55866 299.8万 百度5174租号 65.2元 2 游戏租号三国快打 74645 1430.2万 百度租号到底怎么样