Functional overview
-
Richard Cullin
- Site Admin
- Posts: 152
- Joined: Sat Jun 02, 2012 4:45 pm
Re: Functional overview
thanks art , while your lookin is there a bog standard ccitt crc code in there anywhere ??
-
Amazon [Bot]
- Full Member

- Posts: 185
- Joined: Tue Jan 06, 2026 4:56 pm
Re: Functional overview
do these hex values need to be sent as a string?
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
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
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 languagesdo these hex values need to be sent as a string?
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

- Posts: 4557
- Joined: Sun Sep 05, 2010 5:14 pm
- Contact:
Re: Functional overview
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
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

- Posts: 4557
- Joined: Sun Sep 05, 2010 5:14 pm
- Contact:
Re: Functional overview
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
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
thanks art I will try it out asap.
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.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..
in rtu mode the crc is 16 bits it uses the ccitt crc16 algorithm, the manual lacks detail to put it mildly(Im not sure why the 0x88? Manual says the command ends at the crc of ox31..if 31 is the right crc..)
Code: Select all
public uint crcc=0xffff; // initialise the crc
void crc16(byte crc_in){ // crc a byte
byte c ;
crcc = crcc ^ crc_in ;
for (c=0;c<8;c++){
if (crcc&1)
crcc= ((crcc>>1) ^0xa001 ) ;
else
crcc= crcc>>1;
}
}
-
Richard Cullin
- Site Admin
- Posts: 152
- Joined: Sat Jun 02, 2012 4:45 pm
Re: Functional overview
so far so good , one little weird bit
myser.SendTable();
does nothing unless preceeded with a senddata() at least once
so I did it this way , result below
myser.SendTable();
does nothing unless preceeded with a senddata() at least once
so I did it this way , result below
Code: Select all
//
global Vfd_Open = function()
{
myser.Open(6,9600);
myser.SendData("123");
print( "VFD opened");
}
global SpindleOn = function()
{
vfd={0x01,0x03,0x01,0x01,0x31,0x88};
myser.Table = vfd;
myser.SendTable();
}
//FreeSetSpeed( MySpindleAxis, GlobalGet("SpindleSpeed")); //turn on spindle
print("Vfd Spindle was turned on");
print("Set to Frequency " + GlobalGet("SpindleSpeed"));
};
};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
not sure whats happening here , vfd[3] and vfd[4] don't get sent at all they just vanish
global SpindleSpeed = function( speed )
{
if( Engine.GetSpindleState() != 0)
{
print("speed set to " + speed);
vfd={0x01,0x05,0x03,0,0,0,0x70,0x45};
freq=speed/55.0;
freq=freq*100;
vfd[3]=freq/256;
vfd[4]=freq%256;
//FreeSetSpeed( MySpindleAxis, speed);
print("Frequency set to " + freq );
myser.Table = vfd;
myser.SendTable();
}
};
global SpindleSpeed = function( speed )
{
if( Engine.GetSpindleState() != 0)
{
print("speed set to " + speed);
vfd={0x01,0x05,0x03,0,0,0,0x70,0x45};
freq=speed/55.0;
freq=freq*100;
vfd[3]=freq/256;
vfd[4]=freq%256;
//FreeSetSpeed( MySpindleAxis, speed);
print("Frequency set to " + freq );
myser.Table = vfd;
myser.SendTable();
}
};
-
Richard Cullin
- Site Admin
- Posts: 152
- Joined: Sat Jun 02, 2012 4:45 pm
Re: Functional overview
this could work but fh/fl must be constants if they are the result of a calc nothing gets sent
ie
fh=freq/256 ; nothing sent after vfd table
fh=int(freq/256); the script fails completely in that nothing is sent at all
global SpindleSpeed = function( speed )
{
if( Engine.GetSpindleState() != 0)
{
print("speed set to " + speed);
vfd=table(0x01,0x05,0x03);
freq=speed/55.0;
freq=freq*100;
fh=0x27;//int(freq/256);
fl=0x10;//int(freq%256);
FreeSetSpeed( MySpindleAxis, speed);
print("Frequency set to " + freq );
for (inx=0;inx<3;inx+=1)
{
myser.SendHex(vfd[inx]);
};
myser.SendHex(fh);
myser.SendHex(fl);
};
};
ie
fh=freq/256 ; nothing sent after vfd table
fh=int(freq/256); the script fails completely in that nothing is sent at all
global SpindleSpeed = function( speed )
{
if( Engine.GetSpindleState() != 0)
{
print("speed set to " + speed);
vfd=table(0x01,0x05,0x03);
freq=speed/55.0;
freq=freq*100;
fh=0x27;//int(freq/256);
fl=0x10;//int(freq%256);
FreeSetSpeed( MySpindleAxis, speed);
print("Frequency set to " + freq );
for (inx=0;inx<3;inx+=1)
{
myser.SendHex(vfd[inx]);
};
myser.SendHex(fh);
myser.SendHex(fl);
};
};
-
ArtF
- Global Moderator

- Posts: 4557
- Joined: Sun Sep 05, 2010 5:14 pm
- Contact:
Re: Functional overview
Hi Richard:
I suspect its using floats ..
try
vfd[3]= ToInt(freq/256.0);
vfd[4]= ToInt( ToInt(freq)%256);
I suspect its using floats ..
try
vfd[3]= ToInt(freq/256.0);
vfd[4]= ToInt( ToInt(freq)%256);