{\rtf1\ansi\ansicpg1252\deff0\deftab720{\fonttbl{\f0\fswiss MS Sans Serif;}{\f1\froman\fcharset2 Symbol;}{\f2\fmodern\fprq1 Swiss;}} {\colortbl\red0\green0\blue0;\red0\green240\blue240;\red0\green0\blue255;\red0\green128\blue128;} \deflang1033\pard\plain\f2\fs20\cf2 'This is an example of a SmartMotor set up in Data mode. \par 'It will send "RP to another motor and wait for a response. \par 'The response will be in ASCII charactures \par 'So the SmartMotor will need to convert them into an \par 'integer number that can be used. \par 'This example will store the result into the variable "p" \par \par 'The hardware set-up is as follwos: \par '2 motors serially connected to each other. \par 'The other motor (slave motor) must have it's echo turned off \par 'i.e. Motor 2 should have the ECHO_OFF command sent to it or in the program \par 'The following code should be in motor 1. \par \par END \par \par C0 \par \par CCHN(RS2,0)\tab \tab \tab \tab 'close channel to clear buffer \par OCHN(RS2,0,N,9600,1,8,D)\tab 'open channel for data mode \par PRINT("RP",#13)\tab \tab \tab 'send RP command to next motor \par i=0\tab \tab \tab \tab \tab 'initialize index counter \par \plain\f2\fs20\cf3 WHILE\plain\f2\fs20\cf2 1\tab \tab \tab \tab 'while loop looking for data \par \tab \plain\f2\fs20\cf3 IF\plain\f2\fs20\cf2 LEN>0\tab \tab \tab 'checking buffer \par \tab \tab ab[i]=GETCHR\tab 'get character if charater is in buffer \par \tab \tab \plain\f2\fs20\cf3 IF\plain\f2\fs20\cf2 ab[i]==13\tab 'looking for RETURN \par \tab \tab \tab \plain\f2\fs20\cf3 BREAK\plain\f2\fs20\cf2 \tab \tab 'RETURN marks the end of data string \par \tab \tab \plain\f2\fs20\cf3 ENDIF\plain\f2\fs20\cf2 \tab \tab \tab \par 'to prevent locking up, put a timer here. if no data receive in a given time, should break out of while loop \par \tab \tab i=i+1\tab \tab \tab 'increment index counter \par \tab \plain\f2\fs20\cf3 ENDIF\plain\f2\fs20\cf2 \par \plain\f2\fs20\cf3 LOOP\plain\f2\fs20\cf2 \par \par CMD\tab \tab \tab \tab \tab 'set motor back to command mode \par \par i=0\tab \tab \tab \par p=0 \par y=0\tab \tab \tab \tab \tab 're-initialize variables \par \plain\f2\fs20\cf3 WHILE\plain\f2\fs20\cf2 1 \par \tab \plain\f2\fs20\cf3 IF\plain\f2\fs20\cf2 ab[i]==13\tab 'marks end of string \par \tab \tab \plain\f2\fs20\cf3 BREAK\plain\f2\fs20\cf2 \par \tab \plain\f2\fs20\cf3 ENDIF\plain\f2\fs20\cf2 \par \tab \plain\f2\fs20\cf3 IF\plain\f2\fs20\cf2 ab[i]==45\tab 'checking for negative sign \par \tab \tab i=i+1 \par \tab \plain\f2\fs20\cf3 ENDIF\plain\f2\fs20\cf2 \par \tab y=ab[i]-48\tab \tab 'ASCII code to number \par \tab ab[i]=0\tab \tab 'clear array \par \tab p=p*10\tab \tab 'apply value \par \tab p=p+y \par \tab i=i+1\tab \tab \tab 'index array \par \plain\f2\fs20\cf3 LOOP\plain\f2\fs20\cf2 \par \plain\f2\fs20\cf3 IF\plain\f2\fs20\cf2 ab[0]==45\tab \tab 'if there was an negative sign, apply negative to value \par \tab p=-p\tab \tab \tab 'applying negative to value \par \tab ab[0]=0\tab \tab 'clear array \par \plain\f2\fs20\cf3 ENDIF\plain\f2\fs20\cf2 \par \tab \tab 'VALUE WILL BE STORE IN VARIABLE p \par RETURN\tab \tab \tab 'return back to main program \par }