S7 problem with setting bit in word using pointer

svdhorst

Member
Join Date
Mar 2009
Location
Eindhoven
Posts
4
Hi,

I know there already are a lot of threads about using pointer, but I can't find
the solution to my problem in any of them.

I'm trying to set a bit in a word using a pointer. The word is variable, so I made a pointer. The bit I want to set has an offset to the first bit in that word of 1.0. I tried this code:

L P##VARIABLE_WORD
LAR1
L W [AR1,P#0.0]
T #DBNR
OPN DB [#DBNR]
A #CONDITION
S DBX [AR1,P#1.0]

This doesn't work. I tried some other things, but nothing seems to work.
Please help!
 
Hi,

I know there already are a lot of threads about using pointer, but I can't find
the solution to my problem in any of them.

I'm trying to set a bit in a word using a pointer. The word is variable, so I made a pointer. The bit I want to set has an offset to the first bit in that word of 1.0. I tried this code:

L P##VARIABLE_WORD
LAR1
L W [AR1,P#0.0]
T #DBNR
OPN DB [#DBNR]
A #CONDITION
S DBX [AR1,P#1.0]

This doesn't work. I tried some other things, but nothing seems to work.
Please help!


What declaration is variable_Word?? And what is stored in there??
 
Last edited:
What declaration is variable_Word?? And what is stored in there??
I assume that you have the adress for the possition in there.
If So try this declare it as Dword (temp) and write
L variable_word (Dword)

VARIABLE_WORD is of data type POINTER.
Maybe it's not really clear what I want:
At the block call I enter a fixed word (i.e.: DB228.DBW2).
I want to set the first bit of the second byte in that word, so that would
be DB228.DBX3.0 for this example.
The thing is that I need to do this more words, so therefore I want to use a pointer.
 
VARIABLE_WORD is of data type POINTER.
Maybe it's not really clear what I want:
At the block call I enter a fixed word (i.e.: DB228.DBW2).
I want to set the first bit of the second byte in that word, so that would
be DB228.DBX3.0 for this example.
The thing is that I need to do this more words, so therefore I want to use a pointer.

check this and let me know
 
Oh sorry if i did something wrong.
Can you please explain me what LD? So i know for next time!
I tested it and seemed to work but didn't test it for multi instance
 
Is the code required for an FC or FB ? (Thim's example is for a non-multiple instance FB)

I'd prefer an FC.

@Thim: trying your solution now, I'll let you know if it does the trick. Btw, thanks for the help so far!

Edit:
Thim: Your solution works like a charm :) Thanks very mutch!
I see you used an any-pointer. Is the problem I had that I used a normal pointer?
 
Last edited:
Hi,

I know there already are a lot of threads about using pointer, but I can't find
the solution to my problem in any of them.

I'm trying to set a bit in a word using a pointer. The word is variable, so I made a pointer. The bit I want to set has an offset to the first bit in that word of 1.0. I tried this code:

L P##VARIABLE_WORD
LAR1
L W [AR1,P#0.0]
T #DBNR
OPN DB [#DBNR]
A #CONDITION
S DBX [AR1,P#1.0]

This doesn't work. I tried some other things, but nothing seems to work.
Please help!

My rusty take on what you are doing here..

L P##VARIABLE_WORD
LAR1


you are loading the pointer AR1 to point to the absolute location of #VARIABLE_WORD

L W [AR1,P#0.0]
T #DBNR
OPN DB [#DBNR]


You transfer the value held in #VARIABLE_WORD into #DBNR and open the Data Block with that value. So #VARIABLE_WORD is a data block ID.

A #CONDITION
S DBX [AR1,P#1.0]


On a condition you set bit 0 in a word in the data block that is the same as the DB no..

ie if #VARIABLE_WORD was equal to to 5, you would have set set DB5.DBX6.0 to one ?? which is bit 0 of DBW5.


As I said I am rusty ☯
 
I'd prefer an FC.

@Thim: trying your solution now, I'll let you know if it does the trick. Btw, thanks for the help so far!

Edit:
Thim: Your solution works like a charm :) Thanks very mutch!
I see you used an any-pointer. Is the problem I had that I used a normal pointer?

Never used a pointer before but i think it has to do with the structure of it Any pointer has area of 8words.
Like you see i strip down the anypointer by moving the DB number in "DBNR" then i move the possition in "Bit".
Don't see you doing this in your code i think you can strip down the pointer as well, but then you will probably also need to point first to the DB-area and Bit-area.
Sorry for the bad english
 
Last edited:
Extra:
If you want to use Pointer then i think you need to change
Not sure of it, but someone will correct me if so

LAR1 P##variable_Word
L W [AR1,P#4.0] // change in to [AR1,P#0.0]
T #DBNR
L D [AR1,P#6.0] // Change into [AR1,P#2.0]
T #Bit

OPN DB [#DBNR]
L #Bit
LAR1
A #condition
S [AR1,P#1.0]
 
Extra:
If you want to use Pointer then i think you need to change
Not sure of it, but someone will correct me if so

Yeah I figured this out myself after reading your previous comment.
I know what I did wrong now. I tried to set a bit in the place of the pointer where the DB number is stored in stead of the address.

Thanks for everything!!
 

Similar Topics

Good Morning all can you help/advise me im have a configure ge9 driver Called ge9.ge9 path is (C:\Program Files (x86)\Proficy\Proficy...
Replies
1
Views
2,812
Hi Guys, I have got a problem regarding the setting of more than one limit for one input field. I have got four motors for extrusion & One for...
Replies
1
Views
1,670
Good day, I had installed the RSBizWare package. Installed and configured MS SqlExpress 2008. Created the database, and configured the OBDC data...
Replies
1
Views
1,821
Currently I'm using CC-Link modul QJ1BT11N as master station. The CPU I'm using is Q Series CPU, Q02(H). The problem is, I don't understand how to...
Replies
0
Views
2,795
I am working on a heat recovey system and need to regulate a modulating valve in order to maintain a temperature set-point. I have never used...
Replies
5
Views
5,859
Back
Top Bottom