Functional overview

Discussions and file drops for Auggie
Post Reply
Richard Cullin
Site Admin
Posts: 152
Joined: Sat Jun 02, 2012 4:45 pm

Re: Functional overview

Post by Richard Cullin »

thanks art , while your lookin  is there a bog standard ccitt  crc code in there anywhere ??
Amazon [Bot]
Full Member
Full Member
Posts: 185
Joined: Tue Jan 06, 2026 4:56 pm

Re: Functional overview

Post by Amazon [Bot] »

do these hex values need to be sent as a string?

Code: Select all

global  myser = Serial();
global  vfd={"0x01","0x03","0x01","0x01","0x31","0x88","0x00"}; 
 
global  VFDOpen = function()
{
	myser.Open(6,9600); //port 6 baud 9600
	print( "VFD opened");  
       return;
};
 
global SpindleOn = function()
{

vfd0=ToString(vfd[0]);
vfd1=ToString(vfd[1]);
vfd2=ToString(vfd[2]);
vfd3=ToString(vfd[3]);
vfd4=ToString(vfd[4]);
vfd5=ToString(vfd[5]);
vfd6=ToString(vfd[6]);

  sendData=(vfd0+","+vfd1+","+vfd2+","+vfd3+","+vfd4+","+vfd5+","+vfd6);
 
print(sendData);
    myser.SendData(sendData);
    print("Set to Frequency " + GlobalGet("SpindleSpeed"));
    myser.Close();
    return;
};   
 
global VFDSpindle = function(control)
{ 
  FreeSetSpeed( MySpindleAxis,control); //turn on/off spindle
  if(control ==1){
    print("Spindle On");
    SpindleOn();
  }
  else
  {
    print("Spindle Off");
   //SpindleOff(); // need to call/Create the Off function
  }
};  
 
VFDOpen();
VFDSpindle(1); //1 is on 0 is off

9:52:510  VFD opened 
9:52:513  Spindle On 
9:52:516  0x01,0x03,0x01,0x01,0x31,0x88,0x00 
9:52:519  Set to Frequency 0 
Last edited by Amazon [Bot] on Wed Jan 04, 2017 3:09 am, edited 1 time in total.
Richard Cullin
Site Admin
Posts: 152
Joined: Sat Jun 02, 2012 4:45 pm

Re: Functional overview

Post by Richard Cullin »

do these hex values need to be sent as a string?
not as such ,more like a byte array ie whats required and not only that  0 (null) is a likely value I will need to transmit and  that usually terminates a string in most pgm languages

what I need to send is  chr(1)chr(3)chr(1)chr(1)chr(0x31)chr(0x88)

sendtable() or sendbyte()  or sendchr() would do it

.SendData  sends  0x31 0x33 0x31  .......  ascii  values 
ArtF
Global Moderator
Global Moderator
Posts: 4557
Joined: Sun Sep 05, 2010 5:14 pm
Contact:

Re: Functional overview

Post by ArtF »

Hi Richard:

    I can see its very difficult to send proper data to hex code devices.. so Ive add a couple functions to
make it easier.


global  vfd={0x01,"sometext",0x01,0x01,0x31,0x88}; 
global  myser = Serial();
myser.Open(6,9600); //port 6 baud 9600

myser.Table = vfd;
myser.SendTable();

myser.Close();

    The above fills the serial channels Table object with the data from your VFD command table.
The command SendTable sends the table, it can send mixed strings and hex codes. It knows from the
type of data in the table how to send it.

Alternativel, you can use

myser.SendHex( 0x45 ); to send a byte without using a table..

The new version is now online that had this capability.

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

Re: Functional overview

Post by ArtF »

I looked into the VFD's ..  They have two modes, an ASCII communications mode and an RTU mode. ( Remote terminal unit.). RTU is what your using..

so for a command like

1,3,1,1,crc  will turn spindle on cw
a,b,c,d,e

a = address of invertor,
b = 1- Read data, 2 - write data, 3 - command, 4- read status, 5-set frequency data.
c = number of data bytes..
d = (data bytes) if command -> run, 1 = fwd, 2 = rev, 3 = stop, 4 = r/f 5 = Jog, 6 = Jog+, 7 = JogR
e = crc

so the above is invertor1, function (command), 1 data bytes, data is command #1(fwd), crc

this document shows the commands and structure.. and how to compute the crc byte. So Id advise
to build a library function with a global list of commands in table form..

ie:
global  VFDSpindleOn={0x01,0x03,0x01,0x01,0x31,0x88}
global  VFDReadFreq={0x01......}
etc

(Im not sure why the 0x88? Manual says the command ends at the crc of ox31..if 31 is the right crc..)

send that command with

myser.Table = VFDSpindleOn;
myser.SendTable();

That should work, though I have no vfd to test the theory on..

Art



   

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

Re: Functional overview

Post by Richard Cullin »

thanks art  I will try it out  asap.


