Siemens mb_bittest prodave [Résolu]

Messages postés
1
Date d'inscription
mercredi 24 septembre 2008
Dernière intervention
24 septembre 2008
- 24 sept. 2008 à 21:53 - Dernière réponse :
Messages postés
2
Date d'inscription
mercredi 26 février 2003
Dernière intervention
25 septembre 2008
- 25 sept. 2008 à 13:33
Salut,
J'ai commencé par développer en VB6 pour faire de la récupératione de données sur des automates VIPA/S7_300/S7_200 depuis un PC en MPI/PROFIBUS.
Maintenant je fait ça directement depuis EXEL. Je peut vous reseigner sur les connections et aquisitions.
Pour l'instant je sait récupérer les réels/doubles mots et les mots, mais je coince sut les bits :
la fonction apropriée est mb_bittest mais je n'arrive pas à la comprendre correctement. Je parvient à récupérer des états true/false mais de bits inconnus.
Est-ce que quelqu'un peut m'expliquer en détail comment utiliser la fonction ?
le DB n'est pas demandé, dois-je récupérer un mot complet puis dans un deuxième temps en ressortir le bit voulu ?

merci

OPC siemens S7 200/300
Afficher la suite 

Votre réponse

2 réponses

Meilleure réponse
Messages postés
2
Date d'inscription
mercredi 26 février 2003
Dernière intervention
25 septembre 2008
25 sept. 2008 à 13:33
3
Merci
MB_BITTEST

Sert a tester UN MEMENTO :
Exemple MW0 16 BITs MB0 (8 Bits) + MB1 (8 Bits)

Pour Tester l'état du bit 5 de MB1 [MB1.5 ] :  mbno=1   bitno=5    ---->  est equivalent à M1.5( Bit de Memento) voir function ReadMemo.
Exe: Res = ReadMemo("1.5")

Merci cs_dvp 3

Avec quelques mots c'est encore mieux Ajouter un commentaire

Codes Sources a aidé 92 internautes ce mois-ci

Commenter la réponse de cs_dvp
Messages postés
2
Date d'inscription
mercredi 26 février 2003
Dernière intervention
25 septembre 2008
25 sept. 2008 à 11:01
0
Merci
bonjour, ci-desous un exemple en VBA

Option Compare Database
Option Explicit


Declare Function load_tool Lib "w95_s7" (ByVal lngNo As Byte, ByVal strName As String, ByVal strAdr As String) As Long
Declare Function new_ss Lib "w95_s7" (ByVal bytNr As Byte) As Long
Declare Function db_read Lib "w95_s7" (ByVal lngDbNo As Long, ByVal lngDwNo As Long, ByRef lngAmount As Long, ByRef intBuffer As Integer) As Long
Declare Function unload_tool Lib "w95_s7" () As Long
Declare Function d_field_read Lib "w95_s7" (ByVal bstlngNo As Long, ByVal lngNo As Long, ByVal lngAmount As Long, ByRef intBuffer As Integer) As Long
Declare Function d_field_write Lib "w95_s7" (ByVal bstlngNo As Long, ByVal lngNo As Long, ByVal lngAmount As Long, ByRef intBuffer As Integer) As Long
Declare Function db_write Lib "w95_s7" (ByVal lngDbNo As Long, ByVal lngDwNo As Long, ByRef lngAmount As Long, ByRef intBuffer As Integer) As Long
Declare Function e_field_read Lib "w95_s7" (ByVal lngNo As Long, ByVal lngAmount As Long, ByRef intBuffer As Integer) As Long
Declare Function a_field_write Lib "w95_s7" (ByVal lngNo As Long, ByVal lngAmount As Long, ByRef intBuffer As Integer) As Long
Declare Function a_field_read Lib "w95_s7" (ByVal lngNo As Long, ByVal lngAmount As Long, ByRef intBuffer As Integer) As Long
Declare Function m_field_read Lib "w95_s7" (ByVal lngNo As Long, ByVal lngAmount As Long, ByRef intBuffer As Integer) As Long
Declare Function m_field_write Lib "w95_s7" (ByVal lngNo As Long, ByVal lngAmount As Long, ByRef intBuffer As Integer) As Long


