Beckhoff twincat array

fgsotres

Member
Join Date
May 2011
Location
Mexico City
Posts
10
Hi,

Right now Im working with a Wenglor vision system connected to a Beckhoff PLC. From the camera im getting a string of measurement that i send it to the PLC via TCP/IP. The time rate of the measurement is 250 ms.

In the software, I want to take the measurement and create an array of strings in order to filter this information.
Now, my problem is that every cycle I get a string, the array is totally filled with the same string.

My code is the following:
[/SIZE]


Code:
VAR
	serie : STRING;
	var2: ARRAY[0..10] OF STRING;
        i: INT;
END_VAR

serie:=MAIN.fbClient1.sFromServer; *This is the string that i get from the camera
IF i <=10 
THEN
var2[i]:=serie;
i:=i+1;
ELSE
i:=0;
END_IF;

Any suggestion? :confused:
 
if this program is running continious the array will be filled very fast.
you will have to find a way to detect if a string is received. like testing on last character like newline etc.
if last character then do sequence.
 
Hi

[/SIZE]


Code:
VAR
	serie : STRING;
	var2: ARRAY[0..10] OF STRING;
        i: INT;
END_VAR

IF MAIN.fbClient1.bDataFromServer THEN
MAIN.fbClient1.bDataFromServer := FALSE;
serie:=MAIN.fbClient1.sFromServer; *This is the string that i get from the camera
IF i <=10 
THEN
var2[i]:=serie;
i:=i+1;
ELSE
i:=0;
END_IF;
END_IF;
Let me know if this works, or if you understands what I'm trying to accomplish.
 
Hi,
I really appreciate your posts and have used these options but the problem stills... The sequence is much faster than data.

I ve been checking regarding to this. Even I check the last character of the string, when the sequence starts, is very fast. Every time I get a string, the array is completely filled with the same string. It looks the PLC is fast enough. Im taking as polling time of the string every 250ms. The data came in this time but the PLC works much faster. Is there a way to time or synchronize somehow the adding of each element with the time of the data flow?

Thank you!!!!
 
You have to check for last character and then do sequence once.
so in the sequence there should be a flag that string is received.
then empty the inputstring.
 
You have to check for last character and then do sequence once.
so in the sequence there should be a flag that string is received.
then empty the inputstring.
I disagree. If you use the standard Beckhoff TCP/IP example program, then it is fairly easy.
In Function Block FB_LocalClient, the variable bDataFromServer indicates that a complete string has been received.
As I showed in my example program, you have to reset bDataFromServer when you read the string.
Look into this code from FB LocalClient:

CLIENT_STATE_DATAEXCHA_WAIT:
fbClientDataExcha( bExecute := FALSE );
IF NOT fbClientDataExcha.bBusy THEN
IF NOT fbClientDataExcha.bError THEN
sFromServer := fbClientDataExcha.sFromServer;
bDataFromServer := TRUE;
eStep := CLIENT_STATE_IDLE;
ELSE
(* possible errors are logged inside of fbClientDataExcha function block *)
nErrId := fbClientDataExcha.nErrId;
eStep := CLIENT_STATE_ERROR;
END_IF
END_IF
 
I disagree. If you use the standard Beckhoff TCP/IP example program, then it is fairly easy.
In Function Block FB_LocalClient, the variable bDataFromServer indicates that a complete string has been received.
As I showed in my example program, you have to reset bDataFromServer when you read the string.
Look into this code from FB LocalClient:

CLIENT_STATE_DATAEXCHA_WAIT:
fbClientDataExcha( bExecute := FALSE );
IF NOT fbClientDataExcha.bBusy THEN
IF NOT fbClientDataExcha.bError THEN
sFromServer := fbClientDataExcha.sFromServer;
bDataFromServer := TRUE;
eStep := CLIENT_STATE_IDLE;
ELSE
(* possible errors are logged inside of fbClientDataExcha function block *)
nErrId := fbClientDataExcha.nErrId;
eStep := CLIENT_STATE_ERROR;
END_IF
END_IF

Hi,
In fact Im using this code for the communication but theres a little difference with this code. I have no bDataFromServer variable in the code.
I understand what you want to do... but I dont have this variable and neither in the example from Beckhoff too.

Thank you!!!:confused:
 
Hi,
In fact Im using this code for the communication but theres a little difference with this code. I have no bDataFromServer variable in the code.
I understand what you want to do... but I dont have this variable and neither in the example from Beckhoff too.

Thank you!!!:confused:

I'm really sorry, I'm starting to remember I added this bDataFromServer myself :)
My code is 2 years old already.

If you add the bDataFromServer acknowledge mechanism, it's fairly easy to know when a string has arrived from the camera and when to process it in a higher level program.
 
I'm really sorry, I'm starting to remember I added this bDataFromServer myself :)
My code is 2 years old already.

If you add the bDataFromServer acknowledge mechanism, it's fairly easy to know when a string has arrived from the camera and when to process it in a higher level program.

I get it. I tried to used it with the first code you wrote but it doesn't let me because it says that it is a variable that can be written.
How does the code work?

Thank you!!!
 
Shooter was right (you have to check for the last char and then react) and Noli2 seems that have done this in the past and got it working.

So following their recommendations you should get it working without much hassle.

regarding how to write into a variable declared inside a Function block, you need to declare it as a VAR_INPUT or a VAR_IN_OUT, any normal or output variable won't be writable from outside the function block instance.

the same happens with a program.

PS: excuse any tipo, my internet explorer has decided that this message is being written in Spanish... :sigh:
 

Similar Topics

Hello All, I am trying to do something quite simple but not use to some of Twincat's instructions/syntax. I am programming in...
Replies
4
Views
21,023
Hi everyone, This is my first time posting, so please forgive any omissions or mistakes. I am attempting to control the velocity of a stepper...
Replies
18
Views
920
Hello, I was wondering if anyone know how to upload a PLC program to the Beckhoff TwinCAT 3 from a file? i.e. without having the development pc...
Replies
0
Views
729
Hi anyone got any tips and tricks?? I'm at a stage wherei need to tidy up my hmi project and give all objects sensible names, I did start this...
Replies
0
Views
946
Hello, I have a System running a beckhoff IPC with twincat 2 software on it, Also i have no original source code. Is it possible with the...
Replies
1
Views
1,263
Back
Top Bottom