Hello.
Can somebody help me with a small problem?
I read out value from DB-block, value is stored in it in the S5Time format.
Like s5t#2m40s. I read out value from DB-block, value is stored in it in
the S5Time format. I know as s5t a format in bcd is coded. But the read-out
value 3396 not to approach when converting.
In attempt to consider through vbclient, I receive too the value, just only
in hex? but this is not a problem.
Somebody can specify, what I do wrong and in what there can be a mistake?
The small peace of an source code too wouldn't be bad.
Thanks.
All others of reading, for example interger, are read without problems.
Hello.
Can somebody help me with a small problem?
I read out value from DB-block, value is stored in it in the S5Time format.
Like s5t#2m40s. I read out value from DB-block, value is stored in it in
the S5Time format. I know as s5t a format in bcd is coded. But the read-out
value 3396 not to approach when converting.
In attempt to consider through vbclient, I receive too the value, just only
in hex? but this is not a problem.
Somebody can specify, what I do wrong and in what there can be a mistake?
The small peace of an source code too wouldn't be bad.
Thanks.
All others of reading, for example interger, are read without problems.
Cpu300/400.
Hi,
S5Time is not managed by Snap7 (maybe in the next release).
You need to convert it by yourself.
The value is stored into a word and its format is W#16#BVVV
where B is the Base:
10 ms 00
100 ms 01
1 s 10
10 s 11
And VVV is the BCD value.
So, read a buffer and extract the value with S7.GetWordAt().
Then you need to extract from it (in VB code) the time base and the value.
Hi!
Thank you for fast answer.
I'll try this way and I will write about results.
Thank you
Hi!
Any way strange values.
Example:
Dim DBNumber As Integer = 2500
Dim Size As Integer = 2
Client.DBRead(DBNumber, 0, Size, Buffer)
Txt.Text = S7.GetWordAt(Buffer, 2)
In this memory cell is s5t#2m15s00ms and value which was considered is 8501.
Maybe I lost sight of something?
What you are reading is correct.
8501(dec)=2135(bcd)
The time base is 2=10(bin)=1 sec.
So 135s=2m15s00ms.
Oh!
Thank you. It's really very simple.
Easy way to convert DEC to BCD in VB.NET
RESULT = Val(Str(Hex(DECNUMBER)))
Yes ;)
but don't forget to extract and mask the timebase
int TimeBase = Math.Abs(DECNUMBER >> 12);
RESULT = Val(Str(Hex(DECNUMBER & 0x0FFF)));
After conversion i use operators Left and Rigth for timebase and time.
Timebase=left(bcdtime,1)
Last edit: Gotemcity 2015-03-13
Sorry for disturbing you with so simple problem, but another question appeared.
Now it's about writing to PLC.
In code it's may looks like:
1) Got integer data.
2) Convert to BCD
3) Convert to Byte
4) Convert this Byte to Big Endian Byte
5) Send by DbWrite.
Is it right way of my mind or may be i miss something?
I don't understand 3) and 4)
And, create a VAT and see if what you are sending is correct.
Last edit: Davide Nardella 2015-03-17
3) It's about convert our value to byte array type.
Dim byte(4) as byte = Bitconverter.GetBytes(IntegerValue)
4) it's about byte type. Little endian byte and big endian byte. May be it not nessary.
And send by client.dbwrite(dbnumber,2,byte)
Last edit: Gotemcity 2015-03-17
3) Use S7.SetWordAt() to write a word into a buffer.
4) Is not needed.
Once again you forgot to set the time base.
No, i don't forget about timebase.) In read all is perfect.
But my logic way is that i read from db (8501) that mean the same value i can write, but i was mistaken.
Anyway, i tried to write value and get wrong result.
In bcd my value 2135.(2min15s)
I convert it to integer throught binary:
2135 >>> 0010000100110101 >> 8501
Then:
s7.setwordat(buffer, bytenum, 0, integer)
Client.dbwrite(dbnumber,bytenum,2,buffer)
And in dbtable i got 8 seconds, not min.
This problem in timebase, s7 think that time base 0, but it must be 2.
Where i'm wrong?
Maybe i must sent in binary format?
Like in s5data description?
Last edit: Gotemcity 2015-03-25
Wait, don't answer, maybe i found my problem.
I'll write about that
All is working. It,s my fault.
Thank you. For you help.