Affichage des articles dont le libellé est CN Fanuc. Afficher tous les articles
Affichage des articles dont le libellé est CN Fanuc. Afficher tous les articles

mercredi 12 février 2014

Exemple Focas en VB Part 3

Pour faire suite à un précédent article, voici un petit exemple de code complémentaire sur la programmation sur CN Fanuc par la liaison FOCAS. Le code reprend l'utilisation de la fonction "Status_of_Function" définie dans le précédent billet. Cet exemple permet de relire le type de CN présent sur la machine .

'---------------------
' 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
' read CNC system information
Declare Function cnc_sysinfo Lib "fwlib32.dll" (ByVal FlibHndl As Integer, Odb As ODBSYS) As Integer
' cnc_sysinfo:read CNC system information
#If FS15BD Then

Type ODBSYS
  Dummy As Integer             ' dummy
  Max_axis As Integer          ' maximum axis number
  Cnc_type As String * 2       ' cnc type <ascii char>
  Mt_type As String * 2        ' M/T/TT <ascii char>
  Series As String * 4         ' series NO. <ascii char>
  Version As String * 4        ' version NO.<ascii char>
  Axes As String * 2           ' axis number<ascii char>
End Type

#Else

Type ODBSYS
  Addinfo As Integer           ' additional information
  Max_axis As Integer          ' maximum axis number
  Cnc_type As String * 2       ' cnc type <ascii char>
  Mt_type As String * 2        ' M/T/TT <ascii char>
  Series As String * 4         ' series NO. <ascii char>
  Version As String * 4        ' version NO.<ascii char>
  Axes As String * 2           ' axis number<ascii char>
End Type

#End If


Private Sub Form_Load()
   Dim LibHndl As Integer
    Dim Ret As Integer
    Dim SysInfo As ODBSYS
    Dim Result(16) As Integer
    Dim TypeS As String


'  192.0.0.1 Addresse connexion Ethernet sur CN
'  8193 : Port Focas
   Ret = cnc_allclibhndl3("192.0.0.1", "8193", 10, LibHndl)
   If Ret Then call Status_of_Function(Ret, "cnc_allclibhndl3")

' Recupère les informations sur la CN
    Ret = cnc_sysinfo(LibHndl, SysInfo)
    If Ret Then call Status_of_Function(Ret, "cnc_sysinfo")

'Affiche la description de la CN
    TypeS = "Fanuc " & CStr(SysInfo.Cnc_type)
' Addinfo
' bit 1
'0 : not an i Series CNC
'1 : i Series CNC


    Ret = ConvBin(SysInfo.Addinfo, Result) ' si 10 alors 1 : i Series CNC
    If Result(1) = 1 Then
     TypeS = TypeS & "i Series CNC"
    End If
   
 ' L'information MT_type indique si la CN est du type fraisage ou tournage
' M' : Machining center
' T' : Lathe
' MM' : M series with 2 path control
' TT' : T series with 2/3 path control
' MT' : T series with compound machining function

    TypeS = TypeS & " " & SysInfo.Axes & " axes"
    TypeS = TypeS & " " & SysInfo.Mt_type 
 
    MsgBox TypeS

'  De-allocate handle
    Ret = cnc_freelibhndl(LibHndl)
    If Ret Then Call Status_of_Function(Ret, "cnc_freelibhndl")
End Sub

' Conversion d'un entier en binaire
Function ConvBin(ByVal Number As Integer, Res() As Integer) As Integer
    Dim Rest As Integer
    Dim Result As String
    Dim IND As Integer
    IND = 0
   
    Do
        Rest = Number Mod 2
        Number = Number \ 2
        Res(IND) = Rest
        IND = IND + 1
        'Result = CStr(Rest) & Result
    Loop While Number > 0
   
    ConvBin = IND - 1
   
End Function

Exemple FOCAS suite

Pour faire suite à un précédent article, voici un petit exemple de code complémentaire sur la programmation FOCAS. Le code reprend l'utilisation de la fonction "Status_of_Function" définie dans le précédent billet. Cet exemple permet de relire les valeurs des correcteurs outils.

'---------------------
' 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
    Ret = cnc_setpath(LibHndl, 2)
    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

vendredi 3 mai 2013

Utilisation Focas

Difficile de trouver des informations sur la programmation Focas pour cn Fanuc sur le NET. Voici donc ma petite contribution avec un premier code pour tester la connexion