Function Error_Message(lngRes As Long) As String
Dim strResult As String
Dim vntRep As Variant


  If lngRes <> 0 Then


    strResult = "Dit is foutmelding : " + Format(lngRes)
 
    Select Case lngRes
        Case 202:          strResult = strResult + " No Resources available"
        Case 203:          strResult = strResult + " Configuration error"
        Case 205:          strResult = strResult + " Illegal call"
        Case 206:          strResult = strResult + " Module Not found"
        Case 207:          strResult = strResult + " Driver Not loaded"
        Case 208:          strResult = strResult + " Hardware fault"
        Case 209:          strResult = strResult + " Software fault"
        Case 210:          strResult = strResult + " Memory fault"
        Case 215:          strResult = strResult + " No message"
        Case 216:          strResult = strResult + " Storage fault"
        Case 219:          strResult = strResult + " Internal timeout"
        Case 225:          strResult = strResult + " Too many channels open"
        Case 226:          strResult = strResult + " Internal fault"
        Case 231:          strResult = strResult + " Hardware fault"
        Case 233:          strResult = strResult + " Sin_serv.exe Not started"
        Case 234:          strResult = strResult + " Protected"
        Case 240:          strResult = strResult + " Scp db file does Not exist"
        Case 241:          strResult = strResult + " No global dos storage available"
        Case 242:          strResult = strResult + " Error during transmission"
        Case 243:          strResult = strResult + " Error during reception"
        Case 244:          strResult = strResult + " Device does Not exist"
        Case 245:          strResult = strResult + " Incorrect sub system"
        Case 246:          strResult = strResult + " Unknown code"
        Case 247:          strResult = strResult + " Buffer too small"
        Case 248:          strResult = strResult + " Buffer too small"
        Case 249:          strResult = strResult + " Incorrect protocol"
        Case 251:          strResult = strResult + " Reception error"
        Case 252:          strResult = strResult + " Licence error"
        Case 257:          strResult = strResult + " Connection not established / parameterised"
        Case 266:          strResult = strResult + " Negative ackNowledgement received / timeout error"
        Case 268:          strResult = strResult + " Data does not exist or disabled"
        Case 298:          strResult = strResult + " System storage no longer available"
        Case 302:          strResult = strResult + " Incorrect parameter"
        Case 306:          strResult = strResult + " No memory in DPRAM"
        Case 513:          strResult = strResult + " Incorrect interface specified"
        Case 514:          strResult = strResult + " Maximum amount of interfaces exceeded"
        Case 515:          strResult = strResult + " PRODAVE already initialised"
        Case 516:          strResult = strResult + " Wrong parameter list"
        Case 517:          strResult = strResult + " PRODAVE Not initialised"
                           'if not open prodave
                           gstrPlcstrAdrTable = Chr(2) + Chr(0) + Chr(2) + Chr(0)
                           vntRep = load_tool(1, "S7ONLINE", gstrPlcstrAdrTable)
                           vntRep = new_ss(1)
                         
        Case 518:          strResult = strResult + " Handle cannot be set"
        Case 519:          strResult = strResult + " Data segment cannot be disabled"
        Case 768:          strResult = strResult + " Initialisiation error"
        Case 769:          strResult = strResult + " Initialisiation error"
        Case 770:          strResult = strResult + " Block too small, DW does not exist"
        Case 771:          strResult = strResult + " Block limit exceeded, correct amount"
        Case 784:          strResult = strResult + " No HW found"
        Case 785:          strResult = strResult + " HW defective"
        Case 786:          strResult = strResult + " Incorrect config param"
        Case 787:          strResult = strResult + " Incorrect baud rate / interrupt vector"
        Case 788:          strResult = strResult + " HSA parameterised incorrectly"
        Case 789:          strResult = strResult + " MPI address error"
        Case 790:          strResult = strResult + " HW device already allocated"
        Case 791:          strResult = strResult + " Interrupt not available"
        Case 792:          strResult = strResult + " Interrupt occupied"
        Case 793:          strResult = strResult + " Sap Not occupied"
        Case 794:          strResult = strResult + " No remote station found"
        Case 795:          strResult = strResult + " Internal error"
        Case 796:          strResult = strResult + " System error"
        Case 797:          strResult = strResult + " Error Buffer size"
        Case 800:          strResult = strResult + " Hardware fault"
        Case 801:          strResult = strResult + " DLL function error"
        Case 816:          strResult = strResult + " Version conflict"
        Case 817:          strResult = strResult + " Error COM config"
        Case 818:          strResult = strResult + " Hardware fault"
        Case 819:          strResult = strResult + " COM Port not configured"
        Case 820:          strResult = strResult + " COM Port not available"
        Case 821:          strResult = strResult + " Serial drv in use"
        Case 822:          strResult = strResult + " No connection"
        Case 823:          strResult = strResult + " Job rejected"
        Case 896:          strResult = strResult + " Internal error"
        Case 897:          strResult = strResult + " Hardware fault"
        Case 898:          strResult = strResult + " No driver or device found"
        Case 900:          strResult = strResult + " No driver or device found"
        Case 1023:         strResult = strResult + " System fault"
        Case 2048:         strResult = strResult + " Toolbox occupied"
        Case 16385:        strResult = strResult + " Connection not known"
        Case 16386:        strResult = strResult + " Connection not established"
                           'if lngNot open prodave
                           gstrPlcstrAdrTable = Chr(2) + Chr(0) + Chr(2) + Chr(0)
                           vntRep = load_tool(1, "S7ONLINE", gstrPlcstrAdrTable)
                           vntRep = new_ss(1)
                    
        Case 16387:        strResult = strResult + " Connection is being established"
        Case 16388:        strResult = strResult + " Connection broken down"
        Case 32768:        strResult = strResult + " Function already actively occupied"
        Case 32769:        strResult = strResult + " Not allowed in this operating status"
        Case 33025:        strResult = strResult + " Hardware fault"
        Case 33027:        strResult = strResult + " Object access not allowed"
        Case 33028:        strResult = strResult + " Context is not supported"
        Case 33029:        strResult = strResult + " Invalid address"
        Case 33030:        strResult = strResult + " Type (data type) not supported"
        Case 33031:        strResult = strResult + " Type (data type) not consistent"
        Case 33034:        strResult = strResult + " Object does not exist"
        Case 33537:        strResult = strResult + " Memory slot on CPU not sufficient"
        Case 33796:        strResult = strResult + " Grave error"
        Case 34048:        strResult = strResult + " Incorrect PDU size"
        Case 34562:        strResult = strResult + " Address invalid"
        Case 53761:        strResult = strResult + " Syntax error block name"
        Case 53762:        strResult = strResult + " Syntax error function parameter"
        Case 53763:        strResult = strResult + " Syntax error block type"
        Case 53764:        strResult = strResult + " No linked block in storage medium"
        Case 53765:        strResult = strResult + " Object already exists"
        Case 53766:        strResult = strResult + " Object already exists"
        Case 53767:        strResult = strResult + " Block exists in EPROM"
        Case 53769:        strResult = strResult + " Block does not exist"
        Case 53774:        strResult = strResult + " No block available"
        Case 53776:        strResult = strResult + " Block number too big"
        Case 53825:        strResult = strResult + " Protection level of function not sufficient"
        Case 54278:        strResult = strResult + " Information not available"
        Case 61185:        strResult = strResult + " Incorrect ID2"
        Case 65531:        strResult = strResult + " TeleService Library not found"
        Case 65534:        strResult = strResult + " Unknown error FFFE hex"
        Case 65535:        strResult = strResult + " Timeout error. Check interface"
    End Select
    MsgBox "  " & strResult
   Error_Message = strResult
     
