ScriptAuthor "Deutschmann Automation GmbH" ScriptName "FB-EN" ScriptVersion "V 1.1" // This script realized a script for our filedbus-fieldbus gateway // where one side is Ethernet // 19.07.04 V1.1 change RS Baudrate to 62500 // Declaration of Variable // VA_=Variable Array, VW_=Variable Word, VB_=Variable Byte Var VA_BusInput : BUFFER[1000] ; // max.Fieldbus-Length Var VA_BusOutput : BUFFER[1000] ; // max.Fieldbus-Length Var VW_BusInputLen: Word ; Var VW_BusOutputLen: Word ; Var VW_Timeout_ms: Word ; MoveConst (VW_Timeout_ms , 2) ; // 2ms Timeout => Wartezeit zwischen Datenblöcken Var VW_Const_0: Word ; MoveConst (VW_Const_0, 0); Var VW_Const_1: Word ; MoveConst (VW_Const_1, 1); Var vw_DestOffset: Word ; Var vb_ReturnCode: Byte ; Var VB_ErrorNr: Byte ; Var VB_NoError: Byte ; MoveConst (VB_NoError, 0) ; // Returncode 0 = No Error Var VB_BusLen: Byte ; Var VB_Const_0FH: Byte ; MoveConst (VB_Const_0FH, 0x0F); Var VB_Const_20H: Byte ; MoveConst (VB_Const_20H, 0x20); Var vb_TempB: Byte ; Var vb_rx_char: Byte ; // Errorhandler init => After Error, script will automatic jump to "Errorhandler" SetErrorHandler ( :ErrorHandler ) ; // Init serial port Set ( Baudrate , 62500 ) ; Set ( Databits , 8 ) ; Set ( Startbits , 1 ) ; Set ( Stopbits , 1 ) ; Set ( Parity , none ) ; Set ( ShiftRegisterOutputType , RiseClock_RiseLoad ) ; Set ( ShiftRegisterOutputBitLength , 8 ) ; MoveConst (VB_ErrorNr, 0x10 ) ; // 1xH = grün, x0H = All yellow LED's off Call :ErrorDisplay ; // Start Bus and wait until running BusStart ; Wait ( Bus_Active ) ; // Check if Busdata available :CheckNewBusData ; Get ( AvailableBusData , VW_BusInputLen ) ; if VW_BusInputLen equal VW_Const_0 then :NoBusData else :CopyBusDataToRS ; :CopyBusDataToRS ; ReadBus ( VA_BusInput[0] , VW_BusInputLen ) ; SendRS ( VA_BusInput[0] , VW_BusInputLen ) ; // State-LED = green; Yellow-LED's = Bus-Receive-Data-Len MoveConst (VB_ErrorNr, 0x10 ) ; // 1xH = grün, x0H = All yellow LED's off Convert ( vw_BusInputLen , Word , vb_TempB , Byte ) ; CalculateByte ( vb_TempB , VB_Const_0FH , and , VB_BusLen ) ; CalculateByte ( VB_ErrorNr , VB_BusLen , add , VB_ErrorNr ) ; Call :ErrorDisplay ; // Check if RS-Data available :NoBusData ; MoveConst(vw_DestOffset, 0); :ReadRS ; // Read always one char until timeout ReceiveSomeCharRS ( vw_Timeout_ms , vb_rx_char , vw_const_1) ; Get ( ErrorCode , vb_ReturnCode ) ; if vb_ReturnCode equal vb_NoError then :SaveRxChar else :CopyRSDataToBus ; :SaveRxChar ; CopyIndexed ( vw_const_1 , vb_rx_char , vw_const_0 , va_BusOutput[0] , vw_DestOffset ) ; CalculateWord ( vw_DestOffset , vw_const_1 , add , vw_DestOffset ) ; jump :ReadRS ; //Get ( NumberRSInputCharacter , vb_TempB ) ; //Convert ( vb_TempB , Byte , VW_BusOutputLen , Word ) ; //if VW_BusOutputLen equal VW_Const_0 then :NoRSData else :CopyRSDataToBus ; :CopyRSDataToBus ; //ReceiveSomeCharRS ( VW_Timeout_ms , VA_BusOutput[0] , vw_DestOffset ) ; WriteBus ( VA_BusOutput[0] , vw_DestOffset ) ; :NoRSData ; jump :CheckNewBusData ; // The following code will automaticly executed after a scriptcommand returns with error :ErrorHandler ; //MoveConst (VB_ErrorNr, 0x21 ) ; // xyH: x = 2 => rot, y = ErrorCode Get ( ErrorCode , vb_ReturnCode ) ; CalculateByte ( vb_ReturnCode , VB_Const_0FH , and , vb_ReturnCode ) ; CalculateByte ( vb_ReturnCode , VB_Const_20H , add , VB_ErrorNr ) ; Call :ErrorDisplay ; Return ; // Display "ErrorNr" on bicolor and yellow LEDs :ErrorDisplay ; WriteShiftRegister ( VB_ErrorNr ) ; Return ;