'---------------------
' Ethernet connexion
'---------------------
' allocate library handle 3
Declare Function cnc_allclibhndl3 Lib "fwlib32.dll" (ByVal sIPaddr As String, ByVal nPort As Integer, ByVal nTimeout As Long, FlibHndl As Integer) As Integer
' free library handle
Declare Function cnc_freelibhndl Lib "fwlib32.dll" (ByVal FlibHndl As Integer) As Integer
' set path number(for 4 axes lathes, multi-path)
Declare Function cnc_setpath Lib "fwlib32.dll" (ByVal FlibHndl As Integer, ByVal A As Integer) As Integer
' read tool offset information
Declare Function cnc_rdtofsinfo Lib "fwlib32.dll" (ByVal FlibHndl As Integer, Odb As ODBTLINF) As Integer
' read tool offset value
Declare Function cnc_rdtofs Lib "fwlib32.dll" (ByVal FlibHndl As Integer, ByVal A As Integer, ByVal B As Integer, ByVal c As Integer, Odb As ODBTOFS) As Integer
' cnc_rdtofsinfo:read tool offset information
Type ODBTLINF
Ofs_type As Integer
Use_no As Integer
End Type
' cnc_rdtofs:read tool offset value
Type ODBTOFS
Datano As Integer ' data number
Type As Integer ' data type
Data As Long ' data
End Type
Private Sub Form_Load()
Dim LibHndl As Integer
Dim Ret As Integer
Dim tlinf As ODBTLINF
Dim Ncorrecteur As Integer ' Variable pour le numero de correcteur à relire
Dim tofs As ODBTOFS
' 192.0.0.1 Addresse connexion Ethernet sur CN (Attention deux ports généralement port communication et Data serveur)
' 8193 : Port Focas
Ret = cnc_allclibhndl3("192.0.0.1", "8193", 10, LibHndl)
If Ret Then call Status_of_Function(Ret, "cnc_allclibhndl3")
' Définition du canal dans le cas de CN utilisant plusieurs cannaux
' Dans ce cas la CN est du type :
' MM | : | M series with 2 path control |
' TT | : | T series with 2/3 path control |
If Ret Then Call Status_of_Function(Ret, "cnc_setpath")
' Récupère le nombre de correcteur maxi disponible sur la machine
Ret = cnc_rdtofsinfo(LibHndl, tlinf)
If Ret Then Call Status_of_Function(Ret, "cnc_rdtofsinfo")
Ncorrecteur=10 ' Numéro du correcteur outil à relire
If Ncorrecteur>tlinf.Use_no Then 'Test pour éviter de relire un numéro de correcteur dépassant la limite machine
Ncorrecteur = tlinf.Use_no
End If
' Type de variable pour récupération correcteur outil
' Lathe Series (T series)
' X axis Z axis Nose R Imaginary tool nose Y axis
' Wear 0 2 4 6 8
' Geometry 1 3 5 7 9
' ( Z,GEOMETRY)
Ret = cnc_rdtofs(LibHndl, Ncorrecteur , 3, 8, tofs) ' 3= Z axis Gometry et taille =8 (toujours ?)
If Ret Then Call Status_of_Function(Ret, "cnc_rdtofs")
MsgBox "Valeur du correcteur de géométrie Z pour l'outil : " & Ncorrecteur & "=" & (tofs.Data/1000) ' La valeur est à diviser par 1000 pour avoir en mm
' De-allocate handle
Ret = cnc_freelibhndl(LibHndl)
If Ret Then Call Status_of_Function(Ret, "cnc_freelibhndl")
End Sub
Following your nice example I was able to query the offset number 1 in a 31i control... But As far as I understood it read offsets from tool number 1, and the offset of this tool is defined in 'Ncorrecteur'
RépondreSupprimerHow can I select the tool number first? It´s working for offsets (D / H numbers) but the tool number is fixed I guess... Any suggestions?
Thanks for the great blog. Without this sample I´d never gfigure it out...
Hello Daniel,
RépondreSupprimerTo get the tool compensation settings you must use the function "cnc_rdtofs" as mentionned in this post.
Ret = cnc_rdtofsinfo(LibHndl, tlinf)
tlinf.Use_no gives you the number of tool corector available on the controler.
Ret = cnc_rdtofs(LibHndl, Ncorrector , Nvalue, 8, tofs) gives you the requested value.
You must use a function like : Conv_tofs(tofs.Data, tofs.Type) to get the correct conversion .
Hereafter my Conv_Tofs function :
Function Conv_tofs(Val As Long, Tofs_type As Integer) As Double
Dim Div As Integer
Select Case Tofs_type
Case 6
Div = 1
Case Else
Div = 1000
End Select
Conv_tofs = Val / Div
End Function
Depending of your controler the "lenght" of the data block could be different. You must report to the Html documentation of this function to get more information.
In this post the code are tested and use for a lathe (Type T for the controler )
'Lathe Series (T series)
' X axis Z axis Nose R
'Wear 0 2 4
'Geometry 1 3 5
' Imaginary tool nose position => 6
So am I correct to assume that Nvalue in the code below is the tool number?
RépondreSupprimerRet = cnc_rdtofs(LibHndl, Ncorrector , Nvalue, 8, tofs) gives you the requested value.
Ncorrector is the Corrector Number in the tool table Ie:
RépondreSupprimerIf in the ISO code You use G43H2 2 is your corrector value.
If you want to know the tool length coorection you need to add the tool wear + tool geometry. So in this case you must read both values with the Nvalue 0 + 1 or 2 + 3
cnc_rdtofs(LibHndl, 2, 0, 8, tofs) and cnc_rdtofs(LibHndl, 2, 1, 8, tofs)
Hi Laurent!
RépondreSupprimerI think my mistake is to assume offsets are linked to tools... They´re are independent on FANUCs you can call T10 H400, what Ncorrector is is the H number.... But this is bothering me:
When I execute "Ret = cnc_rdtofsinfo(LibHndl, tlinf)", I get a maximum number of offsets of 32. But we have 996 offsets on this machine (It´s a MoriSeiki NT - FANUC 31iA5, T model, with extended tool offsets option).
I believe tlinf.use_no should return 996 and not 32...
Thanks anyway!