树莓派 发那科 Fanuc Linux跨平台CNC数控数据采集协议,TCP协议包
市面上的数控基本都支持了跨平台通讯,下面以发那科为列讲解跨平台协议如何通讯,无需任何DLL,适配任何开发语言,纯Socket通讯
先上采集图
握手包:a0 a0 a0 a0 00 01 01 01 00 02 00 02
释放包:a0 a0 a0 a0 00 01 02 01 00 00
部分读取信息代码如下
public static Socket TcpSocket;public Form1(){InitializeComponent();}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;}private void button2_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){TcpSocket.Send(SendCommand.HexStringToBytes(SendCommand.握手));byte[] Data = ReceiveData();MessageBox.Show("ok");}}catch (Exception ex){}}private void button1_Click(object sender, EventArgs e){TcpSocket.Send(SendCommand.HexStringToBytes(SendCommand.系统信息));byte[] Data = ReceiveData();系统信息.Text = FanucSysInfo(Data);}private void button3_Click(object sender, EventArgs e){TcpSocket.Send(SendCommand.HexStringToBytes(SendCommand.断开));TcpSocket.Disconnect(false);}private void button4_Click(object sender, EventArgs e){TcpSocket.Send(SendCommand.HexStringToBytes(SendCommand.状态模式));byte[] Data = ReceiveData();byte[] Datanew = Data.Skip(14).ToArray();状态模式.Text="模式"+ ((WorkMode)(BitConverter.ToInt16(Datanew, 15))).ToString();状态模式.Text+=" 状态"+ ((RunStatus)(BitConverter.ToInt16(Datanew, 17))).ToString();}