-
December 7th, 2013, 04:28 AM
#1
Ansi C code
hello guys.recently i was away from the forum.I'M not c programmer and rarely i work with codes.
I need some help about one subject. if you can help, I'll be very glad.
There is one code, written with ansi c language. you can see the code at link:
http://u1312.hizliresim.com/1j/6/v7tr7.png
code is working there is no problem. but i need to change code to other comparasion type, because in my scada system, at same time, 30 same of this code is working at same time and it makes pc to run very very slowly. sometimes pc is freezing and I need to restart pc 4-5times every week. If I reduce the code number to 5 instead of 30, it works without problem, but 30 comparasion must take place at same time. If I change comparasion type I'm sure pc won't freeze ( not with c code, with dynamic comparasion).I just need to understand what code is doing.I posted question to Visual C++ because I could not see ansi c..
As I understand code is reading one decimal number, and divides decimal number to 4096 if result is 1, then returned value is 1, if result is 2, return is 2... like this, return value becomes 0,1,2,4 or 8. but I'm not sure if I understood right.
There is somewhere in code "expression = var1&61440" what is this for? 4096+8192+..= 61440 ok. but what the meaning? if you can describe what this code is doing exactly I'll be very happy.
there is one code more.
http://u1312.hizliresim.com/1j/6/v7ulx.jpg
I need also understand this.expression = var1&768... 768 = 512+256 ok but why not 512+256+1024 ?
if you can help I'll be very happy.
I need a table like this.. if the read value is between
0...4096> result 0,
4097...8192 > result 1
8192..12288> result 2
12288...16384> result 4
16384..32768> result 8
... I'M not sure if I made right table.
-
December 7th, 2013, 07:13 AM
#2
Re: Ansi C code
Please post actual code and not unknown links. Many members (myself included) don't open links to unknown sites.
Before posting, please format the code properly and use code tags. Go advanced, select the posted code and click '#'.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
December 7th, 2013, 07:44 AM
#3
Re: Ansi C code
ok you're right 2kaud. people may think it's not safe. here are the codes.
Code1
Code:
#include "apdefap.h"
long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName)
{
// Rueckgabewert
int index;
// Variable
unsigned long var1;
// Ausdruck
double expression;
// Statuswerte
unsigned long status[1];
unsigned long quality[1];
// Wertebereichsgrenzen
static double limitValue[5] = {0.00000000000000,4096.00000000000000,8192.00000000000000,16384.00000000000000,32768.00000000000000};
static unsigned long value[6] = {0,1,2,4,8,0};
// Werte lesen
var1 = (unsigned long)GetTagDoubleStateQC (lpszObjectName,&status[0],&quality[0]);
GetTagDoubleStateQC (lpszObjectName,&status[0],&quality[0]);
// zu ueberwachender Ausdruck
expression = var1&61440;
// Aufruf der Ueberpruefungsfunktion
index = Check_LimitsD (expression, 6, &limitValue[0]);
return value[index];
}
Code2
Code:
#include "apdefap.h"
long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName)
{
// Rueckgabewert
int index;
// Variable
unsigned long var1;
// Ausdruck
double expression;
// Statuswerte
unsigned long status[1];
unsigned long quality[1];
// Wertebereichsgrenzen
static double limitValue[5] = {0.00000000000000,256.00000000000000,512.00000000000000,1024.00000000000000,2048.00000000000000};
static long value[6] = {9539985,16711680,65280,255,255,9539985};
// Werte lesen
var1 = (unsigned long)GetTagDoubleStateQC ( lpszObjectName,&status[0],&quality[0]);
GetTagDoubleStateQC (lpszObjectName,&status[0],&quality[0]);
// zu ueberwachender Ausdruck
expression = var1&768;
// Aufruf der Ueberpruefungsfunktion
index = Check_LimitsD (expression, 6, &limitValue[0]);
return value[index];
}
at code 2, 9539985 means gray, 16711680 means blue, 65280 means green and 255 means red. code2 is reading one decimal number and giving colour code as a result.
but my question is; if the decimal value will be forexample 600 what will be result? For comparasion, I need to understand code is making which maths calculation, from 0 to xxx this colour, from xxx to yyy this colour.. I think you understood what I mean. I need to find out xxx yyy.
-
December 7th, 2013, 11:43 AM
#4
Re: Ansi C code
And what do the functions do? You haven't included the source for them.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
December 7th, 2013, 01:23 PM
#5
Re: Ansi C code
forexample at code1,
var1 = (unsigned long)GetTagDoubleStateQC (lpszObjectName,&status[0],&quality[0]);
var1 is the source, it changes automaticly.. from 0 to 32768.when var1 = 10000, index becomes 2.
-
December 7th, 2013, 04:09 PM
#6
Re: Ansi C code
there is just somewhere left in the code that i did not understand. code1 is also working like this: I changed source, code is still working.
Code:
#include "apdefap.h"
long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName)
{
int index;
unsigned long var1;
double expression;
static double limitValue[5] = {0.00000000000000,4096.00000000000000,8192.00000000000000,16384.00000000000000,32768.00000000000000};
static unsigned long value[6] = {0,1,2,4,8,0};
var1 = 10000;
expression = var1&61440;
index = Check_LimitsD (expression, 6, &limitValue[0]);
return value[index];
}
this code gives value of 2.. when I change var1=8000; value becomes 1.
I just want to understand this line.
Code:
expression = var1&61440;
what is this doing? "&" means bitwise here?
Last edited by pokajy; December 7th, 2013 at 04:16 PM.
-
December 7th, 2013, 04:30 PM
#7
Re: Ansi C code
ok ok I solved.
61440 means 2#0000_0000_0000_0000_1111_0000_0000_0000
10000 means 2#0000_0000_0000_0000_0010_0111_0001_0000
if
expression = 10000&61440;
then.. expression = 2#0000_0000_0000_0000_0010_0000_0000_0000 = 8192
if expression = 8192 then result is 2.
---------------------
61440 means 2#0000_0000_0000_0000_1111_0000_0000_0000
8000 means 2#0000_0000_0000_0000_0001_1111_0100_0000
if
expression = 8000&61440;
then.. expression = 2#0000_0000_0000_0000_0001_0000_0000_0000 = 4096
if expression = 4096 then result is 1.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|