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
②网络配置
③扫描端口,获取端口数据,传输数据FunctionScanConnNet
OnErrGoToerrhandler
Do
NetSts=ChkNet(202)
If(NetSts>0)Then
Input#202,RecvString′ 从 202 端 口 获 取 输 入 , 并 赋 值 到 变 量 R e c v S t r i n g '从202端口获取输入,并赋值到变量RecvString
′
从202端口获取输入,并赋值到变量RecvString
ParseStrRecvString, R e c v S t r ,RecvStr,RecvStr(),"#"
ParseStrRecvString, R e c v S t r ,RecvStr,RecvStr(),""
SelectRecvStr$(0)
Case"X"
MoveCurPos+X(Val(RecvStr$(1)))
Case"-X"
MoveCurPos-X(Val(RecvStr$(1)))
Case"RobotRun"
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))
GoLJM(P100)
'发送数据到202端口
Print#202,"#GoToPointok"
Send
ElseIfNetSts
CallNetOpen
ElseIfNetSts=0Then
EndIf
Print#202,"#RobotPos"+","+Str( C X ( C u r P o s ) ) + " , " + S t r (CX(CurPos))+","+Str(CX(CurPos))+","+Str(CY(CurPos))+","+Str( C Z ( C u r P o s ) ) + " , " + S t r (CZ(CurPos))+","+Str(CZ(CurPos))+","+Str(CU(CurPos))+","+Str( C V ( C u r P o s ) ) + " , " + S t r (CV(CurPos))+","+Str(CV(CurPos))+","+Str(CW(CurPos))+"#"
Wait0.2
Loop
errHandler:
RecvString$=""
EResumeNext
Fend
三.c#编程①Tcp连接核心代码usingSystem.Threading.Tasks;
usingTestLTDMC;
usingSystem.Threading;
usingSystem.Windows.Forms;
namespaceTest
{
classRobot
{
privateSocketclient;
publicstaticobjectsendLock=newobject();
privateIPEndPointipep;
privatebyte[]buf=newbyte[1024];
privatestaticobjectSendLock=newobject();
privatestaticobjectLock=newobject();
publicstaticRobotrobot;
privateboolRobotConnectSts=false;
publicstaticRobotinstance;
publicstaticRobotInstance()
{
if(instance==null)
{
instance=newRobot();
}
returninstance;
}
privateRobot()
{
IPAddressipad=IPAddress.Parse(“192.168.0.1”);
ipep=newIPEndPoint(ipad,2001);
}
publicvoidConnectWithRobot()
{
if(client!=null&&client.Connected)
{
client.Close();
}
try
{
lock(sendLock)
{
client=newSocket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
client.Connect(ipep);
client.BeginReceive(buf,0,buf.Length,SocketFlags.None,newAsyncCallback(Receive),client);
}
}
catch
{
}
}
publicboolGetRobotConnectSts
{
get
{
if(client!=null)
{
RobotConnectSts=client.Connected;
}
else
{
RobotConnectSts=false;
}
returnRobotConnectSts;
}
}
publicvoidDisconnectWithRobot()
{
if(client!=null)
{
client.Close();
}
}
privatevoidReceive(IAsyncResultia)
{
try
{
client=ia.AsyncStateasSocket;
intcount=client.EndReceive(ia);
client.BeginReceive(buf,0,buf.Length,SocketFlags.None,newAsyncCallback(Receive),client);
stringcontext=Encoding.ASCII.GetString(buf,0,count);
if(context.Length>0)
{
ProcessData(context);
}
else
{
}
}
catch
{
}
}
privatevoidProcessData(stringrecvdata)
{
recvdata=recvdata.Trim();
string[]cmddata=recvdata.Split(newchar[]{’#’});
//string[]singlecmddata1=cmddata[1].Split(newchar[]{’ '});
string[]singlecmddata=cmddata[1].Split(newchar[]{’,’});
if(singlecmddata[0].Trim()!=“RobotPos”)
{
RunLog.instance.SaveLog(1,“PC接收到Robot发来的去”+recvdata+“命令”);
}
switch(singlecmddata[0].Trim())
{
case"RobotPos":
//相关处理
break;
default:
break;
}
}
publicvoidSendCmdToRobot(stringpart1,doublepart2,stringpart3,stringpart4,stringpart5,stringpart6,stringpart7)
{
stringsendcmd="";
sendcmd=part1+""+part2+""+part3+""+part4+""+part5+""+part6+""+part7;
SendCmdData(sendcmd);
}
publicvoidSendCmdData(stringStrData)
{
RunLog.instance.SaveLog(1,“PC向Robot发送”+StrData+“命令”);
lock(SendLock)
{
try
{
byte[]buf1;
buf1=Encoding.ASCII.GetBytes(StrData+" ");
client.Send(buf1,0,buf1.Length,SocketFlags.None);
}
catch
来源 网络
————————————————
更多详情:
爱普生机器人