scot

GX works 3 RS2 function

8 posts in this topic

Hello. - I'm sorry for my English - I'm a self-taught :)
Please help with the RS2 function ...
Request:
I need to send in ASCII timestamp in mm.ss format [minutes.seconds]

Problem
I am sending a single frame - but it is exposed from the back.

How to do to send time in given format. Time is counted from 10 minutes to 0.

simple code (just for a view):

 

IF send_data THEN
SM8561:=TRUE;
RS2(SM412,D400,D450,D470,K1,D800);

//D400 - Double word witch frame
//D450:=K7
//D470:=K0 // I DO NOT NEED TO RECEIVE ANY DATA

	S1M8561:=FALSE;
	send_data:=FALSE;
END_IF;

 

Share this post


Link to post
Share on other sites

So your question is how to convert an integer value to a string?

INT_TO_STRING(_E)

Edited by Gambit

Share this post


Link to post
Share on other sites

no.
Because I have to specify a DWORD variable of the following information:
variable declaration
D300: = H023130 // (# STX 1 0) (* minutes *)
D301: = H2e // (.) (* Dot *)
D302: = H323303 // (2 3 #ETX) (* seconds *)

Total 7 characters.

Next it should look like this

D400:=H0231302e;
D402:=H323303;

Then do something like ROL because after sending via RS485 I get everything back.

Share this post


Link to post
Share on other sites

What is your problem? It looks like you have setup the RS2 instruction to send data correctly. What is happening that is wrong? Maybe you can explain what is actually going wrong, and then explain what you want it to do?

Share this post


Link to post
Share on other sites

ok, sorry for the lack of concrete.
First question

how to make from

'12.34'

this: H31322e3334

next

how to make from

H31322e3334

this (addded stx etx and DW):

D400:=H0231322e;
D402:=H333403;

because sending D400 will display this on the terminal:

43.21

so how to make from:

D400:=H0231322e;
D402:=H333403;

this:

D400:=H0334332e;
D402:=H323102;

that is all

 

 

Share this post


Link to post
Share on other sites

The problem is the encoding/decoding of words/bytes. I don't know how the string is generated but you need to encode it differently before sending it to the terminal.

You need to swap the bytes/words. You need to do e.g. MOV to move around the words and then SWAP to do a rotation of the bytes. I would have a small area of variables for encoding purposes since you will need to shift around a little bit. I have just used some variables as an example below. This is not a complete code, just an example of how it can be solved, and is probably lacking some code also. But it gives you an idea of how to solve your issue. Note the MOV, DMOV and SWAP instructions.

First, take your raw data of minute/second H31323334 (e.g. in D300-D301):
MOV D300 D310 //I assume that the raw mm is in D300, and then move it to a temporary area (D310)
MOV D301 D311 //I assume that the raw ss is in D301, and then move it to a temporary area (D311)
SWAP D310 //Swaps the two bytes
SWAP D311 //Swaps the two bytes

... Insert your dot (H2e) where needed, then append STX/ETX.

At last:
DMOV D310 D400 //Moves the complete string into D400 which is the 'send' area

Share this post


Link to post
Share on other sites

Most of what you wrote is ok but the question is how to put H2e into MM and SS and also add STX and ETX - for me that is the biggest problem. how to ins

Share this post


Link to post
Share on other sites

I thought that you had the complete string already like you describe above (you say that you can already send 43.21)... How do you get this string today? Please write where you get the 43.21 from, and also where "12" and "34" comes from. Are you making this yourself? Are you getting them from a different system? What are they in the first place (INTs, STRINGs....)?

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