ScriptName "Transparent I/O" ScriptAuthor "(dA) " ScriptVersion "V 1.1" // 30.10.02 V 1.0 create for UNIGATE IC and basis board // 02.07.04 V 1.1 modified for DeviceNet SetErrorHandler ( :AddressLable1 ) ; var vb_error : Byte ; Var b : BUFFER [10]; // die buffer sind linear hintereinander angereit Var b1 : BUFFER [90]; Var s : BUFFER [10]; Var s1 : BUFFER [90]; Var k : BUFFER [10]; Var k1 : BUFFER [90]; var test : byte ; var size : word; moveconst (size, 1); var time : word ; moveconst (time, 10); var vb_ErCo : byte ; var v2 : byte ; var vbcx00 : byte ; moveconst ( vbcx00 , 0x00 ) ; var vwcx00 : word ; moveconst ( vwcx00 , 0x00 ) ; var vbcx01 : byte ; moveconst ( vbcx01 , 0x01 ) ; var vwcx01 : word ; moveconst ( vwcx01 , 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 wtemp : word ; Set ( Baudrate , 9600 ) ; Set ( Databits , 8 ) ; Set ( Startbits , 1 ) ; Set ( Parity , none ) ; Set ( ShiftRegisterInputType , RiseClock_LowLoad ) ; Set ( ShiftRegisterOutputType , RiseClock_RiseLoad ) ; Set ( ShiftRegisterInputBitLength , 16 ) ; Set ( ShiftRegisterOutputBitLength , 8 ) ; WriteShiftRegister ( vbcxFF ) ; // 0 WriteShiftRegister ( vbcxFE ) ; // 1 WriteShiftRegister ( vbcxFD ) ; // 2 WriteShiftRegister ( vbcxFB ) ; // 3 WriteShiftRegister ( vbcxF7 ) ; // 4 WriteShiftRegister ( vbcxEF ) ; // FB State rt WriteShiftRegister ( vbcxDF ) ; // FB State gn WriteShiftRegister ( vbcxBF ) ; // RS State gn WriteShiftRegister ( vbcx7F ) ; // RS State rt //****************************************************************************** // Init with the following call call :Init_ICDN_Basis; // or fix Set ( FieldbusID , 1 ) ; // set the fieldbus ID Set ( BusBaudrate , 125000 ) ; Set ( BusInputSize , 8 ) ; Set ( BusOutputSize , 8 ) ; //****************************************************************************** Set(VendorID, 272); // VendCode = 272; Set(DeviceType, 12); // ProdType = 12; Set(DeviceRevision, 0x021E); // 02 = MajRev=2, 1E=MinRev=30 Set(ProductCode, 0x1234); // 0x1234 => 4660 decimal call :SetLedsOff ; call :Set_RS_State_LED_StaticRed ; var bBusIn : byte; var wBusIn : word; var bBusOut : byte; var wBusOut : word; var len_rs_in : byte ; var last_len_rs_in : byte; BusStart ; Wait ( Bus_Active ) ; Get ( BusInputSize , bBusIn ) ; Get ( BusOutputSize , bBusOut ) ; Convert ( bBusIn , Byte , wBusIn , Word ) ; Convert ( bBusOut , Byte , wBusOut , Word ) ; :start ; // RS receive ? Copy ( len_rs_in , last_len_rs_in , vwcx01 ) ; Get ( NumberRSInputCharacter , len_rs_in ) ; if len_rs_in equal vbcx00 then :read_bus ; if len_rs_in notequal last_len_rs_in then :read_bus; Convert ( len_rs_in , Byte , wtemp , Word ) ; // count of RS receive ReceiveSomeCharRS( time, s[0], wtemp ); // and store in RS-InBuf //write to the bus WriteBus ( s[0] , wBusOut ) ; moveconst (len_rs_in, 0); :read_bus ; WaitBusDataChanged ( time , wBusIn ) ; Get ( errorCode , vb_ErCo ) ; if vb_ErCo equal vbcx02 then :start; //Get ( availableBusData , wtemp ) ; //if wtemp equal vwcx00 then :start; ReadBus ( b[0] , wBusIn ) ; //Get ( errorCode , vb_ErCo ) ; //if vb_ErCo equal vbcx00 then :write_rs else :start; :write_rs; SendRS( b[0], wBusIn ) ; call :Set_RS_State_LED_StaticGreen ; jump :start; :AddressLable1 ; Get ( ErrorCode , vb_error ) ; if vb_error less vbcx10 then :ShowNo else :NoShow ; :ShowNo ; //?CalculateByte ( vb_error , v2 , not , vb_error ) ; WriteShiftRegister ( vb_error ) ; :NoShow ; // TBD user evaluation for the value of Errorcode return ; :Set_RS_State_LED_StaticRed ; WriteShiftRegister ( vbcx7F ) ; return ; :Set_RS_State_LED_StaticGreen ; WriteShiftRegister ( vbcxBF ) ; return ; :SetLedsOff ; WriteShiftRegister ( vbcxFF ) ; return ; :Init_ICDN_Basis; var vw_Baud :word ; var vw_fieldbusID :word ; var vw_fbSwitch :word ; var vl_fieldbusID :long ; var vwc0 :word ; moveconst ( vwc0 , 0 ) ; var vwc1 :word ; moveconst ( vwc1 , 1 ) ; var vwc4 :word ; moveconst ( vwc4 , 4 ); var vwc64 :word ; moveconst ( vwc64 , 64 ) ; var vwc128 :word ; moveconst ( vwc128 , 128 ) ; var vwcx3F :word ; moveconst ( vwcx3F , 0x3F ) ; var vwcxC0 :word ; moveconst ( vwcxC0 , 0xC0 ) ; Set ( ShiftRegisterInputType , RiseClock_LowLoad ) ; Set ( ShiftRegisterInputBitLength , 16 ) ; Set ( ShiftRegisterOutputType , RiseClock_RiseLoad ) ; Set ( ShiftRegisterOutputBitLength , 8 ) ; ReadShiftRegister ( vw_fbSwitch ) ; CalculateByte ( vw_fbSwitch , vwc1 , not , vw_fbSwitch ) ; // Hardware ist low aktiv CalculateByte ( vw_fbSwitch , vwc4 , rol , vw_fbSwitch ) ; // oben Links Baudrate: 7 6 ; CO ID: 5 4 3 2 1 0 :Set_CO_Init ; Set ( BusInputSize , 8 ) ; Set ( BusOutputSize , 8 ) ; :CO_SwapNibble; CalculateByte ( vw_fbSwitch , vwcx3F , and , vw_fieldbusID ) ; // ID Mask CalculateByte ( vw_fbSwitch , vwcxC0 , and , vw_Baud ) ; // CO Baudrate call :CO_SetFieldbusID ; call :CO_SetBaudrate ; return; //**************************** :CO_SetFieldbusID ; if vw_fieldbusID greater vwc0 then :CheckLess64 else :TestMode ; :CheckLess64 ; if vw_fieldbusID less vwc64 then :SetIDfromSwitch else :TestMode ; :SetIDfromSwitch ; Convert ( vw_fieldbusID , word , vl_fieldbusID , Long ) ; SetByVar ( FieldbusID , vl_fieldbusID ) ; // must be a long type jump :EndID_Init ; :TestMode ; if vw_fieldbusID equal vwc0 then :SetIDto1 else :EndID_Init ; :SetIDto1 ; Set ( FieldbusID , 1 ) ; :EndID_Init ; return ; //************************* //************************* :CO_SetBaudrate ; if vw_Baud equal vwc0 then :SetBaud_1_Mbaud else :CheckBaud_500_kbaud ; :SetBaud_1_Mbaud ; Set ( BusBaudrate, 1000000 ); // CANopen only jump :SetBaudrateEnd ; :CheckBaud_500_kbaud ; if vw_Baud equal vwc64 then :SetBaud_500_kbaud else :CheckBaud_250_kbaud ; :SetBaud_500_kbaud ; Set ( BusBaudrate, 500000 ); // CANopen, DeviceNet jump :SetBaudrateEnd ; :CheckBaud_250_kbaud ; if vw_Baud equal vwc128 then :SetBaud_250_kbaud else :SetBaud_125_kbaud ; :SetBaud_250_kbaud ; Set ( BusBaudrate, 250000 ); // CANopen, DeviceNet jump :SetBaudrateEnd ; :SetBaud_125_kbaud ; Set ( BusBaudrate, 125000 ); // CANopen, DeviceNet :SetBaudrateEnd ; return ; //*************************