epson机器⼈编程范例_Epson机械⼿简单实例编程
Epson简单实例
1.Epson软件⽅⾯编程
2.⽹络配置⽅⾯
3.vs编码⽅⾯
软件配置:Epson机械⼿软件,vs2012
⽹络配置:Tcp通信,IP地址及端⼝设置
硬件配置:Pc机,机械⼿,机械⼿供电器
⼀.环境准备
①pc,机械⼿,供电器上电。
②pc与机械⼿的两个⽹线插⼝连接,置供电器Power为On
③配置pc的ip地址与Epson软件同⼀个ip地址,Epson软件每⼀个端⼝都可以设置⼀个ip,可以同时开多个端⼝(设置位置:设置—系统配置—控制器—TCP/IP)
④窗⼝—电脑与控制器通信–增加,添加⼀个以太⽹连接p1,同时设置ip地址
⑤将软件状态从离线改为usb,在更改为名为p1的以太⽹连接。
⑥⼯具—机器⼈管理器,调试机械⼿,机械⼿运动则表⽰环境准备完成。
⼆. 编写Epson软件代码
①初始化Epson
②⽹络配置
③扫描端⼝,获取端⼝数据,传输数据Function ScanConnNet
OnErr GoTo errhandler
Do
NetSts = ChkNet(202)
If (NetSts > 0) Then
Input #202, RecvString$ '从202端⼝获取输⼊,并赋值到变量RecvString$
ParseStr RecvString$, RecvStr$(), "#"
ParseStr RecvString$, RecvStr$(), " "
Select RecvStr$(0)
Case "X"
Move CurPos +X(Val(RecvStr$(1)))
Case "-X"
Move CurPos -X(Val(RecvStr$(1)))
CX(P100) = Val(RecvStr$(1))
CY(P100) = Val(RecvStr$(2))
CZ(P100) = Val(RecvStr$(3))
CU(P100) = Val(RecvStr$(4))
CV(P100) = Val(RecvStr$(5))
CW(P100) = Val(RecvStr$(6))
Go LJM(P100)
'发送数据到202端⼝
Print #202, "#GoToPointok"
Send
ElseIf NetSts
Call NetOpen
ElseIf NetSts = 0 Then
EndIf
Print #202, "#RobotPos" + "," + Str$(CX(CurPos)) + "," + Str$(CY(CurPos)) + "," + Str$(CZ(CurPos)) + "," + Str$(CU(CurPos))
Wait 0.2
Loop
errHandler:
RecvString$ = ""
EResume Next
Fend
三.c#编程①Tcp连接核⼼代码using System.Threading.Tasks;
using TestLTDMC;
using System.Threading;
using System.Windows.Forms;
namespace Test
{
class Robot
{
private Socket client;
public static object sendLock = new object();
private IPEndPoint ipep;
private byte[] buf = new byte[1024];
private static object Lock = new object();
public static Robot robot;
private bool RobotConnectSts = false;
public static Robot instance;
public static Robot Instance()
{
if (instance == null)
{
instance = new Robot();
}
return instance;
}
private Robot()
{
IPAddress ipad = IPAddress.Parse("192.168.0.1");
ipep = new IPEndPoint(ipad, 2001);
}
public void ConnectWithRobot()
{
if (client != null && client.Connected)
{
client.Close();
}
try
{
lock (sendLock)
{
client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); client.Connect(ipep);
client.BeginReceive(buf, 0, buf.Length, SocketFlags.None, new AsyncCallback(Receive), client); }
}
catch
}
}
public bool GetRobotConnectSts
{
get
{
if (client != null)
{
RobotConnectSts = client.Connected;
}
else
{
RobotConnectSts = false;
}
return RobotConnectSts;
}
}
public void DisconnectWithRobot()
{
if (client != null)
{
client.Close();
}
}
private void Receive(IAsyncResult ia)
{
try
{
client = ia.AsyncState as Socket;
int count = client.EndReceive(ia);
client.BeginReceive(buf, 0, buf.Length, SocketFlags.None, new AsyncCallback(Receive), client); string context = Encoding.ASCII.GetString(buf, 0, count);
if (context.Length > 0)
ProcessData(context);
}
else
{
}
}
catch
{
}
}
private void ProcessData(string recvdata)
{
recvdata = recvdata.Trim();
string[] cmddata = recvdata.Split(new char[] { '#' });
//string[] singlecmddata1 = cmddata[1].Split(new char[] { '\r\n' });
string[] singlecmddata = cmddata[1].Split(new char[] { ',' });
if (singlecmddata[0].Trim() != "RobotPos")
{
RunLog.instance.SaveLog(1, "PC接收到Robot发来的去" + recvdata + "命令");
}
switch (singlecmddata[0].Trim())
{
case "RobotPos":
//相关处理
break;
default:
break;
}
}
public void SendCmdToRobot(string part1, double part2, string part3, string part4, string part5, string part6, string part7) {vs编程软件
string sendcmd = "";
sendcmd = part1 + " " + part2 + " " + part3 + " " + part4 + " " + part5 + " " + part6 + " " + part7;
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论