I looked into the VFD's ..  They have two modes, an ASCII communications mode and an RTU mode. ( Remote terminal unit.). RTU is what your using..
I wish if possible to keep it in rtu mode to maintain compatibility with mach3 -hauyung_dll  , it would be a pita to need to reprogram vfd every time to swap controllers.
(Im not sure why the 0x88? Manual says the command ends at the crc of ox31..if 31 is the right crc..)
in rtu mode the crc is 16 bits it uses the ccitt crc16 algorithm, the manual lacks detail  to put it mildly

Code: Select all

public uint  crcc=0xffff; // initialise the crc  

void crc16(byte crc_in){   //  crc a byte
      byte c ;
      crcc = crcc ^  crc_in ;
&nbsp; &nbsp; &nbsp; for (c=0;c<8;c++){
&nbsp; &nbsp; &nbsp; &nbsp;  if (crcc&1)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  crcc= ((crcc>>1) ^0xa001 )&nbsp;  ;
&nbsp; &nbsp; &nbsp; &nbsp;  else
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  crcc= crcc>>1;
&nbsp; &nbsp; &nbsp; }
}



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

Re: Functional overview

Post by Richard Cullin »

so far so good , one little weird bit

myser.SendTable();

does nothing &nbsp;unless preceeded with a senddata() &nbsp;at least once

so I did it this way &nbsp;, result below &nbsp; :)

Code: Select all

// 
global &nbsp;Vfd_Open = function()
{
myser.Open(6,9600);

myser.SendData("123");
print( "VFD opened"); &nbsp;
}


global SpindleOn = function()
{
 &nbsp; &nbsp;
 &nbsp; &nbsp;vfd={0x01,0x03,0x01,0x01,0x31,0x88}; 
 &nbsp; &nbsp;myser.Table = vfd;
 &nbsp; &nbsp;myser.SendTable();
 }
 
 &nbsp; &nbsp;//FreeSetSpeed( MySpindleAxis, GlobalGet("SpindleSpeed")); //turn on spindle
 &nbsp; &nbsp;print("Vfd Spindle was turned on");
 &nbsp; &nbsp;print("Set to Frequency " + GlobalGet("SpindleSpeed"));
}; &nbsp; 
 



 
};



You do not have the required permissions to view the files attached to this post.
Last edited by Richard Cullin on Wed Jan 04, 2017 10:49 pm, edited 1 time in total.
Richard Cullin
Site Admin
Posts: 152
Joined: Sat Jun 02, 2012 4:45 pm

Re: Functional overview

Post by Richard Cullin »

not sure whats happening here ,&nbsp; vfd[3] and vfd[4] don't get sent at all they just vanish


global SpindleSpeed = function( speed )
{
&nbsp; &nbsp; if( Engine.GetSpindleState() != 0)
&nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; print("speed set to " + speed);
&nbsp; &nbsp; &nbsp; vfd={0x01,0x05,0x03,0,0,0,0x70,0x45};
&nbsp; &nbsp; &nbsp; freq=speed/55.0;
&nbsp; &nbsp; &nbsp; freq=freq*100;
&nbsp; &nbsp; &nbsp; vfd[3]=freq/256;
&nbsp; &nbsp; &nbsp; vfd[4]=freq%256;
&nbsp; &nbsp; &nbsp; //FreeSetSpeed( MySpindleAxis, speed);
&nbsp; &nbsp; &nbsp; print("Frequency&nbsp; set to " + freq );
&nbsp; &nbsp; &nbsp; myser.Table = vfd;
&nbsp; &nbsp; &nbsp; myser.SendTable();


&nbsp; &nbsp; }

};&nbsp;





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

Re: Functional overview

Post by Richard Cullin »

this could work but fh/fl must be constants if they are the result of a calc nothing gets sent
ie&nbsp;
fh=freq/256&nbsp; ;&nbsp; nothing sent after vfd table
fh=int(freq/256);&nbsp; the script fails completely in that nothing is sent at all





global SpindleSpeed = function( speed )
{
&nbsp; &nbsp; if( Engine.GetSpindleState() != 0)
&nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; print("speed set to " + 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; fh=0x27;//int(freq/256);
&nbsp; &nbsp; &nbsp; fl=0x10;//int(freq%256);
&nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; FreeSetSpeed( MySpindleAxis, speed);
&nbsp; &nbsp; &nbsp; print("Frequency&nbsp; set to " + freq );

&nbsp; &nbsp; &nbsp; for (inx=0;inx<3;inx+=1)
&nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; myser.SendHex(vfd[inx]);
&nbsp; &nbsp; &nbsp; };
myser.SendHex(fh);
myser.SendHex(fl);
&nbsp; &nbsp; };

};&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:

I suspect its using floats ..

try

vfd[3]= ToInt(freq/256.0);
vfd[4]= ToInt( ToInt(freq)%256);
Post Reply