Serial Communication - EL 6001 in TwinCAT

tech007
2010-11-10
2011-01-12
  • tech007 - 2010-11-10

    Hello Friends,

    I am new to this forum. And I am new to field of programming of PLC as well. I used Allen Bradley before some years back and now, i have to use Beckhoff PLC for my research work.

    I like to read the data from external device for the temperature control. I like to read the data through RS 242 port in Beckhoff PLC. The sequence of this PLC (EK 1100 PLC driver,EL6001 Interface and KL 9010 End connector). As CPU,we are using Industrial PC from Beckhoff C69xx. We are using TwinCAT here with Ether CAT field bus.

    Can anybody help me to do programming with this ? Or guide me how to proccede with this task ?

    The programme is below. I can send and receive the sring but i can't read the temperature.I check the baudrate and other thing is all right. But still i can't read it.

    The code is mentioned below :


    Timer(IN:=TRUE, PT:=T#1s);
    IF Timer.Q OR Send.Busy THEN

    (Send( SendString:= '$02Hello World - $03',)
    Send( SendString:= 'S1',
    TXbuffer:= TxBuffer1, ( see global variables )
    Busy=> SendBusy,
    Error=> SendErrorID);

    Timer(IN:=FALSE); ( reset timer )
    END_IF

    Receive(
    ( Prefix:= '$02',
    Suffix:= '$03',
    Prefix:= '$N',
    Suffix:= '$R',
    )
    Prefix:= '$0F',
    Suffix:= '$12',
    Timeout:= T#1s,
    ReceivedString:= ReceivedString,
    RXbuffer:= RxBuffer1,
    StringReceived=> StringReceived,
    Busy=> ReceiveBusy,
    Error=> ReceiveErrorID,
    RxTimeout=> ReceiveTimeout );
    IF StringReceived THEN
    ReceiveCounter := ReceiveCounter + 1;
    LastReceivedString := ReceivedString;
    END_IF

    COMportControl(

    Mode:= SERIALLINEMODE_EL6_22B,
    pComIn:= ADR(COMin_EL6001), ( I/O data; see global variables )
    pComOut:= ADR(COMout_EL6001), ( I/O data; see global variables )
    SizeComIn:= SIZEOF(COMin_EL6001), ( I/O data; see global variables )
    TxBuffer:= TxBuffer2, ( Transmit buffer; see global variables )
    RxBuffer:= RxBuffer2, ( Receive buffer; see global variables )
    Error=> COMportControlError,
    ErrorID=> COMportControlErrorID );


    Variables :

    RxBuffer2: ComBuffer; ( Receive data buffer; used with all receive function blocks )
    TxBuffer2: ComBuffer; ( Transmit data buffer; used with all receive function blocks )
    COMin_EL6001 AT %IB66 : KL6inData22B; (Linked with EL6001TwinCAT System Manager )
    COMout_EL6001 AT %QB66 : KL6outData22B;(Linked with EL6001TwinCAT System Manager )


    I all configure 22 bytes of Input and Output from the EL6001 Module. I want to take daata types EL6inData22B and EL6outData22B respectively
    but i am getting error that unknown type ??!!

    Help me out through this. It's quite urgent.

    Thanks in advance.

    Tech007

     
  • shooter - 2010-12-06

    unknown type is meaning you have a variable not declared correct.
    or the type is not in the datatypes list (could be coming from a library)

     
  • sampatheee - 2011-01-12

    Dear All,

    I am new this forum & also new for Codesys...i am going ask a doubt in serial interface

    We are doing serial communication between Wago 750-851 and TRILAS (is a Sensor).in this i have doubt on like i am closing and opening the port after receving expected(bytes) message from sensor this is correct are not or always i have to keep open the port...Please if anybody knew answer help me...

     
  • shooter - 2011-01-12

    it depends on the speed you are using, if you ask it every second then close comms every minute.to get rid of any mal bits.
    no it is not needed to close down a rs232 port, i2c and lots of industrial busses you will need to stop, to give others a change to talk, but in rs232 there is only one conection.
    just try it without closing as it will speed up the comms.

     
  • sampatheee - 2011-01-12

    ok i will try to do this way..

    if i want to change the hardware like now i am having 758-870 to 750- 841,is i need to change in software only library r anything else...

     
  • sampatheee - 2011-01-12

    For ur refernce i am attaching u my program.

    LaserOnTrigg(Clk:=HMI.TL1_LaserOnRq);

    IF LaserOnTrigg.Q THEN
    Sensor.TRILAS1LaserOnSet:=TRUE;
    END_IF;

    IF Sensor.TRILAS1LaserOnSet AND NOT TRILAS1Cmd4B_LASERON.Msg4BComm.SERIAL_INTERFACE.xCOM_PORT_IS_OPEN THEN
    OpenCOMPort4B:=TRUE;
    StartDataTransmit4B := FALSE;
    TRILAS1Cmd4B_LASERON(
    StartTransmit:=StartDataTransmit4B,
    OpenCOMPort:=OpenCOMPort4B,
    DeviceAddress:=HMI.TL1_DeviceAddress,
    COMAddressInData:=COM1AddressInData,
    COMAddressOutData:=COM1AddressOutData
    );
    ELSIF Sensor.TRILAS1LaserOnSet AND TRILAS1Cmd4B_LASERON.Msg4BComm.SERIAL_INTERFACE.xCOM_PORT_IS_OPEN THEN
    StartDataTransmit4B:=TRUE;
    TRILAS1Cmd4B_LASERON(
    StartTransmit:=StartDataTransmit4B,
    OpenCOMPort:=OpenCOMPort4B,
    DeviceAddress:=HMI.TL1_DeviceAddress,
    COMAddressInData:=COM1AddressInData,
    COMAddressOutData:=COM1AddressOutData
    );
    IF TRILAS1Cmd4B_LASERON.StartTransmit = FALSE THEN
    StartDataTransmit4B:=FALSE;
    Sensor.TRILAS1LaserOnSet := FALSE;
    END_IF;
    ELSIF NOT Sensor.TRILAS1LaserOnSet AND TRILAS1Cmd4B_LASERON.Msg4BComm.SERIAL_INTERFACE.xCOM_PORT_IS_OPEN THEN
    OpenCOMPort4B:=FALSE;
    StartDataTransmit4B:=FALSE;
    TRILAS1Cmd4B_LASERON(
    StartTransmit:=StartDataTransmit4B,
    OpenCOMPort:=OpenCOMPort4B,
    DeviceAddress:=HMI.TL1_DeviceAddress,
    COMAddressInData:=COM1AddressInData,
    COMAddressOutData:=COM1AddressOutData
    );
    END_IF;

     

Log in to post a comment.