End If
Error_Message = ""
End Function

Function ReadInput(strInputnumber As String) As Boolean


' format strInputnumber   : "4.1"  ou "40.1" ou "140.1"


Dim lngNo As Long, lngAmount As Long
Dim intBuffer(0) As Integer
Dim intBitnumber As Integer




lngNo = Mid(strInputnumber, 1, Len(strInputnumber) - 2)
lngAmount = 1
intBitnumber = Mid(strInputnumber, Len(strInputnumber), 1)
Error_Message (e_field_read(lngNo, lngAmount, intBuffer(0)))




ReadInput = intBuffer(0) And (2 ^ intBitnumber)


End Function
Function ReadOutput(strOutputnumber As String) As Boolean


' format strOutputnumber   : "4.1"  ou "40.1" ou "140.1"


Dim lngNo As Long, lngAmount As Long
Dim intBuffer(0) As Integer
Dim intBitnumber As Integer




lngNo = Mid(strOutputnumber, 1, Len(strOutputnumber) - 2)
lngAmount = 1
intBitnumber = Mid(strOutputnumber, Len(strOutputnumber), 1)
Error_Message (a_field_read(lngNo, lngAmount, intBuffer(0)))




ReadOutput = intBuffer(0) And (2 ^ intBitnumber)


End Function
Function WriteOutput(strOutputnumber As String, blnSetReset As Boolean) As Boolean


' format strOutputnumber   : "4.1"  ou "40.1" ou "140.1"




Dim lngNo As Long, lngAmount As Long
Dim intBuffer(0) As Integer
Dim intBitnumber As Integer




lngNo = Mid(strOutputnumber, 1, Len(strOutputnumber) - 2)
lngAmount = 1
intBitnumber = Mid(strOutputnumber, Len(strOutputnumber), 1)


'read actual value
Error_Message (a_field_read(lngNo, lngAmount, intBuffer(0)))