'---------------------
' 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

Private Sub Form_Load()
Dim LibHndl As Integer
Dim Ret As Integer


'  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)

End Sub


'---------------------------------------
' Gestion erreur sur fonction focas
'--------------------------------------
Sub Status_of_Function(ByRef Error As Integer, Optional FocasFonction As String)

Dim MSGA As String
Dim MSGB As String

'Return  Meaning  Explanation and Error handling
Select Case Error
Case EW_PROTOCOL
    MSGA = "(-17)  Protocol error (Ethernet version only)": MSGB = "Data from Ethernet Board is incorrect." & vbCrLf & "Contact with the service section or the section in charge."
Case EW_SOCKET
    MSGA = "(-16)  Socket error (Ethernet version only)": MSGB = "Investigate CNC power supply, Ethernet cable and I/F board."
Case EW_NODLL
    MSGA = "(-15)  DLL file error": MSGB = "There is no DLL file for each CNC series corresponding to specified node."
Case EW_BUS
    MSGA = "(-11)  Bus error (HSSB version only)": MSGB = "A bus error of CNC system occurred." & vbCrLf & "Contact with the service section or the section in charge."
Case EW_SYSTEM2
    MSGA = "(-10)  System error (2) (HSSB version only)": MSGB = "A system error of CNC system occurred." & vbCrLf & "Contact with the service section or the section in charge."
Case EW_HSSB
    MSGA = "(-9)  Communication error of HSSB (HSSB version only)": MSGB = "Investigate the serial line or I/F board of HSSB."
Case EW_HANDLE
    MSGA = "(-8)  Handle number error  Get the library handle number."
Case EW_VERSION
    MSGA = "(-7)  Version mismatch between the CNC/PMC and library": MSGB = "The CNC/PMC version does not match that of the library." & vbCrLf & "Replace the library or the CNC/PMC control software."
Case EW_UNEXP
    MSGA = "(-6)  Abnormal library state": MSGB = "An unanticipated error occurred." & vbCrLf & "Contact with the section in charge."
Case EW_SYSTEM
    MSGA = "(-5)  System error (HSSB version only)": MSGB = "A system error of CNC occurred." & vbCrLf & "Contact with the service section or the section in charge."
Case EW_PARITY
    MSGA = "(-4)  Shared RAM parity error (HSSB version only)": MSGB = "A hardware error occurred." & vbCrLf & "Contact with the service section."
Case EW_MMCSYS
    MSGA = "(-3)  FANUC drivers installation error (HSSB version only)": MSGB = "The drivers required for execution are not installed."
Case EW_RESET
    MSGA = "(-2)  Reset or stop request": MSGB = "The RESET or STOP button was pressed." & vbCrLf & "Call the termination function."
Case EW_BUSY
    MSGA = "(-1)  Busy": MSGB = "Wait until the completion of CNC processing, or retry."
Case EW_OK
    MSGA = "(0)  Normal termination"
    Exit Sub
Case EW_FUNC
    MSGA = "(1)  Error(function is not executed, or not available)": MSGB = "Specific function which must be executed beforehand has not been executed." & vbCrLf & "Otherwise that function is not available."
Case EW_LENGTH
    MSGA = "(2)  Error(data block length error, error of number of data)": MSGB = "Check and correct the data block length or number of data."
Case EW_NUMBER
    MSGA = "(3)  Error(data number error)": MSGB = "Check and correct the data number."
Case EW_ATTRIB
    MSGA = "(4)  Error(data attribute error)": MSGB = "Check and correct the data attribute."
Case EW_DATA
    MSGA = "(5)  Error(data error)": MSGB = "Check and correct the data." & vbCrLf & "For the following operations, this code indicates that the specified program cannot be found." & vbCrLf & "Delete specified program" & vbCrLf & "Search specified program" & vbCrLf & "Start uploading NC program"

Case EW_NOOPT
    MSGA = "(6)  Error(no option)": MSGB = "There is no corresponding CNC option."
Case EW_PROT
    MSGA = "(7)  Error(write protection)": MSGB = "Write operation is prohibited."
Case EW_OVRFLOW
    MSGA = "(8)  Error(memory overflow)": MSGB = "CNC tape memory is overflowed."
Case EW_PARAM
    MSGA = "(9)  Error(CNC parameter error)": MSGB = "CNC parameter is set incorrectly."
