Dear programmers
I want try to compiled this program that I have written for readiing the voltage but it doesn't compiled it.
It show the next errors but I don't know how I can the solution for fixed this errors.
Errror report:
========
Compiling...
Spanningsmeter.eba
File: C:\Spanningsmeter.eba (53) undefined variable - Counter
File: C:\Spanningsmeter.eba (53) illegal operand
File: C:\Spanningsmeter.eba (53) invalid assignment
File: C:\Spanningsmeter.eba (63) undefined variable - Counter
File: C:\Spanningsmeter.eba (63) illegal operand
Error(s) in compiling C:\Spanningsmeter.eba
This is my program it's public you can used it's free !
$USE "inpout32.lib"
DECLARE IMPORT, Inp32(PortAddr : WORD), WORD
DECLARE IMPORT, Out32(PortAddr : WORD, PortData : WORD)
DECLARE EXTERN _sscanf(STRING buf, STRING format,...),INT
DECLARE EXTERN sprintf(POINTER p, POINTER p, ...), INT
DECLARE "kernel32", Sleep(time:int)
DECLARE Counter(), WORD
DECLARE Calibratie()
CONST BA = 0x2F8
CONST RTS = 0x02
CONST DTR = 0x01
CONST MODEM_CONTROL_REG = 0x04
CONST MODEM_STATUS_REG = 0x06
GLOBAL Spanning
GLOBAL Negatief
GLOBAL Positief
GLOBAL Tijd_Factor
GLOBAL Counter
DEF Spanning AS DOUBLE
DEF Negatief AS DOUBLE
DEF Positief AS DOUBLE
DEF Tijd_Factor AS DOUBLE
SUB Counter(), WORD
DEF n AS INT
n = 0
'_ASM
' STI
'_ENDASM
Out32((BA + MODEM_CONTROL_REG), DTR + RTS)
DO
n++ /* tellen */
UNTIL ((Inp32(BA + MODEM_STATUS_REG) & 0x10) = 0) /* herhalen tot CTS = 0 */
Out32((BA + MODEM_CONTROL_REG), RTS) /* DTR uit, RTS blijft aan */
'_ASM
' CLI
'_ENDASM
RETURN(n)
ENDSUB
SUB Calibratie()
Tijd_Factor = -(Counter / LOG(1 - Negatief / (Positief + Negatief)))
Sleep(500)
RETURN
ENDSUB
OPENCONSOLE
Negatief = 10.2 /* fijnregeling */
Positief = 10.25 /* fijnregeling */
Calibratie()
DO
Spanning = ((Negatief + Positief) * (1 - EXP(-Counter / Tijd_Factor)) - Negatief)
PRINT USING("###.##", Spanning, "V")
Sleep(500)
UNTIL INKEY$(1) <> ""
END
CLOSECONSOLE
You are using the Counter as a function and as a variable, which is not necessarily a bad thing but it can lead to a lot of ambiguities. If (and I emphasize IF) your Counter and SUB Counter are two different entities then you obviously need to define Counter variable. You said it is GLOBAL but you have not defined it as, I presume, an INT. And that is exactly what the compiler is telling you - that you have not defined your variable.
However, I am a bit suspicious about your usage of Counter as a variable and as a function. Looking at your code it seems that you actually want to use the Counter as a function and not a variable at all. In that case you should change your code from:
Tijd_Factor = -(Counter / LOG(1 - Negatief / (Positief + Negatief)))
to:
Tijd_Factor = -(Counter() / LOG(1 - Negatief / (Positief + Negatief)))
and from:
Spanning = ((Negatief + Positief) * (1 - EXP(-Counter / Tijd_Factor)) - Negatief)
to:
Spanning = ((Negatief + Positief) * (1 - EXP(-Counter() / Tijd_Factor)) - Negatief)
Notice how I used parentheses to tell the compiler that I want it to use the result returned by the function, not the value in the "Counter" variable (which is not defined anyway).
Also, looking at the code of your "Counter()" function I see you defined it as of type WORD, which means it is expected to return WORD value as a result, yet inside the function you are returning the value of the local variable "n", which is defined as INT. Again, not a good thing to do. I'd suggest you change the definition of the function to:
SUB Counter(), INT
in order for the program to work as expected.
Hope this helps.
Barney
Hello Barney
Thanks for your quickly respons
But there is an problem with endless loop I can't quit the program when I press any key
OPENCONSOLE
Negatief = 10.2 /* fijnregeling */
Positief = 10.25 /* fijnregeling */
Calibratie()
DO
Spanning = ((Negatief + Positief) * (1 - EXP(-Counter() / Tijd_Factor)) - Negatief)
PRINT USING("###.##", Spanning, "V")
Sleep(500)
UNTIL INKEY$(1) <> ""
END
CLOSECONSOLE
Because you are ending the programmin END before you close the window CLOSECONSOLE.
Larry
Hi Stephane!
I just corrected your code a bit and add a few more lines to give you a better idea about what is happening inside your program.
Hope that helps you see better what is happening inside of your program.
$USE "inpout32.lib"
DECLARE IMPORT, Inp32(PortAddr : WORD), WORD
DECLARE IMPORT, Out32(PortAddr : WORD, PortData : WORD)
DECLARE EXTERN _sscanf(STRING buf, STRING format,...),INT
DECLARE EXTERN sprintf(POINTER p, POINTER p, ...), INT
DECLARE "kernel32", Sleep(time:int)
DECLARE Counter(), INT
DECLARE Calibratie()
CONST BA = 0x2F8
CONST RTS = 0x02
CONST DTR = 0x01
CONST MODEM_CONTROL_REG = 0x04
CONST MODEM_STATUS_REG = 0x06
GLOBAL Spanning
GLOBAL Negatief
GLOBAL Positief
GLOBAL Tijd_Factor
GLOBAL Counter
DEF Spanning AS DOUBLE
DEF Negatief AS DOUBLE
DEF Positief AS DOUBLE
DEF Tijd_Factor AS DOUBLE
OPENCONSOLE
PRINT "start"
Sleep(500)
Negatief = 10.2 /* fijnregeling */
Positief = 10.25 /* fijnregeling */
Calibratie()
'main loop
DO
PRINT "IN main loop"
Sleep(500)
Spanning = ((Negatief + Positief) * (1 - EXP(-Counter() / Tijd_Factor)) - Negatief)
PRINT USING("###.##", Spanning, "V")
Sleep(500)
UNTIL INKEY$<> ""
CLOSECONSOLE
END
SUB Counter(), INT
DEF n AS INT
PRINT "IN Counter"
Sleep(500)
n = 0
'_ASM
' STI
'_ENDASM
Out32((BA + MODEM_CONTROL_REG), DTR + RTS)
DO
PRINT "IN Counter loop"
Sleep(500)
PRINT "n:",n
PRINT (Inp32(BA + MODEM_STATUS_REG) & 0x10)
n++ /* tellen */
UNTIL ((Inp32(BA + MODEM_STATUS_REG) & 0x10) = 0) /* herhalen tot CTS = 0 */
Out32((BA + MODEM_CONTROL_REG), RTS) /* DTR uit, RTS blijft aan */
'_ASM
' CLI
'_ENDASM
PRINT "LEAVING Counter"
Sleep(500)
RETURN(n)
ENDSUB
SUB Calibratie()
PRINT "IN Calibratie"
Sleep(500)
Tijd_Factor = -(Counter() / LOG(1 - Negatief / (Positief + Negatief)))
Sleep(500)
PRINT "LEAVING Calibratie"
Sleep(500)
RETURN
ENDSUB
Quote from: Techno on October 28, 2008, 04:46:22 AM
Hello Barney
Thanks for your quickly respons
But there is an problem with endless loop I can't quit the program when I press any key
...
I forgot to add a comment.
As you can see in the "log" printed in the console window, the program never goes to the main loop hence the fact that you can't close it after pressing any key as in :
UNTIL INKEY$<> ""
CLOSECONSOLE
END
Hi 'Techno'!
I saw you had commented out "CLI" and "STI" in your code.
However there is a way to use this opcodes under XP and WIN 2000.
You have to set "SeTcbPrivilege" on your machine and "massage" the IOPL priv a little bit which is done by the attached "lib".
ProcessUserModeIOPL setting requires "SeTcbPrivilege"!!
Granting it to current account (admin rights required) takes effect after next login!
Description:
Go into Administrative Tools\Local Security Policy\Local Policies\User Rights Assignment
and there select the "Act as part of the operating system" policy and add your local account.
The exported function in the "SetIOPLto3.lib" is "SetIOPLto3" -Casesensitive!"
Have fan!
Csaba
Ficko, you don't need to change available privileges. More secure is to execute only your pogram as a service, or directly in SYSTEM account, using the NetScheduleJobAdd function and ITaskScheduler::Run method.
I have attached working assembler example (source requires modified nasm) which uses the task scheduler to switch into system account. Scheduler service should be running.
Tested on XP pro sp3, but without LPT port (laptop). I like coding in nasm, i have used (8 bit) assembler for years.
BTW, you don't need LSA handle, and adjusting TCB privileges, the TCB must be just available - can be disabled, but not deleted.
Nice alternative Sap! ;-)
By the way what you mean by "modified nasm" ?
Just recompilled it with added support (code) for unicode strings L"blah" and escaped characters like \n \r \x00 \t and \\.
Strings in invoke's are handled by invoke macro. I use it separately with Crimson Editor as the GUI.
Sapero
I try this function for using in my ebasic applications. but it give "strange errors" and I don't know what this errors main.
DECLARE "KERNEL32", Sleep(time:int)
DECLARE "KERNEL32", QueryPerformanceCounter (lpPerformanceCount : LARGE_INTEGER), INT
DECLARE "KERNEL32", QueryPerformanceFrequency (lpFrequency : LARGE_INTEGER), INT
DECLARE "KERNEL32", GetCurrentProcess (), INT
DECLARE "KERNEL32", SetPriorityClass (hProcess : INT, dwPriorityClass : INT), INT
DECLARE TimeInit()
DECLARE TimeRead(), DOUBLE
DECLARE Delay(ms AS DOUBLE)
DECLARE RealTime()
DECLARE NormalTime()
CONST NORMAL_PRIORITY_CLASS = 0x20
CONST IDLE_PRIORITY_CLASS = 0x40
CONST HIGH_PRIORITY_CLASS = 0x80
CONST REALTIME_PRIORITY_CLASS = 0x100
DEF StartTime AS INT64
DEF TimeUnit AS DOUBLE
TimeUnit = 0.000838096515
SUB TimeRead()
DEF f AS INT64
DEF x AS INT
x = QueryPerformanceFrequency(f)
TimeUnit = (1000 / f)
x = QueryPerformanceCounter(StartTime)
RETURN
ENDSUB
SUB TimeInit()
DEF t AS INT64
DEF x AS INT
x = QueryPerformanceCounter(t)
RETURN((TimeUnit * (t - StartTime)))
ENDSUB
SUB Delay(dDelayTime AS DOUBLE)
DEF TimeStart AS DOUBLE
TimeStart = TimeRead()
WHILE TimeRead < (TimeStart + dDelayTime)
ENDWHILE
RETURN
ENDSUB
SUB RealTime()
SetPriorityClass (GetCurrentProcess(),REALTIME_PRIORITY_CLASS)
RETURN
ENDSUB
SUB NormalTime()
SetPriorityClass (GetCurrentProcess(), NORMAL_PRIORITY_CLASS)
RETURN
ENDSUB
If it works I will create then an DLL file for my thesis
Compiling...
Timer32Functions.eba
File: C:\Timer32Functions.eba (26) no appropriate conversion exists
File: C:\Timer32Functions.eba (26) Warning: Uninitialized variable: f
File: C:\Timer32Functions.eba (28) no appropriate conversion exists
File: C:\Timer32Functions.eba (29) Warning: RETURN value expected.
File: C:\Timer32Functions.eba (36) no appropriate conversion exists
File: C:\Timer32Functions.eba (36) Warning: Uninitialized variable: t
File: C:\Timer32Functions.eba (37) no appropriate conversion from DOUBLE to NONE exists
File: C:\Timer32Functions.eba (44) undefined variable - dDelayTime
File: C:\Timer32Functions.eba (44) illegal operand
Error(s) in compiling C:\Timer32Functions.eba
I hate errors !
Greets
Stephane
Thanks guys for your quickly responses and help me
This functions are time functions
Compiling...
Timer32Functions.eba
File: C:\Timer32Functions.eba (26) no appropriate conversion exists
Means the parameter being passed is a different type than what was declared.
Passed int64; declared LARGE_INTEGER
File: C:\Timer32Functions.eba (26) Warning: Uninitialized variable: f
Means you didn't give f a initial value
File: C:\Timer32Functions.eba (28) no appropriate conversion exists
Means the parameter being passed is a different type than what was declared.
Passed int64; declared LARGE_INTEGER
File: C:\Timer32Functions.eba (29) Warning: RETURN value expected.
Subroutine declared as returning a DOUBLE but you are not returning anything
File: C:\Timer32Functions.eba (36) no appropriate conversion exists
Means the parameter being passed is a different type than what was declared.
Passed int64; declared LARGE_INTEGER
File: C:\Timer32Functions.eba (36) Warning: Uninitialized variable: t
Means you didn't give t a initial value
File: C:\Timer32Functions.eba (37) no appropriate conversion from DOUBLE to NONE exists
You defined the function as NOT returning a value and you're trying to return one.
File: C:\Timer32Functions.eba (44) undefined variable - dDelayTime
File: C:\Timer32Functions.eba (44) illegal operand
You declared the function parameter as ms but at line 44 you stuck in dDelayTime - they need to be the same
Larry
Thanks the new versions works
Stephane