VC + + connection Fanuc machine tool real-time data acquisition using FOCAS4.0 version of the development library
FoCas protocol, tested successfully on HSSB's fanuc15i.
int main (int argc, char *argv[]) {
if (ARGC < 2)
{
fprintf (stderr, "Usage:%s + optional \ n", argv[0]);
Exit (1);
}
unsigned short hfanuc;
Short Fanret, Funcret; Do we have a handle + did function succeed?
Odbst Fanbuf; CNC Status
Odbact Spspeed; Spindle speed (selected spindle)
ODBACT2 Spspeed2; Spindle speed
Prgdir Progdir; Program Directory
Odbaxis buf; Axis Position (test)
Long node = 9; Simulator
Short method = 0; Defaults to Ethernet
if (argv[2]!= NULL)
method = Atoi (argv[2]);
Switch (method)
{
Case 1:
Fanret = Cnc_allclibhndl (&HFANUC); HSSB Real Machine
Break
Case 2:
Fanret = CNC_ALLCLIBHNDL2 (node, &HFANUC); HSSB Simulator Ncguide
Break
Default
Fanret = Cnc_allclibhndl3 (argv[1], 8193, 5, &HFANUC); Ethernet
Break
}
if (!fanret)
{
Funcret = Cnc_statinfo (Hfanuc, &fanbuf);
if (Funcret)
printf ("ERROR (%d) cnc_statinfo Controller%s \ n", Funcret, argv[1]);
Else
printf (' Fanuc%s replied:\nautomatic-manual Mode (AUT): \t\t%d\nstatus of Automatic Operation (run): \t%d\nstatus of Emerg Ency (Emergency): \t%d\nstatus of Alarm (Alarm): \t\t%d\nstatus of program Editing (edit): \t%d\n ", argv[1], Fanbuf.aut, fan Buf.run, Fanbuf.emergency, Fanbuf.alarm, Fanbuf.edit);
Funcret = Cnc_acts (Hfanuc, &spspeed);
if (Funcret)
printf ("ERROR (%d) cnc_acts Controller%s \ n", Funcret, argv[1]);
Else
printf ("Spindle speed (selected spindle): \t\t%ld\n", spspeed.data); ... Cnc_rdcommand
}
if (!cnc_rdparam (Stat.hfanuc, 15051,-1, 4 + 4 * max_axis, &fanparam))//Read tool offset (15051 = 18i)
{
for (int i = 0; i < 4; i++)//4 Values
{
sprintf (buf, "%.3f%.1s", (float) fanparam.u.ldatas[i]/1000, cdelim); Add Value + |
strcat (Stat.corder, buf); Add to Stat.corder
}
}
else//Did not work
for (int i = 0; i < 4; i++)//4 Values
strcat (Stat.corder, Cnoresult); 0|0|0|0|