Functional overview

Discussions and file drops for Auggie
Richard Cullin
Old Timer
Posts: 152
Joined: Sat Jun 02, 2012 5:45 am

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 
User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4591
Joined: Sun Sep 05, 2010 6:14 am
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
User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4591
Joined: Sun Sep 05, 2010 6:14 am
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
Old Timer
Posts: 152
Joined: Sat Jun 02, 2012 5:45 am

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
Old Timer
Posts: 152
Joined: Sat Jun 02, 2012 5:45 am

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; 
 



 
};



Attachments
screenshot.png
Last edited by Richard Cullin on Wed Jan 04, 2017 11:49 am, edited 1 time in total.
Richard Cullin
Old Timer
Posts: 152
Joined: Sat Jun 02, 2012 5:45 am

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
Old Timer
Posts: 152
Joined: Sat Jun 02, 2012 5:45 am

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;
User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4591
Joined: Sun Sep 05, 2010 6:14 am
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);
User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4591
Joined: Sun Sep 05, 2010 6:14 am
Contact:

Re: Functional overview

Post by ArtF »

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

Ill check that.. shouldnt be..

Art
Richard Cullin
Old Timer
Posts: 152
Joined: Sat Jun 02, 2012 5:45 am

Re: Functional overview

Post by Richard Cullin »

ToInt()&nbsp; does the trick for sendhex , will try table again

thanks
Richard Cullin
Old Timer
Posts: 152
Joined: Sat Jun 02, 2012 5:45 am

Re: Functional overview

Post by Richard Cullin »

ToInt()&nbsp; does the trick for sendtable too&nbsp;
next step crc calc
User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4591
Joined: Sun Sep 05, 2010 6:14 am
Contact:

Re: Functional overview

Post by ArtF »

No problem, glad to know VFDs can work in Auggie. Ive been burning tests again lately,it &nbsp;feels good to be using it
again, I've been so busy coding I hadnt done much cutting. Auggie impresses me more each time I use it lately.
&nbsp;I see errors I need to fix and small troubles I'd like to change, but overall its treating me pretty good, like an old
reliable, turn it on and it burns..

&nbsp;Each of your troubles has fixed a primary interface, so it shows how much testing can help. YaNvrNo helps me a
tremendous amount in primary testing , Ive crashed him hundreds of times.. (probably thousands..), so I
really have to hand it to him for stamina. The result is a controller thats a bit scary internally as it does so many things,
but for all that probably as reliable as Mach3 is on my mill at this point, better in terms of starting over or after a
pause. Never thought Id make another controller..but this one is purely for fun, that's why its free. &nbsp; So keep testing.. :-)
&nbsp;

Good luck
Art
User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4591
Joined: Sun Sep 05, 2010 6:14 am
Contact:

Re: Functional overview

Post by ArtF »

Richard:

Ill look at adding a crcfromtable command..

Art
Richard Cullin
Old Timer
Posts: 152
Joined: Sat Jun 02, 2012 5:45 am

Re: Functional overview

Post by Richard Cullin »

100% SUCCESS


global SpindleSpeed = function( speed )
{
&nbsp; &nbsp; if( Engine.GetSpindleState() != 0)
&nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; CRC=0xffff;
&nbsp; &nbsp; &nbsp; print("speed set to " + speed);
&nbsp; &nbsp; &nbsp; vfd=table(0x01,0x05,0x03,0,0,0);
&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;
&nbsp; &nbsp; &nbsp; FreeSetSpeed( MySpindleAxis, speed);
&nbsp; &nbsp; &nbsp; print("Frequency&nbsp; set to " + freq );

&nbsp; &nbsp; &nbsp; for (inx=0;inx<6;inx+=1)
&nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; myser.SendHex(vfd[inx]);
&nbsp; &nbsp; &nbsp; CRC=Crc16(CRC,vfd[inx]);
&nbsp; &nbsp; &nbsp; };
&nbsp; &nbsp; print("the CRC " + CRC);
&nbsp; &nbsp; &nbsp; myser.SendHex(ToInt(CRC/256));
&nbsp; &nbsp; &nbsp; myser.SendHex(ToInt(CRC%256));
&nbsp; &nbsp; };

};&nbsp;

global&nbsp; Crc16 = function(crc,byte_in)
{
//print("CRC " + byte_in );
crc = crc ^&nbsp; byte_in ;
&nbsp; &nbsp; &nbsp; for (c=0;c<8;c+=1){
&nbsp; &nbsp; &nbsp; &nbsp; if (crc&1)
&nbsp; &nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; crc= ((crc>>1) ^0xa001 )&nbsp; ;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; else
&nbsp; &nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; crc= crc>>1;
&nbsp; &nbsp; &nbsp; &nbsp; };
&nbsp; &nbsp; &nbsp; };
return ToInt(crc);
};
User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4591
Joined: Sun Sep 05, 2010 6:14 am
Contact:

Re: Functional overview

Post by ArtF »

Awesome.. amazing how easy it looks after you figure it out , eh? I do like GameMonkey scripting... amazingly powerfull

Art
Post Reply

Who is online

Users browsing this forum: No registered users and 37 guests