Functional overview

Discussions and file drops for Auggie
Post Reply
Amazon [Bot]
Full Member
Full Member
Posts: 185
Joined: Tue Jan 06, 2026 4:56 pm

Re: Functional overview

Post 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 ); 
&nbsp; &nbsp; &nbsp; for (inx=0;inx<6;inx+=1)
&nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; print("vfd ",vfd[inx]);
&nbsp; &nbsp; &nbsp; &nbsp; CRC=Crc16(CRC,vfd[inx]);
&nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; print("the CRC " + CRC);
&nbsp; &nbsp; &nbsp; vfd[6]=ToInt(CRC%256);
&nbsp; &nbsp; &nbsp; vfd[7]=ToInt(CRC/256);
&nbsp; &nbsp; &nbsp; for (inx=0;inx<8;inx+=1)
&nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; print("the vfd["+ inx + "] " + vfd[inx]);
&nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; myser.Table = vfd;
&nbsp; &nbsp; &nbsp; myser.SendTable();
};&nbsp;  
ArtF
Global Moderator
Global Moderator
Posts: 4557
Joined: Sun Sep 05, 2010 5:14 pm
Contact:

Re: Functional overview

Post by ArtF »

Hi:

>>can't figure how to add elements to a table yet either ,that would be useful

&nbsp; 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
Richard Cullin
Site Admin
Posts: 152
Joined: Sat Jun 02, 2012 4:45 pm

Re: Functional overview

Post by Richard Cullin »

thanks guys
adding elements&nbsp; like this works perfectly

Code: Select all

global SpindleSpeed = function( speed )
{
 
&nbsp; &nbsp; &nbsp; CRC=0xffff;
&nbsp; &nbsp; &nbsp; print("speed set to " + speed); 
&nbsp; &nbsp; &nbsp; //FreeSetSpeed( MySpindleAxis, speed);
&nbsp; &nbsp; &nbsp; vfd=table(0x01,0x05,0x03);
&nbsp; &nbsp; &nbsp; freq=speed/55.0;
&nbsp; &nbsp; &nbsp; freq=freq*100;
&nbsp; &nbsp; &nbsp; vfd[3]=ToInt(freq/256);
&nbsp; &nbsp; &nbsp; vfd[4]=ToInt(freq%256); 
&nbsp; &nbsp; &nbsp; vfd[5]=0;
&nbsp; &nbsp; &nbsp; print("Frequency&nbsp; set to " + freq );
&nbsp; &nbsp; &nbsp; for (inx=0;inx<tableCount(vfd);inx+=1)
&nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CRC=Crc16(CRC,vfd[inx]);
&nbsp; &nbsp; &nbsp; };
&nbsp; &nbsp; &nbsp; // print("the CRC " + CRC);
&nbsp; &nbsp; &nbsp; vfd[7]=ToInt(CRC/256);
&nbsp; &nbsp; &nbsp; vfd[6]=ToInt(CRC%256);
&nbsp; &nbsp; &nbsp; myser.Table = vfd;
&nbsp; &nbsp; &nbsp; myser.SendTable();
};&nbsp; 
 

if I wanted to add a speed dro&nbsp; that read the spindle freq say 2 times / sec , are there any 'timers' or such available to schedule calls to dro update function
Richard Cullin
Site Admin
Posts: 152
Joined: Sat Jun 02, 2012 4:45 pm

Re: Functional overview

Post by Richard Cullin »

just to complete things the system call back script was altered also as below

Code: Select all

// Library SystemCallBacks 
// Created&nbsp; Thursday, December 31, 2015 
// Author&nbsp; Art&nbsp; &nbsp; &nbsp;  -- Do not edit above this line
&nbsp; 
//&nbsp; Enter Global vars below this line. 
 
 
&nbsp;  
 
