Custom protocol for Copley Stepnet on RS232


Recommended Posts

Got the basics working quickly but stuck on the last key part.

Copley use a register based interface. To command the controller to move to a specific position, you first set the position register, then drop a command in the command register.

For the position register interface, i created a VariableValue component on Page_0, and linked it to a custom channel named CopleyPositionRegister[0]. It has an IO type of WritePositionRegister, which is specified in the Copley_Stepnet custom protocol.

Here's the code:

function WritePositionRegister(position)
private string in
   // lock the port
   if (!LockPort())
	  throw("Unable to lock port")
   // profile type - profile absolute scurve = 1
   Write("s r0xC8 1" + chr(13))
   // and read until the eol:
   in = ReadUntil(chr(13)) 
   //private val = CopleyPositionRegister[0]
   private string vStr = DoubleToStr(position)
   // position
   Write("s r0xCA " + vStr + chr(13))
   in = ReadUntil(chr(13)) 
   // release the port
   // and return the response
   // error occured
// return NULL to indicate error.  This should never happen
// because of the throw() statement above

What I'm not clear about is how to get the channel value into my code so that I can write it out the port. Is there a special variable name that I can use? I've tried defining the function name with a variable position, as above. I've tried accessing the channel with 'CopleyPositionRegister[0]'.

I can't quite get it to work.

Everything else was pretty easy - polling the status register, issuing move and home commands. But there's no example of outputting a channel value with custom code to convert it to serial.

Link to comment
Share on other sites

There are a number of private variables (parameters really) automatically passed in. The one you want is called SetToValue, but only applies if you select an Output I/O type. You can read about these variables in the Extending DAQFactory -> User devices chapter of the User's Guide. User devices and user protocols are almost identical, so some of the basics are described here, and the protocol specific stuff described in the next chapter.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.