赞
踩
C# 采用发那科Robot Interface 中间库和机器人控制柜通过网络通讯,主要功能如下:
- /// 连接发那科机器人
- /// </summary>
- /// <param name="IPAddress">机器人IP地址</param>
- /// <param name="DataPosRegStartIndex">PR寄存器开始地址</param>
- /// <param name="DataPosRegEndIndex">PR寄存器结束地址</param>
- /// <returns></returns>
- public static bool ConnectRobot(string IPAddress, int DataPosRegStartIndex, int DataPosRegEndIndex)
- {
- lock (Lock_FNCRobot)
- {
- try
- {
- mobjCore = new Core();
- mobjCore.set_TimeOutValue(1000);
- mobjDataTable = mobjCore.get_DataTable();
- mobjDataNumReg_INT = mobjDataTable.AddNumReg(FRIF_DATA_TYPE.NUMREG_INT, 1, 200);
- mobjDataNumReg_REAL = mobjDataTable.AddNumReg(FRIF_DATA_TYPE.NUMREG_REAL, 1, 200);
- mobjDataString_NUMREG_COMMENT = mobjDataTable.AddString(FRIF_DATA_TYPE.NUMREG_COMMENT, 1, 10);
- mobjDataPosReg = mobjDataTable.AddPosReg(FRIF_DATA_TYPE.POSREG, 1, DataPosRegStartIndex, DataPosRegEndIndex);
- mobjCurPos = mobjDataTable.AddCurPos(FRRJIf.FRIF_DATA_TYPE.CURPOS, 1);
-
- if (mobjCore.Connect(IPAddress.Trim()))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- catch (Exception e1)
- {
- MessageBox.Show("异常信息:\r\n" + e1.Message.ToString(), "Exclamation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- return false;
- }
- }
- }

- /// <summary>
- /// 断开和发那科机器人的通讯
- /// </summary>
- public static void DisConnectRobot()
- {
- lock (Lock_FNCRobot)
- {
- try
- {
- mobjCore.Disconnect();
- mobjCore = null;
- mobjDataTable = null;
- mobjDataNumReg_INT = null;
- mobjDataNumReg_REAL = null;
- mobjDataString_NUMREG_COMMENT = null;
- mobjDataPosReg = null;
- mobjCurPos = null;
- //MessageBox.Show("连接已终止!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- catch (Exception e1)
- {
- MessageBox.Show("异常信息:\r\n" + e1.Message.ToString(), "Exclamation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- }
- }
- }

- /// <summary>
- /// 读发那科机器人DO值
- /// </summary>
- /// <param name="DO">DO号</param>
- /// <param name="Result">DO值</param>
- /// /// <param name="Count">位数</param>
- /// <returns>返回true或false</returns>
- public static bool ReadRobotDO(int DO, ref Array Result, int Count)
- {
- lock (Lock_FNCRobot)
- {
- try
- {
- if (mobjCore.ReadSDO(DO, ref Result, Count))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- catch (Exception e1)
- {
- MessageBox.Show("异常信息:\r\n" + e1.Message.ToString(), "Exclamation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- return false;
- }
- }
- }

- /// <summary>
- /// 写发那科机器人DO值
- /// </summary>
- /// <param name="DO">DO</param>
- /// <param name="Value">DO值:0或1</param>
- /// <returns>返回true或false</returns>
- public static bool WriteRobotDO(int DO, int Value)
- {
- lock (Lock_FNCRobot)
- {
- try
- {
- Array buf = new short[1];
- buf.SetValue((short)Value, 0);
- if (mobjCore.WriteSDO(DO, ref buf, 1))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- catch (Exception e1)
- {
- MessageBox.Show("异常信息:\r\n" + e1.Message.ToString(), "Exclamation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- return false;
- }
- }
- }

- public static bool ReadRobotDI(int DI, ref Array Result)
- {
- lock (Lock_FNCRobot)
- {
- try
- {
- if (mobjCore.ReadSDI(DI, ref Result, 1))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- catch (Exception e1)
- {
- MessageBox.Show("异常信息:\r\n" + e1.Message.ToString(), "Exclamation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- return false;
- }
- }
- }

- public static bool ReadRobotR(int R, ref object Result)
- {
- lock (Lock_FNCRobot)
- {
- try
- {
- mobjDataTable.Refresh();
- if (mobjDataNumReg_INT.GetValue(R, ref Result))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- catch (Exception e1)
- {
- MessageBox.Show("异常信息:\r\n" + e1.Message.ToString(), "Exclamation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- return false;
- }
- }
- }
-

- public static bool WriteRobotR(int R, int Value, int Count)
- {
- lock (Lock_FNCRobot)
- {
- try
- {
- if (mobjDataNumReg_INT.SetValuesInt(R, ref Value, Count))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- catch (Exception e1)
- {
- MessageBox.Show("异常信息:\r\n" + e1.Message.ToString(), "Exclamation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- return false;
- }
- }
- }

- public static bool WriteRobotR(int R, float Value, int Count)
- {
- lock (Lock_FNCRobot)
- {
- try
- {
- if (mobjDataNumReg_REAL.SetValuesReal(R, ref Value, Count))
- {
- return true;
- }
- else
- {
- return false;
- }
-
- }
- catch (Exception e1)
- {
- MessageBox.Show("异常信息:\r\n" + e1.Message.ToString(), "Exclamation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- return false;
- }
- }
- }

- public static bool WriteRobotR_COMMENT(int R, string Value)
- {
- lock (Lock_FNCRobot)
- {
- try
- {
- if (mobjDataString_NUMREG_COMMENT.SetValue(R, Value))
- {
- mobjDataString_NUMREG_COMMENT.Update();
- return true;
- }
- else
- {
- return false;
- }
- }
- catch (Exception e1)
- {
- MessageBox.Show("异常信息:\r\n" + e1.Message.ToString(), "Exclamation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- return false;
- }
- }
- }

- public static bool ReadRobotPRJoint(int PR, ref float[] Result)
- {
- lock (Lock_FNCRobot)
- {
- try
- {
- short ut = 0, validJ = 0;
- mobjDataTable.Refresh();
- if (mobjDataPosReg.GetValueJoint(PR, ref Result[0], ref Result[1], ref Result[2], ref Result[3], ref Result[4], ref Result[5], ref Result[6], ref Result[7], ref Result[8], ref ut, ref validJ))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- catch (Exception e1)
- {
- MessageBox.Show("异常信息:\r\n" + e1.Message.ToString(), "Exclamation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- return false;
- }
- }
- }

- public static bool ReadRobotPRXyzwpr(int PR, ref float[] Result)
- {
- lock (Lock_FNCRobot)
- {
- try
- {
- float X = 0, Y = 0, Z = 0, W = 0, P = 0, R = 0, E1 = 0, E2 = 0, E3 = 0;
- short C1 = 0, C2 = 0, C3 = 0, C4 = 0, C5 = 0, C6 = 0, C7 = 0;
- short ut = 0, validc = 0, uf = 0;
- mobjDataTable.Refresh();
- if (mobjDataPosReg.GetValueXyzwpr(PR, ref X, ref Y, ref Z, ref W, ref P, ref R, ref E1, ref E2, ref E3, ref C1, ref C2, ref C3, ref C4,
- ref C5, ref C6, ref C7, ref uf, ref ut, ref validc))
- {
- Result[0] = X;
- Result[1] = Y;
- Result[2] = Z;
- Result[3] = W;
- Result[4] = P;
- Result[5] = R;
- return true;
- }
- else
- {
- return false;
- }
- }
- catch (Exception e1)
- {
- MessageBox.Show("异常信息:\r\n" + e1.Message.ToString(), "Exclamation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- return false;
- }
- }
- }

- public static bool WriteRobotPRJoint(int PR, Array Value, short UF, short UT)
- {
- lock (Lock_FNCRobot)
- {
- try
- {
- if (mobjDataPosReg.SetValueJoint(PR, ref Value, UF, UT))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- catch (Exception e1)
- {
- MessageBox.Show("异常信息:\r\n" + e1.Message.ToString(), "Exclamation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- return false;
- }
- }
- }

- public static bool WriteRobotPRXyzwpr(int PR, float X, float Y, float Z, float W, float P, float R, float E1, float E2, float E3,
- short C1, short C2, short C3, short C4, short C5, short C6, short C7, short UF, short UT)
- {
- lock (Lock_FNCRobot)
- {
- try
- {
- if (mobjDataPosReg.SetValueXyzwpr2(PR, X, Y, Z, W, P, R, E1, E2, E3, C1, C2, C3, C4, C5, C6, C7, UF, UT))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- catch (Exception e1)
- {
- MessageBox.Show("异常信息:\r\n" + e1.Message.ToString(), "Exclamation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- return false;
- }
- }
- }

- public static bool ReadCurrRobotXyzwpr(ref Array xyzwpr)
- {
- lock (Lock_FNCRobot)
- {
- try
- {
- Array config = new short[7];
- Array joint = new float[9];
- short intUF = 0;
- short intUT = 0;
- short intValidC = 0;
- short intValidJ = 0;
-
- mobjDataTable.Refresh();
- mobjCurPos.GetValue(ref xyzwpr, ref config, ref joint, ref intUF, ref intUT, ref intValidC, ref intValidJ);
- return true;
- }
- catch (Exception e1)
- {
- MessageBox.Show("异常信息:\r\n" + e1.Message.ToString(), "Exclamation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- return false;
- }
- }
- }

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。