I need help with a call to a class
hooktxu
Posts: 33
I have got this class:
I want to call to this class and obtain nMag. i do this, but it can´t work:
What can I do¨???
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 High = 1 Low = 0 Out = %1 OBJ iWifi : "iWiFiXXX" VAR long sensorStack[noparse][[/noparse]20] byte readed byte nMag PUB arrancar 'Reservamos el uso de un cog para la rutina testeo asignandole un espacio en pila 'Metodo que me reserva el uso de un nuevo cog, haciendo llamada a la rutina parpadeo 'y reservando un espacio de memoria en la pila cognew(testearMagnetico,@sensorStack) PUB testearMagnetico DirA[noparse][[/noparse]14]:=0 'Patita del sensor magnetico 1 configurada como entrada DirA[noparse][[/noparse]13]:=0 'Patita del sensor magnetico 2 configurada como entrada DirA[noparse][[/noparse]12]:=0 'Patita del sensor magnetico 3 configurada como entrada DirA[noparse][[/noparse]11]:=0 'Patita del sensor magnetico 4 configurada como entrada DirA[noparse][[/noparse]16]~~ 'LED VERDE 'Rutina en forma de bucle que se encarga de chequear de forma continua si el sensor detecta un nivel waitcnt(clkfreq*10 + cnt) repeat if(InA[noparse][[/noparse]14]==0) waitcnt(18_000_000+cnt) outa[noparse][[/noparse]16] := High nMag:=1 ''iWifi.compassServerConnection(0,1) readed:=1 elseif(InA[noparse][[/noparse]14]==1) waitcnt(40*12_000_000+cnt) outa[noparse][[/noparse]16] := Low if(InA[noparse][[/noparse]13]==0) waitcnt(18_000_000+cnt) outa[noparse][[/noparse]16] := High nMag:=2 ''iWifi.compassServerConnection(0,1) readed:=1 elseif(InA[noparse][[/noparse]13]==1) waitcnt(40*12_000_000+cnt) outa[noparse][[/noparse]16] := Low if(InA[noparse][[/noparse]12]==0) waitcnt(18_000_000+cnt) outa[noparse][[/noparse]16] := High nMag:=3 ''iWifi.compassServerConnection(0,1) readed:=1 elseif(InA[noparse][[/noparse]12]==1) waitcnt(40*12_000_000+cnt) outa[noparse][[/noparse]16] := Low if(InA[noparse][[/noparse]11]==0) waitcnt(18_000_000+cnt) outa[noparse][[/noparse]16] := High nMag:=4 ''iWifi.compassServerConnection(0,1) readed:=1 elseif(InA[noparse][[/noparse]11]==1) waitcnt(40*12_000_000+cnt) outa[noparse][[/noparse]16] := Low PUB leernMag return nMag
I want to call to this class and obtain nMag. i do this, but it can´t work:
sensorMagnetico.arrancar waitcnt(clkfreq*2 + cnt) A:=sensorMagnetico.leernMag
What can I do¨???
Comments
Currently you will get the content of nMag. So each time you want to know what the state of nMag is, you have to call leernMag.
Variable A will be always empty (= 0), as you have a waitcnt(clkfreq*2+cnt) in the code that should obtain nMag, but you have a waitcnt(clkfreq*10+cnt) inside of arrancar.
How can I get the solution? I don't understand what you say me about the times
sensorMagnetico.arrancar will return immediately - not waiting for the new COG to be started AND not waiting for testearMagnetico which waits 10 seconds.
So, after 2 seconds you read nMag, but after 10 seconds it will be written by testearMagnetico for the first time. That's the problem.
So, the fix would be : wait for at least 11 sec before you call leernMag for the first time.
sensorMagnetico.arrancar
waitcnt(clkfreq*12 + cnt)
A:=sensorMagnetico.leernMag
i do speak spanish.
let's see if i can help you with my poor english [noparse]:)[/noparse]
The comment says, in other words "continous loop to validating if the level sensor detects a level raising"
IMOO, besides the code posted by @MagIO2, i'd put all the pin settings on sensormagnetico.arrancar routine
Regards
Heich
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Toys are microcontroled.
Robots are microcontroled.
I am microcontroled.
If it's not Parallax then don't even bother. :-)
·
Mini-Din/PS2 connectors are for sale! 5 for $1! PM me if you wish to make an order.
Cheap·shipping unless specified!··········150 left!!··
Le aconsejo cambiar su co'digo a eso de abajo....
Asi esto
··· sensorMagnetico.arrancar
··· waitcnt(clkfreq*2·+·cnt)
··· A:=sensorMagnetico.leernMag
Siempre returnara' o Zero or el numero 1..4 depende si Readed esta' uno o no....
Samuel
Post Edited (SamMishal) : 7/18/2009 5:48:23 PM GMT