Case EW_BUFFER
    MSGA = "(10)  Error(buffer empty/full)": MSGB = "The buffer is empty or full." & vbCrLf & "Wait until completion of CNC processing, or retry."
Case EW_PATH
    MSGA = "(11)  Error(path number error)": MSGB = "A path number is incorrect."
Case EW_MODE
    MSGA = "(12)  Error(CNC mode error)": MSGB = "The CNC mode is incorrect." & vbCrLf & "Correct the CNC mode."
Case EW_REJECT
    MSGA = "(13)  Error(CNC execution rejection)": MSGB = "The execution at the CNC is rejected." & vbCrLf & "Check the condition of execution."
Case EW_DTSRVR
    MSGA = "(14)  Error(Data server error)": MSGB = "Some errors occur at the data server."
Case EW_ALARM
    MSGA = "(15)  Error(alarm)": MSGB = "The function cannot be executed due to an alarm in CNC." & vbCrLf & "Remove the cause of alarm."
Case EW_STOP
    MSGA = "(16)  Error(stop)": MSGB = "CNC status is stop or emergency."
Case EW_PASSWD
    MSGA = "(17)  Error(State of data protection)": MSGB = "Data is protected by the CNC data protection function."

Case Else
    MSGA = "Erreur inconnue  :" & Error
    MSGB = "Numéro d'erreur inconnue"
End Select

MsgBox "ERREUR SUR FONCTION FOCAS -> " & FocasFonction & " : " & MSGA & vbCrLf & vbCrLf & MSGB

End Sub

mercredi 11 avril 2012

MACRO-CLIENT Fanuc

Pour mes besoins j'ai du me plonger dans les macros clients sur FANUC. J'ai eu un peu de mal à trouver les infos surtout que la doc constructeur était très Light sur certains sujets.

Voici donc une petite listes de codes utiles testés sur Fanuc 31i

Message Opérateur

#3000=30(ERREUR APPEL FONCTION UVW) Affiche une erreur CN et arrête la machine : 30= Numéro de l'erreur (ERREUR APPEL FONCTION UVW=0) = Texte de l'erreur

#3006=1(ERREUR APPEL FONCTION UVW) Par rapport à la solution avec variable 3000 permet de ne pas créer une erreur CN mais juste un message (ici pas de numéro de message d'erreur juste 0 ou 1 )

Temps d'éxécution d'un programme

J'utilise la variable 3001 Cette variable fonctionne comme une horloge comptant par incrément d'une milliseconde. On peut la remettre à Zéro dans un programme. Sinon, elle repasse à Zéro après 2147483648 millisecondes ce qui laisse de la marge :)

En début de programme
#3001=0 (INIT HORLOGE) En fin de programme je récupère le temps et je divise par 1000 pour les secondes
#501=#3001/1000 (HORLOGE FIN)

Ecrire dans un fichier des résultats
Pour Ecride ce temps dans un fichier
POPEN
DPRNT[TEMPS:#501[90]S]
PCLOS


POPEN pour ouvrir le fichier
PCLOS pour le fermer
et DPRNT pour écrire. Le fichier céé le sera avec le nom PRNTXXXX.DAT XXX étant un numéro incrémenté par la CN à chque nouveau fichier

DPRNT[TEMPS:#501[90]S] Pour écrire une variable on utilise la notation #501[43] -> 43 veut dire 3 chiffre après la virgule et 4 c'est le nomrbre de chiffre avant


Palpage avec palpeur de contact

Le palpage utilise le code G31 déplacement avec saut

G31X Y Z F (Palpage)
G53
#101=#5061(X au declenchement)
#102=#5064(Y au declenchement)
#103=#5062(Z au declenchement)

Attention sur ma machine l'orde des axes et XZCY d'où 5064 pour Y (cas d'un tour fraiseur)

Les variables #5061 à #5068 sont les données de position du signal de saut ( au moment ou le palpeur arrête la machine)


Vérouillage des fichiers macro
Pour le vérouillage des programmes (MACRO) sur Fanuc, il est possible d'interdire la modification des programmes 8000 à 9000 avec les paramètres CN :

Paramètres #3202
#3202-0 [NE8]:
Verrouille ou autorise l'édition des programmes 8000 à 8999.
0: Édition verrouillée 1: Édition autorisée
#3202-4 [NE9]:
Verrouille ou autorise l'édition des programmes 9000 à 9999.
0: Édition verrouillée 1: Édition autorisée

A complèter