// 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()
{

&nbsp; myser.Close();&nbsp;  // shut vfd port
 
&nbsp; print( "--System -- System Disabled.");
&nbsp; //shut off any spindle since I use one..
&nbsp; if( lookup("SpindleOff")) { SpindleOff(); };
&nbsp; //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()
{

&nbsp;  Vfd_Open();&nbsp; //&nbsp; open vfd port

&nbsp;  print( "--System -- System enabling.");
};
 
//This script is called whenever 
//the user presses RUN if the run was allowed
 
global OnRun = function()
{
&nbsp;  
&nbsp;  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 )
{
&nbsp;  print( "--System -- User has zeroed an axis"&nbsp; );
};
 
//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 )
{
&nbsp;  print( "--System -- User has homed an axis" );
};
 
//This script is called whenever 
//the user regens the toolpath
 
global OnRegen = function()
{
&nbsp;  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()
{
&nbsp;  print( "--System -- System has reset Scripting system.");
};
&nbsp; 
ArtF
Global Moderator
Global Moderator
Posts: 4557
Joined: Sun Sep 05, 2010 5:14 pm
Contact:

Re: Functional overview

Post by ArtF »

Hi Richard:

&nbsp; 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)
{
&nbsp; SpindleFeed =...
&nbsp; sleep(1);
}

&nbsp; 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&nbsp; 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");

&nbsp; 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



Richard Cullin
Site Admin
Posts: 152
Joined: Sat Jun 02, 2012 4:45 pm

Re: Functional overview

Post 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 &nbsp;:-\

[the vfd takes at least 8mS to reply] see &nbsp;pic for &nbsp;cmd and response


global GetVfdSpeed = function( )
{

&nbsp; &nbsp;vfd={0x01,0x04,0x03,0x01,0,0,0xA1,0x8E};
&nbsp; &nbsp;myser.Table = vfd;
&nbsp; &nbsp;myser.SendTable();
&nbsp; &nbsp;sleep(1);
&nbsp; &nbsp;string = myser.ReadData( 8 );
&nbsp; &nbsp;print(string);
&nbsp; &nbsp;vfdrpm=(ToInt(string[4])*256+ToInt(string[5]))*55/100;
&nbsp; &nbsp;print("Rpm &nbsp;read " + &nbsp;vfdrpm );
&nbsp; &nbsp;return vfdrpm;
};
You do not have the required permissions to view the files attached to this post.
Last edited by Richard Cullin on Fri Jan 06, 2017 1:29 am, edited 1 time in total.
ArtF
Global Moderator
Global Moderator
Posts: 4557
Joined: Sun Sep 05, 2010 5:14 pm
Contact:

Re: Functional overview

Post 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
Richard Cullin
Site Admin
Posts: 152
Joined: Sat Jun 02, 2012 4:45 pm

Re: Functional overview

Post by Richard Cullin »

buff depth 19&nbsp;
&nbsp; Script MCode10() called&nbsp;
attempt to call non function type

unknown(75) : str = myser.GetData();

callstack..
unknown(75): GetVfdSpeed
unknown(23): MCode10
unknown(1): __main
&nbsp;
Variable ScriptError calls with current:1.0000


from&nbsp; this
global GetVfdSpeed = function( )
{

&nbsp; &nbsp; vfd={0x01,0x04,0x03,0x01,0,0,0xA1,0x8E};
&nbsp; &nbsp; myser.Table = vfd;
&nbsp; &nbsp; myser.SendTable();
&nbsp; &nbsp; //sleep(1);

while( !myser.DataWaiting() ) { yield();};
print("buff depth " + myser.DataWaiting() );
str = myser.GetData();
print( "buffer "+str );




&nbsp; &nbsp; string = myser.ReadData( 8 );
&nbsp; &nbsp; print("got this " + string);
&nbsp; &nbsp; vfdrpm=(ToInt(string[4])*256+ToInt(string[5]))*55/100;
&nbsp; &nbsp; print("Rpm&nbsp; read " +&nbsp; vfdrpm );
&nbsp; &nbsp; return vfdrpm;
};




Richard Cullin
Site Admin
Posts: 152
Joined: Sat Jun 02, 2012 4:45 pm

Re: Functional overview

Post by Richard Cullin »

buff depth 8&nbsp;
got this &nbsp;
buff depth now 0&nbsp;
&nbsp; Script MCode10() called&nbsp;
operator getind bad operand int for string

unknown(84) :&nbsp; &nbsp; vfdrpm=(ToInt(string[4])*256+ToInt(string[5]))*55/100;

callstack..
unknown(84): GetVfdSpeed
unknown(23): MCode10
unknown(1): __main
&nbsp;
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( )
{

&nbsp; &nbsp; vfd={0x01,0x04,0x03,0x01,0,0,0xA1,0x8E};
&nbsp; &nbsp; myser.Table = vfd;
&nbsp; &nbsp; myser.SendTable();
&nbsp; &nbsp; //sleep(1);

while( !myser.DataWaiting() ) { yield();};
print("buff depth " + myser.DataWaiting() );
//str = myser.GetData();
//print( "buffer "+str );




&nbsp; &nbsp; string = myser.ReadData( myser.DataWaiting() );
&nbsp; &nbsp; print("got this " + string);
print("buff depth now " + myser.DataWaiting() );
&nbsp; &nbsp; vfdrpm=(ToInt(string[4])*256+ToInt(string[5]))*55/100;
&nbsp; &nbsp; print("Rpm&nbsp; read " +&nbsp; vfdrpm );
&nbsp; &nbsp; return vfdrpm;
};


ArtF
Global Moderator
Global Moderator
Posts: 4557
Joined: Sun Sep 05, 2010 5:14 pm
Contact:

Re: Functional overview

Post by ArtF »

Richard:

&nbsp; 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
Post Reply