// This script needs a hardware which is capable of running DPV1 // you will receive errors if your hardware does not support DPV1 ScriptName "DPV1" ScriptVersion "V 1.0" // V1.0 für SC ScriptAuthor "dA" // V 1.0 Drehschalter Test geändert, bei ungerade keine Diagnose wenn gerade Diagnose No 6 // V 1.0 FB ID fest auf 4 // defining some variables Var a_DPV1Buffer : BUFFER[200] ; Var a_DPV1Updated : BUFFER[5] ; Var b_Const0: BYTE; MoveConst ( b_Const0 , 0 ) ; Var b_Const1: BYTE; MoveConst ( b_Const1 , 1 ) ; Var b_Const80: BYTE; MoveConst ( b_Const80 , 80 ) ; Var bErrorLen: BYTE; MoveConst ( bErrorLen , 10 ) ; Var lConst1000: LONG; MoveConst ( lConst1000, 1000) ; Var ErrorString: BUFFER[10]; MoveConst ( ErrorString[0], "! Error ! "); Var Timer1ms: LONG; Var NewCyclData: BYTE; Var CyclBusData: BUFFER[244]; Var CyclBusLen: WORD; Var bCyclBusLen: byte; var Timeout: word ; moveconst ( Timeout , 10 ); var ReceiveData: buffer[100]; var NumberCharToReceive: word ; moveconst ( NumberCharToReceive, 80); var ReturnCode: byte ; var vw_DestOffset: word ; var bc0: byte; moveconst ( bc0, 0); var wc0: word; moveconst ( wc0, 0); var wc1: word; moveconst ( wc1, 1); var vb_rx_char: byte; var resBuf: buffer[20]; var bc1: byte ; moveconst ( bc1, 1); var vbcx00 : byte ; moveconst ( vbcx00 , 0x00 ) ; var vbcx01 : byte ; moveconst ( vbcx01 , 0x01 ) ; var vbcx02 : byte ; moveconst ( vbcx02 , 0x02 ) ; // ... // Warning: timout var vbcx04 : byte ; moveconst ( vbcx04 , 0x04 ) ; var vbcx08 : byte ; moveconst ( vbcx08 , 0x08 ) ; var vbcx10 : byte ; moveconst ( vbcx10 , 0x10 ) ; var vbcx20 : byte ; moveconst ( vbcx20 , 0x20 ) ; var vbcx40 : byte ; moveconst ( vbcx40 , 0x40 ) ; var vbcx80 : byte ; moveconst ( vbcx80 , 0x80 ) ; var vbcxFF : byte ; moveconst ( vbcxFF , 0xFF ) ; var vbcxFE : byte ; moveconst ( vbcxFE , 0xFE ) ; var vbcxFD : byte ; moveconst ( vbcxFD , 0xFD ) ; var vbcxFB : byte ; moveconst ( vbcxFB , 0xFB ) ; var vbcxF7 : byte ; moveconst ( vbcxF7 , 0xF7 ) ; var vbcxEF : byte ; moveconst ( vbcxEF , 0xEF ) ; var vbcxDF : byte ; moveconst ( vbcxDF , 0xDF ) ; var vbcxBF : byte ; moveconst ( vbcxBF , 0xBF ) ; var vbcx7F : byte ; moveconst ( vbcx7F , 0x7F ) ; var RxSync : buffer[10] ; var vltemp : long ; var v2 : byte ; var vbsw1: byte; var btemp: byte; var wtemp: word; var bDestination : byte ; // Installing the Errorhandler to make the script more safe SetErrorHandler ( :ErrorHandler ) ; Set ( warningTime , 10000 ) ; // create 2 DPV1 Objects // Nr Slot Idx Len DataBuffer Update Flag InitDPV1Object ( 1 , 0 , 0 , 80 , a_DPV1Buffer[0] , a_DPV1Updated[0] ) ; InitDPV1Object ( 2 , 0 , 1 , 80 , a_DPV1Buffer[80] , a_DPV1Updated[1] ) ; //InitDPV1Object ( 3 , 1 , 0 , 80 , a_DPV1Buffer[160] , a_DPV1Updated[2] ) ; //InitDPV1Object ( 4 , 1 , 1 , 80 , a_DPV1Buffer[240] , a_DPV1Updated[3] ) ; //InitDPV1Object ( 5 , 2 , 2 , 80 , a_DPV1Buffer[320] , a_DPV1Updated[4] ) ; Set ( RS_State_LED , StaticRed ) ; // only for SC // Starting profibus BusStart ; Wait ( Bus_Active ) ; // Read activ Buslength Get ( BusInputSize , bCyclBusLen ) ; Convert ( bCyclBusLen , Byte , CyclBusLen , Word ) ; Get ( RS_Switch , bDestination ) ; Convert ( bDestination , Byte , vbsw1 , Word ) ; :Endlos; // for normal cyclic data just reply all bus data // this relies on InputSize equals outputsize!!! Get ( BusDataChanged , NewCyclData ) ; //if NewCyclData equal b_Const0 then :CheckTimer ; if NewCyclData equal b_Const0 then :CheckRSRRx ; ReadBus ( CyclBusData[0] , CyclBusLen ) ; //WriteBus ( CyclBusData[0] , CyclBusLen ) ; // RS Data empfangen, wenn ja auf Objekt 2 ausgeben // Check if RS-Data available :CheckRSRRx; MoveConst(vw_DestOffset, 0); :ReadRS ;// Read always one char until timeout delay (100); ReceiveSomeCharRS ( Timeout , vb_rx_char , wc1) ; Get ( ErrorCode , ReturnCode ) ; if ReturnCode equal bc0 then :SaveRxChar else :CopyRSDataToObj2 ; :SaveRxChar ; CopyIndexed ( wc1 , vb_rx_char , wc0 , a_DPV1Buffer[80] , vw_DestOffset ) ; CalculateWord ( vw_DestOffset , wc1 , add , vw_DestOffset ) ; jump :ReadRS ; :CopyRSDataToObj2 ; WriteBus ( a_DPV1Buffer[80] , CyclBusLen ) ; call:ReadSW1changed; //**************** //:CheckTimer; // increment byte 1 in Object 1 every second Get ( Timer , Timer1ms ) ; if Timer1ms less lConst1000 then :CheckObjects ; Set ( Timer , 0 ) ; CalculateByte ( a_DPV1Buffer[0] , wc1 , add , a_DPV1Buffer[0] ) ; SendRS ( CyclBusData[0] , CyclBusLen ) ;// Daten im Sekunden Takt ausgeben :CheckObjects ; // check if one object has changed, new SPS DPV1 data received if a_DPV1Updated[0] notequal b_Const0 then :UpdateObject1 ; if a_DPV1Updated[1] notequal b_Const0 then :UpdateObject2 ; //if a_DPV1Updated[2] notequal b_Const0 then :UpdateObject3 ; //if a_DPV1Updated[3] notequal b_Const0 then :UpdateObject4 ; //if a_DPV1Updated[4] notequal b_Const0 then :UpdateObject5 ; jump :Endlos ; // process changed DPV1 object :UpdateObject1 ; MoveConst(a_DPV1Updated[0], 0 ); SendRS ( a_DPV1Buffer[0] , b_Const80 ) ; jump :Endlos ; :UpdateObject2 ; MoveConst(a_DPV1Updated[1], 0); SendRS ( a_DPV1Buffer[80] , b_Const80 ) ; jump :Endlos ; :ErrorHandler ; SendRS(ErrorString[0], bErrorLen); Return ; :ReadSW1changed; Get ( RS_Switch , bDestination ) ; Convert ( bDestination , Byte , vbsw1 , Word ) ; CalculateByte ( vbsw1 , wc1 , and , wtemp ) ; //CalculateByte ( RxSync[1] , v2 , not , RxSync[1] ) ; // invert //CalculateByte ( RxSync[0] , vbcx04 , rol , RxSync[0] ) ; // swap nibble //if RxSync[1] equal vbsw1 then :nochange; if wtemp equal wc0 then :nochange; //Copy ( RxSync[1] , vbsw1 , wc1 ) ; Set ( SystemError , 6 ) ; return; :nochange ; Set ( SystemError , 0 ) ; return;