Page 6 of 8
Re: Functional overview
Posted: Thu Jan 05, 2017 12:56 pm
by Amazon [Bot]
How about something like this
Code: Select all
global SpindleSpeed = function( speed )
{
CRC=0xffff;
print("speed set to " + speed);
vfd={0x0,0x0,0x0,0x0,0x0,0x88,0x0,0x0,0x0};
vfd[0]=0x01;
vfd[1]=0x05;
vfd[2]=0x03;
freq=(speed/55.0)*100;
vfd[3]=ToInt(freq/256);
vfd[4]=ToInt(freq%256);
FreeSetSpeed( MySpindleAxis, speed);
print("Frequency set to : " + freq );
for (inx=0;inx<6;inx+=1)
{
print("vfd ",vfd[inx]);
CRC=Crc16(CRC,vfd[inx]);
}
print("the CRC " + CRC);
vfd[6]=ToInt(CRC%256);
vfd[7]=ToInt(CRC/256);
for (inx=0;inx<8;inx+=1)
{
print("the vfd["+ inx + "] " + vfd[inx]);
}
myser.Table = vfd;
myser.SendTable();
};
Re: Functional overview
Posted: Thu Jan 05, 2017 1:10 pm
by ArtF
Hi:
>>can't figure how to add elements to a table yet either ,that would be useful
To add, just do it.
ex:
vfd = { 1,2,3 };
vfd[7] = 6;
//you now have 8 elements in vfd, the ones not set are NULL.
// 1,2,3,NULL,NULL,NULL,NULL,6;
Art
Re: Functional overview
Posted: Thu Jan 05, 2017 9:12 pm
by Richard Cullin
thanks guys
adding elements like this works perfectly
Code: Select all
global SpindleSpeed = function( speed )
{
CRC=0xffff;
print("speed set to " + speed);
//FreeSetSpeed( MySpindleAxis, speed);
vfd=table(0x01,0x05,0x03);
freq=speed/55.0;
freq=freq*100;
vfd[3]=ToInt(freq/256);
vfd[4]=ToInt(freq%256);
vfd[5]=0;
print("Frequency set to " + freq );
for (inx=0;inx<tableCount(vfd);inx+=1)
{
CRC=Crc16(CRC,vfd[inx]);
};
// print("the CRC " + CRC);
vfd[7]=ToInt(CRC/256);
vfd[6]=ToInt(CRC%256);
myser.Table = vfd;
myser.SendTable();
};
if I wanted to add a speed dro that read the spindle freq say 2 times / sec , are there any 'timers' or such available to schedule calls to dro update function
Re: Functional overview
Posted: Thu Jan 05, 2017 9:20 pm
by Richard Cullin
just to complete things the system call back script was altered also as below
Code: Select all
// Library SystemCallBacks
// Created Thursday, December 31, 2015
// Author Art -- Do not edit above this line
// Enter Global vars below this line.
// This script will be called
//whenever the system is going from
//Enabled to Disable. It is called after the
// system shuts down motion.
global OnDisable = function()
{
myser.Close(); // shut vfd port
print( "--System -- System Disabled.");
//shut off any spindle since I use one..
if( lookup("SpindleOff")) { SpindleOff(); };
//shut down any other Estop process here..
};
//This script is called whenever
//the system is going from disabled to
//enabled. It is called before removing Estop
//conditions.
global OnEnable = function()
{
Vfd_Open(); // open vfd port
print( "--System -- System enabling.");
};
//This script is called whenever
//the user presses RUN if the run was allowed
global OnRun = function()
{
print( "--System -- System about to run.");
};
//This script is called whenever
//the user zeroes an axis, axis is a bitfield
//value, bit 1 is axis 1, bit 2 is axis 2....
//do not change the zero here, that would
//cause an infinite loop
global OnZero = function( axis )
{
print( "--System -- User has zeroed an axis" );
};
//This script is called whenever
//the user homes an axis, axis is a bitfield
//value, bit 1 is axis 1, bit 2 is axis 2....
//called after homing and zeroing
global OnHome = function( axis )
{
print( "--System -- User has homed an axis" );
};
//This script is called whenever
//the user regens the toolpath
global OnRegen = function()
{
print( "--System -- User has Regened the toolpath.");
};
//This script is called whenever
//the Scripting system has reset and
// reloaded all scripts. You may do additional
// startup tasks here.
global OnAllScriptsLoaded = function()
{
print( "--System -- System has reset Scripting system.");
};
Re: Functional overview
Posted: Thu Jan 05, 2017 10:23 pm
by ArtF
Hi Richard:
Well, when it comes to timers theres a couple of ways. Sleep releases the thread and uses no system resources, the thread
goes to sleep until the time set. So sleep(1); will return to the program and things run until at least 1 second has gone by, and it returns.
So a routine like
while(1)
{
SpindleFeed =...
sleep(1);
}
will run forever..updateing a dro every second.
if its a dro with motion, you can use blocks.
block("MotionUpdate"); is the same as saying sleep until an axis moves..but will be periodically called
every few seconds I believe even if axis dont move..just to keep things in sync.
or you can use your own blocks.
block("MyUpdate"); will put a script to sleep until some other script calls
signal("MyUpdate");
The combination of those two techniques handle almost any timing requirement..other than
reading time. I think theres a tick command in there.. Ill have to check..
Art
Re: Functional overview
Posted: Fri Jan 06, 2017 1:23 am
by Richard Cullin
first try at getting some data back from vfd ,although the the vfd accepts the cmd and replies accordingly
myser.ReadData( 8 ) returns nothing :-\
[the vfd takes at least 8mS to reply] see pic for cmd and response
global GetVfdSpeed = function( )
{
vfd={0x01,0x04,0x03,0x01,0,0,0xA1,0x8E};
myser.Table = vfd;
myser.SendTable();
sleep(1);
string = myser.ReadData( 8 );
print(string);
vfdrpm=(ToInt(string[4])*256+ToInt(string[5]))*55/100;
print("Rpm read " + vfdrpm );
return vfdrpm;
};
Re: Functional overview
Posted: Fri Jan 06, 2017 1:32 am
by ArtF
Check if myser.DataWaiting() is a value.
as a test maybe
while( !myser.DataWaiting() ) { yield()};
print( myser.DataWaiting() );
str = myser.GetData(8);
print( str );
just out of curiousity, it may tell me whats failing. I suspect I need to add a
GetHexData function..
Art
Re: Functional overview
Posted: Fri Jan 06, 2017 2:02 am
by Richard Cullin
buff depth 19
Script MCode10() called
attempt to call non function type
unknown(75) : str = myser.GetData();
callstack..
unknown(75): GetVfdSpeed
unknown(23): MCode10
unknown(1): __main
Variable ScriptError calls with current:1.0000
from this
global GetVfdSpeed = function( )
{
vfd={0x01,0x04,0x03,0x01,0,0,0xA1,0x8E};
myser.Table = vfd;
myser.SendTable();
//sleep(1);
while( !myser.DataWaiting() ) { yield();};
print("buff depth " + myser.DataWaiting() );
str = myser.GetData();
print( "buffer "+str );
string = myser.ReadData( 8 );
print("got this " + string);
vfdrpm=(ToInt(string[4])*256+ToInt(string[5]))*55/100;
print("Rpm read " + vfdrpm );
return vfdrpm;
};
Re: Functional overview
Posted: Fri Jan 06, 2017 2:08 am
by Richard Cullin
buff depth 8
got this
buff depth now 0
Script MCode10() called
operator getind bad operand int for string
unknown(84) : vfdrpm=(ToInt(string[4])*256+ToInt(string[5]))*55/100;
callstack..
unknown(84): GetVfdSpeed
unknown(23): MCode10
unknown(1): __main
Variable RunState calls with current:1.0000
Variable InScript calls with current:0.0000
Variable ScriptError calls with current:1.0000
Variable Execute calls with current:0.0000
from code
global GetVfdSpeed = function( )
{
vfd={0x01,0x04,0x03,0x01,0,0,0xA1,0x8E};
myser.Table = vfd;
myser.SendTable();
//sleep(1);
while( !myser.DataWaiting() ) { yield();};
print("buff depth " + myser.DataWaiting() );
//str = myser.GetData();
//print( "buffer "+str );
string = myser.ReadData( myser.DataWaiting() );
print("got this " + string);
print("buff depth now " + myser.DataWaiting() );
vfdrpm=(ToInt(string[4])*256+ToInt(string[5]))*55/100;
print("Rpm read " + vfdrpm );
return vfdrpm;
};
Re: Functional overview
Posted: Fri Jan 06, 2017 2:15 am
by ArtF
Richard:
I think, just as sending text is kinda special, so too is the difference between recieving text, and receiving data.
Ill change the code so that the myser.Table returns the data , itd be much easier to access.
Art