'Write new Value
If blnSetReset = True Then
    intBuffer(0) = intBuffer(0) Or (2 ^ intBitnumber)
    'Error_Message (a_field_write(lngNo, lngAmount, intBuffer(0)))
    If Error_Message(a_field_write(lngNo, lngAmount, intBuffer(0))) <> "" Then
         WriteOutput = False
    Else
        WriteOutput = True
    End If
End If


If (blnSetReset = False) And ((intBuffer(0) And (2 ^ intBitnumber)) <> 0) Then
    intBuffer(0) = intBuffer(0) Xor (2 ^ intBitnumber)
    'Error_Message (a_field_write(lngNo, lngAmount, intBuffer(0)))
    If Error_Message(a_field_write(lngNo, lngAmount, intBuffer(0))) <> "" Then
        WriteOutput = False
    Else
        WriteOutput = True
    End If
 End If


End Function




Function readchar(lngDbNo As Long, lngDwNo As Long, lngAmount As Long) As String


Dim intBuffer(27) As Integer
Dim strBit_0_15, strBit_16_31 As String
Dim lngCounter As Long


Error_Message (db_read(lngDbNo, lngDwNo, lngAmount, intBuffer(0)))
readchar = ""
lngCounter = 0
Do While lngCounter < lngAmount  ' Inner loop.
    strBit_16_31 = Hex(intBuffer(lngCounter))    If Len(strBit_16_31) 3 Then strBit_16_31 "0" + strBit_16_31    If Len(strBit_16_31) 2 Then strBit_16_31 "00" + strBit_16_31    If Len(strBit_16_31) 1 Then strBit_16_31 "000" + strBit_16_31
    strBit_0_15 = Hex(intBuffer(lngCounter + 1))    If Len(strBit_0_15) 3 Then strBit_0_15 "0" + strBit_0_15    If Len(strBit_0_15) 2 Then strBit_0_15 "00" + strBit_0_15    If Len(strBit_0_15) 1 Then strBit_0_15 "000" + strBit_0_15
    readchar = readchar + Chr("&H" + Mid(strBit_16_31, 3, 2)) + Chr("&H" + Mid(strBit_16_31, 1, 2)) + Chr("&H" + Mid(strBit_0_15, 3, 2)) + Chr("&H" + Mid(strBit_0_15, 1, 2)) 'SWAP
    lngCounter = lngCounter + 2   ' Increment Counter.
Loop
End Function




Function WriteMemo(strMemoNumber As String, ByVal blnSetReset As Boolean) As Boolean


' format strMemonumber   : "4.1"  ou "40.1" ou "140.1"




Dim lngNo As Long, lngAmount As Long
Dim intBuffer(0) As Integer
Dim intBitnumber As Integer




lngNo = Mid(strMemoNumber, 1, Len(strMemoNumber) - 2)
lngAmount = 1
intBitnumber = Mid(strMemoNumber, Len(strMemoNumber), 1)


'read actual value
Error_Message (m_field_read(lngNo, lngAmount, intBuffer(0)))


 


'Write new Value
If blnSetReset = True Then
    intBuffer(0) = intBuffer(0) Or (2 ^ intBitnumber)
    'Error_Message (m_field_write(lngNo, lngAmount, intBuffer(0)))
    If Error_Message(m_field_write(lngNo, lngAmount, intBuffer(0))) <> "" Then
        WriteMemo = False
    Else
        WriteMemo = True
    End If
End If


If (blnSetReset = False) And ((intBuffer(0) And (2 ^ intBitnumber)) <> 0) Then
    intBuffer(0) = intBuffer(0) Xor (2 ^ intBitnumber)
    'Error_Message (m_field_write(lngNo, lngAmount, intBuffer(0)))
    If Error_Message(m_field_write(lngNo, lngAmount, intBuffer(0))) <> "" Then
        WriteMemo = False
    Else
        WriteMemo = True
    End If
 End If


End Function


 


Function ReadMemo(strMemoNumber As String) As Boolean


' format strMemonumber   :  "4.1"  ou "40.1" ou "140.1"


Dim lngNo As Long, lngAmount As Long
Dim intBuffer(0) As Integer
Dim intBitnumber As Integer




lngNo = Mid(strMemoNumber, 1, Len(strMemoNumber) - 2)
lngAmount = 1
intBitnumber = Mid(strMemoNumber, Len(strMemoNumber), 1)
Error_Message (m_field_read(lngNo, lngAmount, intBuffer(0)))




ReadMemo = intBuffer(0) And (2 ^ intBitnumber)


End Function
Commenter la réponse de cs_dvp

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.