树莓派Linux跨平台免授权CNC数控数据采集协议,TCP协议包,支持(fanuc、三菱、西门子、海德汉、马扎克、兄弟、哈斯、广数、凯恩帝KND、华中)数控跨平台,支持网关Linux

这篇具有很好参考价值的文章主要介绍了树莓派Linux跨平台免授权CNC数控数据采集协议,TCP协议包,支持(fanuc、三菱、西门子、海德汉、马扎克、兄弟、哈斯、广数、凯恩帝KND、华中)数控跨平台,支持网关Linux。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

市面上的数控基本都支持了跨平台通讯,下面以三菱为列讲解跨平台协议如何通讯,无需任何DLL,适配任何开发语言,纯Socket通讯

先上采集图 

cnc协议,Fanuc数据采集,西门子数控数据采集,三菱CNC数据采集,java,开发语言,c#,TCP,协议

代码如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 三菱TCP
{
    public partial class Form1 : Form
    {
        public static Socket TcpSocket;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
         

        }

        private void btnVer_Click(object sender, EventArgs e)
        {
           
        }
        //TcpSocket.Send(SendCommand.伺服名称);


        //    byte[] Data = ReceiveData();



        //byte[] Data2 = new byte[] { 0x10 };



        //string s = Encoding.Default.GetString(Data.Skip(28).Take(1).ToArray()).Replace("\0", string.Empty);

        public   byte[] ReceiveData()
        {
            byte[] b = new byte[1024];
            int n = TcpSocket.Receive(b);
            byte[] DATA = b.Take(n).ToArray();

            textBox1.Text = BitConverter.ToString(DATA).Replace("-","");;
            return DATA;






        }
     
        public string timeconvert(string time)
        {
            time= time.PadLeft(6,'0');

            if (time.Length > 6)
            {

                return time.Substring(0, time.Length-4)+":" + time.Substring(time.Length - 4, 2) + ":" + time.Substring(time.Length - 6, 2);
            }
            else
            {
                return time.Substring(0, 2) + ":" + time.Substring(2, 2) + ":" + time.Substring(4, 2);
            }


        }
      
     
        private void button12_Click(object sender, EventArgs e)
        {
            TcpSocket.Send(SendCommand.程序内容);
            byte[] Data = ReceiveData();
            程序内容.Text = Encoding.Default.GetString(Data.Skip(22).ToArray()).Replace("\0", string.Empty);

        }

        private void button13_Click(object sender, EventArgs e)
        {
            TcpSocket.Send(SendCommand.当前刀具号);
            byte[] Data = ReceiveData();
            int time = BitConverter.ToInt32(Data.Skip(22).Take(4).ToArray(), 0);
            当前刀具号.Text = time.ToString();
        }

        private void button14_Click(object sender, EventArgs e)
        {
            TcpSocket.Send(SendCommand.主轴设定);
            byte[] Data = ReceiveData();
            int time = BitConverter.ToInt32(Data.Skip(22).Take(4).ToArray(), 0);
            主轴转速设定.Text = time.ToString();
        
        }

        private void button15_Click(object sender, EventArgs e)
        {
            TcpSocket.Send(SendCommand.进给速度设定);
            byte[] Data = ReceiveData();
            
            进给速度设定.Text = BitConverter.ToDouble(Data.Skip(22).Take(8).ToArray(), 0).ToString();

        }

        private void button16_Click(object sender, EventArgs e)
        {
            TcpSocket.Send(SendCommand.进给速度实际值);
            byte[] Data = ReceiveData();
            进给速度实际值.Text = BitConverter.ToDouble(Data.Skip(44).Take(8).ToArray(), 0).ToString(); ;
        }

    

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                TcpSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                TcpSocket.ReceiveTimeout = 1000;
                TcpSocket.Connect(txt_ip.Text, int.Parse(txt_port.Text));
                if (TcpSocket.Connected)
                {
                    MessageBox.Show("ok");
                }

            }
            catch (Exception ex)
            {

            }
        }

        private void button19_Click(object sender, EventArgs e)
        {
           
            TcpSocket.Send(SendCommand.主轴倍率);
            byte[] Data = ReceiveData();
  
            主轴倍率.Text = Data.Last().ToString();

        }

        private void button20_Click(object sender, EventArgs e)
        {
            TcpSocket.Send(SendCommand.进给倍率);
            byte[] Data = ReceiveData();

            进给倍率.Text = Data.Last().ToString();
        }

        private void button21_Click(object sender, EventArgs e)
        {

            TcpSocket.Send(SendCommand.CNC类型);
            byte[] Data = ReceiveData();
            CNC类型.Text = Encoding.Default.GetString(Data.Skip(22).Take(22).ToArray()).Replace("\0", string.Empty);
             

        }

        private void button22_Click(object sender, EventArgs e)
        {
            TcpSocket.Send(SendCommand.加工件数);
            byte[] Data = ReceiveData();
            int time = BitConverter.ToInt32(Data.Skip(22).Take(4).ToArray(), 0);
            加工件数.Text = time.ToString();
            
        }

       

        private void button23_Click(object sender, EventArgs e)
        {
            增益.Text = 读取伺服监控(0x01);
        }

        private void button24_Click(object sender, EventArgs e)
        {
            跟踪延迟.Text = 读取伺服监控(0x02);
        }

      

        private void timer1_Tick(object sender, EventArgs e)
        {
            foreach (Control c in this.Controls)
            {
            
                Control c1 = c as Button;
                if (c1 != null)
                {
                    if (c1.Name != "button1"&& c1.Name != "button25")
                    {
                        ((Button)c1).PerformClick();

                    }
              
                }
            }
        }

        private void button25_Click_1(object sender, EventArgs e)
        {
            timer1.Enabled = true;
        }

      
    }
}

 文章来源地址https://www.toymoban.com/news/detail-596308.html

到了这里,关于树莓派Linux跨平台免授权CNC数控数据采集协议,TCP协议包,支持(fanuc、三菱、西门子、海德汉、马扎克、兄弟、哈斯、广数、凯恩帝KND、华中)数控跨平台,支持网关Linux的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包