Sign in to follow this  
Followers 0
tech007

Serial Communication - EL 6001 in TwinCAT

5 posts in this topic

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

Share this post


Link to post
Share on other sites
What specifically is the error you are getting? How is it being reported to you? Is it when trying to build? Or are you getting an error from the Serial Port when you are running it? Anyway, your prefix and suffix arguments in your Receive FB are entered incorrectly. You appear to want the prefix to be an ASCII SI ($0F) and the suffix to be an ASCII DC ($12). But you've put in the strings for the hex values instead of the hex values themselves. For example, in terms of bytes, you want, $0F, for the prefix, but what you put in was, $24 $30 $46 (i.e. the byte values for the string '$0F')

Share this post


Link to post
Share on other sites
The error was : Undefined types. But after this, i spoke to Local Beckhoff PLC and realise that KL6InData22B and KL6OutData22B are having same image. So, doesn't matter identically. Regarding prefix and suffix, actually are wrong. I wil change it. But still, this is the sample programme to send and receive the string. It works fine. Main task i have is to read the temperature through RS 232 communication from temperature mesurment device. So, for that i am using only Receive string programme but it's not working. I spoke to beckhoff local support and they said everything is all right. Even, module (EL 6001) interface setting is also seems to be correct. But i am not getting data. BaudRate and time is also correct. I don't know why i can't detect data from temperature mesurment (Almemo 5690-2) ?!!! I mean even not in programme but also in Twin CAT System Manager i am not getting the data. That's quite shock for me. Because programme just manuplate or control the data from Twin CAT System Manager nothing more. Even module seems to be also all right. And i don't know how to define prefix or suffix for that device but if i don't define then technicall it's all right and data should come. Can you give me suggestion or tips regarding same ? Or if you have sample project to read temperature then it can be also great help. Please find the programme below : Thanking you. --------------------------------------------------------------------------------------------------------------------------------------- Timer(IN:=TRUE, PT:=T#1s); IF Timer.Q OR Receive.Busy THEN Receive( Prefix:= ' ', Suffix:= ' ', Timeout:= T#1s, ReceivedString:= ReceivedString, RXbuffer:= RxBuffer2, StringReceived=> StringReceived, Busy=> ReceiveBusy, Error=> ReceiveErrorID, RxTimeout=> ReceiveTimeout ); IF StringReceived THEN ReceiveCounter := ReceiveCounter + 1; LastReceivedString := ReceivedString; END_IF Timer(IN:=FALSE); (* reset timer *) END_IF IF StringReceived THEN b:= STRING_TO_BYTE('LastReceivedString'); END_IF (*================================================================== Background communication with EL6001 terminal *) 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 ); ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Share this post


Link to post
Share on other sites
I got again question regarding same. Now, finally the programme is runrining with small changes. I got strings from the Device which i am expecting. But i have problem that i don't want that whole string but i just want to read the temperature from it. I used some function of string but it's not working out. Programme find below : ---------------------------------------------------------------------------- Timer(IN:=TRUE, PT:=T#10s); IF Timer.Q THEN Receive( Prefix:= '< >', Suffix:= '< >', Timeout:= T#10s, ReceivedString:= ReceivedString, RXbuffer:= RxBuffer2, StringReceived=> StringReceived, Busy=> ReceiveBusy, Error=> ReceiveErrorID, RxTimeout=> ReceiveTimeout ); IF StringReceived =TRUE THEN ReceiveCounter := ReceiveCounter + 1; LastReceivedString := ReceivedString; diff_string := FIND ('ReceivedString','LastReceivedString'); concen := CONCAT ('ReceivedString','LastReceivedString'); change := MID ('LastReceivedString',6,31); END_IF END_IF ------------------------------------------------------------------------------ Variables : Receive: ReceiveString; ReceivedString: STRING; LastReceivedString: STRING; StringReceived: BOOL; ReceiveBusy: BOOL; ReceiveError: BOOL; ReceiveErrorID: ComError_t; ReceiveTimeout: BOOL; ReceiveCounter: UDINT; ------------------------------------------------------------------------------- This is the varibale which get the string from the device i.e.''LastReceivedString ''. But as you can see, MID function or CONCAT function are only actining on this varible Lable not Actual data from the device. For example, diff_string variable result ideally should find data diffrence from the both varible insted of that it is making diffrence of name for both varible not the actual data. I like to separate the Temperatue reading from the whole string which lengh is 81. Insten of that, this string function, will not act on this string rather than only label of LastReceviedString. Can you give idea how to take out or read out only selected data from the whole string ? I am using the same module as i mentioned before i.e. Ek1100 , EL 6010 and EL9010. Thanks.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0