Serial communication in Twincat 2.0

aspen

Member
Join Date
May 2013
Location
Got
Posts
4
HI,

I'm working with Beckhoff CX5020 series PLC and I'm using Serial ComLibV2 library for serial communication(RS422).

The problem I have is I want to send a constant string NOT time based but event based i.e : If I receive a HIGH on a digital input then I will send this packet over the serial port to the other device. It can be 100 times in a second that this event happens, but every time I need to make sure that I'm sending the string once.

This might sound stupid our simple to you but I could not find how to do this in Twincat. should I use a Trigger(R_TRIGG)? in my code or should I monitor the BUSY flag of the send function? I'm receiving as many as 10 packets(XpingX) on the other device sometimes.

Here is a sample code of what I have:

IF SendTrigger THEN

CASE SendStpes OF
0:
;
1:
LED_Signal:=FALSE;

Send(SendString:= 'XpingX',
TXbuffer:= TxBuffer1,
Busy=> SendBusy,
Error=> SendErrorID);

IF NOT(SendBusy) THEN
SendStpes :=2;
END_IF

2:
;
END_CASE;

This is the Global variable definitions:

COMin_EL62xx AT %I* :EL6inData22B ;
COMout_EL62xx AT %Q* : EL6outData22B;

RxBuffer1: ComBuffer;
TxBuffer1: ComBuffer;

Send: SendString;
SendBusy: BOOL;
SendErrorID: ComError_t;

I also have a "fast_task" running in the background(faster than the main program cycle) that takes care of sending and receiving packets.

Cheers,
 
keep packets small with 100 events /second at 9600 baud max 10 characters
make array with strings to send (this way you can get asyncrin events
if message is sent do next one.
check both counters for collision (meaning too much to send
do not shift array but use pointers.
so you wil have two event driven tasks 1 get event and another send packet.
 
Hi Paul,

Thanks for your answer. I'm using 115200 baud so I don't think I have reached the limit of the sending packets yet.
What I'm asking is how would you make sure that when I call "Send" my packet is sent and only once not 10 times!. I'm using Switch case in this example and it is a state machine but somehow I get multiple packets on the other side.It is not always!
It would be really nice if you have a sample code of what you explained as your answer is more general and I really need to see an implementation to get inspired.

Thanks again :)
 
as i said in my other message, you need two separate tasks, one for receiving the sendtrigger and yes you have to do this with R_TRIG (you also have to see if the contact can bounce (this is giving more pulses / closure, depending on type of inputcard).
And a task for making a sendrequest.
However if the sending is still busy and you get a trigger you will have to save this in an array and when busy is gone get the next message out of the array.
to test above make the message dependant of the trigger thus
trigger=001, next trigger is trigger002 etc. the ping should be trigger001ping002 or any number active at the time.
Both of these tasks are event driven. your PLC_PRG is best timed, this way you can find out how fast is needed.
For this is best to have the tasks as slow as needed.
you can divide several in several tasks, like scanning inputs need to be fast, however setting outputs could be slower. etc
 

Similar Topics

Good morning everyone, This is my first post here. I am beginning my journey on PLC programming and still a really newbie, I want to write a...
Replies
0
Views
1,254
Hello guys! If anybody has any experience with serial communication in TwinCAT with Beckhoffs PLCs, would be really helpful. I Have: - CX2020...
Replies
9
Views
5,023
Good morning all! ( at least fo he ones living around the GMT+1 area:P) Im having some problems with my program while using serial...
Replies
2
Views
2,294
Currently,we are facing the communication go through with 422 tx+ and tx-. Mitsubishi fx5u series is used and using command rs2. But the package...
Replies
0
Views
103
I have wasted a week trying to figure out how to connect an SLC5/03 with my laptop. I do not have and can not Buy the 1747 UIC and PC3 cables. I...
Replies
14
Views
2,555
Back
Top Bottom