Forum
Reading from multiple axes
Quote from Henrique Núñez on October 7, 2020, 1:34 pmLike described in the posts, the trials on reading from multiple axes were unsuccessful.
I'm also trying to do it, and I've seen on the documentation that the parameter differs from machine to machine. Here as follows:
Data size at all axes specification:
In some function, when you read/write data for all axes, data size that must be allocated is different as follows.
the library except Series 30i, 0i-D/F, PMi-A: number of the actual control axis.
the library for Series 30i, 0i-D/F, PMi-A: number of maximum axes in interface.I'm a computer scientist, and I have little knowledge on CNCs. Could someone explain what "number of maximum axes in interface" is?
Thx
Like described in the posts, the trials on reading from multiple axes were unsuccessful.
I'm also trying to do it, and I've seen on the documentation that the parameter differs from machine to machine. Here as follows:
Data size at all axes specification:
In some function, when you read/write data for all axes, data size that must be allocated is different as follows.
the library except Series 30i, 0i-D/F, PMi-A: number of the actual control axis.
the library for Series 30i, 0i-D/F, PMi-A: number of maximum axes in interface.
I'm a computer scientist, and I have little knowledge on CNCs. Could someone explain what "number of maximum axes in interface" is?
Thx
Quote from Versex on October 9, 2020, 12:43 pmHi Henrique,
So I have not had any luck reading multiple axes at the same time. I am not entirely sure why this is. It may be an issue with the .cs file. The way the Focas works in .Net is that it imports the calls from the C++ dll. When they marshal the calls, there are various options that need to be accounted for. It is entirely possible that they made a mistake with that. I haven't looked too deeply into that though.
I am on vacation for the next week, but if I get some time, I will look into this to see if I can figure something out. I just made a program that looped through each number from 1 to 256 and found that no matter what you put into the data length field it will not work. Although I did just discover a buffer overflow.
As for the Max number of axes, that is defined in fwlib32.cs. You will find this, at the top of that file...
/* Axis define */
#if FS30D
public const short MAX_AXIS = 32;
#elif M_AXIS2
public const short MAX_AXIS = 24;
#elif FS15D
public const short MAX_AXIS = 10;
#else
public const short MAX_AXIS = 8;
#endifSo it depends on what control you have as to what the max number of axis is for that machine. I believe it just defines the maximum number of possible axes that the control type supports.
I'll let you know what I find out.
Hi Henrique,
So I have not had any luck reading multiple axes at the same time. I am not entirely sure why this is. It may be an issue with the .cs file. The way the Focas works in .Net is that it imports the calls from the C++ dll. When they marshal the calls, there are various options that need to be accounted for. It is entirely possible that they made a mistake with that. I haven't looked too deeply into that though.
I am on vacation for the next week, but if I get some time, I will look into this to see if I can figure something out. I just made a program that looped through each number from 1 to 256 and found that no matter what you put into the data length field it will not work. Although I did just discover a buffer overflow.
As for the Max number of axes, that is defined in fwlib32.cs. You will find this, at the top of that file...
/* Axis define */
#if FS30D
public const short MAX_AXIS = 32;
#elif M_AXIS2
public const short MAX_AXIS = 24;
#elif FS15D
public const short MAX_AXIS = 10;
#else
public const short MAX_AXIS = 8;
#endif
So it depends on what control you have as to what the max number of axis is for that machine. I believe it just defines the maximum number of possible axes that the control type supports.
I'll let you know what I find out.
Quote from Henrique Núñez on October 30, 2020, 7:35 amHello Versex.
I changed my programming from C# to C++, because i needed a better acquisition rate. My conclusions: the trouble is with FOCAS. I measured the time needed to execute the FOCAS requests to the CNC, and each of them took around 15ms to execute. So 4*15 = 60ms, although the actual time varied quite a bit, ranging from 50ms to 150ms.
Since all the calls delay more or less the same, i tried optimizing the code by reading all the axes at once. I managed to get the number of axes information with the following code:
ODBSYS sysinfo_cnc;
cnc_sysinfo(_machine_handle, &sysinfo_cnc);printf("Axis: %d\n", sysinfo_cnc.max_axis);
I fount out that my machine axis number is 32, so by using the following code I managed to get all axes position:
_ret = cnc_absolute(_machine_handle, ALL_AXES, 512, &_axisPositionAbsolute);
Note that I'm using Fwlib64 directly with C++, not with the C# translation overlay.
Regards.
Hello Versex.
I changed my programming from C# to C++, because i needed a better acquisition rate. My conclusions: the trouble is with FOCAS. I measured the time needed to execute the FOCAS requests to the CNC, and each of them took around 15ms to execute. So 4*15 = 60ms, although the actual time varied quite a bit, ranging from 50ms to 150ms.
Since all the calls delay more or less the same, i tried optimizing the code by reading all the axes at once. I managed to get the number of axes information with the following code:
ODBSYS sysinfo_cnc;
cnc_sysinfo(_machine_handle, &sysinfo_cnc);
printf("Axis: %d\n", sysinfo_cnc.max_axis);
I fount out that my machine axis number is 32, so by using the following code I managed to get all axes position:
_ret = cnc_absolute(_machine_handle, ALL_AXES, 512, &_axisPositionAbsolute);
Note that I'm using Fwlib64 directly with C++, not with the C# translation overlay.
Regards.
Quote from Henrique Núñez on June 15, 2021, 1:49 pmQuote from Versex on October 9, 2020, 12:43 pmHi Henrique,
So I have not had any luck reading multiple axes at the same time. I am not entirely sure why this is. It may be an issue with the .cs file. The way the Focas works in .Net is that it imports the calls from the C++ dll. When they marshal the calls, there are various options that need to be accounted for. It is entirely possible that they made a mistake with that. I haven't looked too deeply into that though.
I am on vacation for the next week, but if I get some time, I will look into this to see if I can figure something out. I just made a program that looped through each number from 1 to 256 and found that no matter what you put into the data length field it will not work. Although I did just discover a buffer overflow.
As for the Max number of axes, that is defined in fwlib32.cs. You will find this, at the top of that file...
/* Axis define */
#if FS30D
public const short MAX_AXIS = 32;
#elif M_AXIS2
public const short MAX_AXIS = 24;
#elif FS15D
public const short MAX_AXIS = 10;
#else
public const short MAX_AXIS = 8;
#endifSo it depends on what control you have as to what the max number of axis is for that machine. I believe it just defines the maximum number of possible axes that the control type supports.
I'll let you know what I find out.
Hi, I'm back.
I'm in another development iteration, and like i said previously, it would be great if i improved the acquisition rate. I also found out that every FOCAS call is slow (probably due to the protocol stack involved and the CNC event loop), so performing the reads in the least possible number of FOCAS calls would help me.
At first, I used `_ret = Focas1.cnc_absolute2(_machine_handle, -1, (short) (4 + 4 * Focas1.MAX_AXIS), _axisPositionAbsolute);` but it returned an error. So i tried to brute force the axis number with this simple code.
```
// trying to get all axes:
for (int i = 0; i < 100; i++)
{
Console.WriteLine("Trying {0} axes", i);
_ret = Focas1.cnc_absolute2(_machine_handle, -1, (short) (4 + 4 * i), _axisPositionAbsolute);if (_ret != Focas1.EW_OK)
{
Console.WriteLine("[Getter] Error {0} on getting all axes position. {1}", _ret, i);
}
}```
In the attached image you can see that, after 32, it stops returning an error (for my machine, 0i-MF).
By using 4 + 4 * 32 as the byte number i managed to read properly all the axes, as you can see in the other attachment.
TLDR: I managed to read all axes at once, using this tiny hack.
Quote from Versex on October 9, 2020, 12:43 pmHi Henrique,
So I have not had any luck reading multiple axes at the same time. I am not entirely sure why this is. It may be an issue with the .cs file. The way the Focas works in .Net is that it imports the calls from the C++ dll. When they marshal the calls, there are various options that need to be accounted for. It is entirely possible that they made a mistake with that. I haven't looked too deeply into that though.
I am on vacation for the next week, but if I get some time, I will look into this to see if I can figure something out. I just made a program that looped through each number from 1 to 256 and found that no matter what you put into the data length field it will not work. Although I did just discover a buffer overflow.
As for the Max number of axes, that is defined in fwlib32.cs. You will find this, at the top of that file...
/* Axis define */
#if FS30D
public const short MAX_AXIS = 32;
#elif M_AXIS2
public const short MAX_AXIS = 24;
#elif FS15D
public const short MAX_AXIS = 10;
#else
public const short MAX_AXIS = 8;
#endifSo it depends on what control you have as to what the max number of axis is for that machine. I believe it just defines the maximum number of possible axes that the control type supports.
I'll let you know what I find out.
Hi, I'm back.
I'm in another development iteration, and like i said previously, it would be great if i improved the acquisition rate. I also found out that every FOCAS call is slow (probably due to the protocol stack involved and the CNC event loop), so performing the reads in the least possible number of FOCAS calls would help me.
At first, I used `_ret = Focas1.cnc_absolute2(_machine_handle, -1, (short) (4 + 4 * Focas1.MAX_AXIS), _axisPositionAbsolute);` but it returned an error. So i tried to brute force the axis number with this simple code.
```
// trying to get all axes:
for (int i = 0; i < 100; i++)
{
Console.WriteLine("Trying {0} axes", i);
_ret = Focas1.cnc_absolute2(_machine_handle, -1, (short) (4 + 4 * i), _axisPositionAbsolute);
if (_ret != Focas1.EW_OK)
{
Console.WriteLine("[Getter] Error {0} on getting all axes position. {1}", _ret, i);
}
}
```
In the attached image you can see that, after 32, it stops returning an error (for my machine, 0i-MF).
By using 4 + 4 * 32 as the byte number i managed to read properly all the axes, as you can see in the other attachment.
TLDR: I managed to read all axes at once, using this tiny hack.
Uploaded files:
- You need to login to have access to uploads.
Quote from Henrique Núñez on June 15, 2021, 1:49 pmThis is where it stopped returning errors.
This is where it stopped returning errors.
Uploaded files:
- You need to login to have access to uploads.
Quote from Versex on June 15, 2021, 2:40 pmThat is awesome! Thank you for letting me know. I will have to look into this for our machines.
I also wanted to discuss a bit about the slow speed when reading from Fanuc. So what I have found is that the standard Fanuc controller using an Ethernet cable for communication is super slow. There are a couple of things that I have found that increase the speed. The first is an HSSB (High-Speed Serial Bus) connection. You will find this on some machines that have a full computer HMI running Windows. You will only be able to use this method on a machine that has an HSSB card in it. If you do not have HSSB there is still another option.
The second option is to purchase a Dataserver card for extra program storage on the machine. This is a card that can be inserted into the controller. It has an ethernet connection and will also have an FTP server running on it so that you can connect to it from your desktop and drop programs directly onto the machine. If you have a Dataserver card already or you feel like purchasing one, you can then request Fanuc to enable the Fast Ethernet option for a small fee. This will increase the read speed dramatically. You will be able to retrieve information in milliseconds rather than seconds. Using the Fast Ethernet option and the Dataserver, the code doesn't need to change. The only thing you would need to change is the IP address you are connecting to because the Dataserver requires its own IP address.
I hope this has been helpful and thank you again for posting this information.
That is awesome! Thank you for letting me know. I will have to look into this for our machines.
I also wanted to discuss a bit about the slow speed when reading from Fanuc. So what I have found is that the standard Fanuc controller using an Ethernet cable for communication is super slow. There are a couple of things that I have found that increase the speed. The first is an HSSB (High-Speed Serial Bus) connection. You will find this on some machines that have a full computer HMI running Windows. You will only be able to use this method on a machine that has an HSSB card in it. If you do not have HSSB there is still another option.
The second option is to purchase a Dataserver card for extra program storage on the machine. This is a card that can be inserted into the controller. It has an ethernet connection and will also have an FTP server running on it so that you can connect to it from your desktop and drop programs directly onto the machine. If you have a Dataserver card already or you feel like purchasing one, you can then request Fanuc to enable the Fast Ethernet option for a small fee. This will increase the read speed dramatically. You will be able to retrieve information in milliseconds rather than seconds. Using the Fast Ethernet option and the Dataserver, the code doesn't need to change. The only thing you would need to change is the IP address you are connecting to because the Dataserver requires its own IP address.
I hope this has been helpful and thank you again for posting this information.