beautypg.com

Dynamixel dx-116 – Robotis DX-116 User Manual

Page 34

background image

33

English Translation by: Tribotix Pty Ltd

www.tribotix.com

DYNAMIXEL

DX-116

#define RX_TIMEOUT_COUNT2 10000L //10mSec
#define RX_TIMEOUT_COUNT1 (RX_TIMEOUT_COUNT2*10L) //1Sec

unsigned long ulCounter;
byte bCount;

ulCounter = 0;
while(gbRxBufferReadPointer == gbRxBufferWritePointer)
{
if(ulCounter++ > RX_TIMEOUT_COUNT1)
{
return 0;
}
}
bCount = 0;
for(bCount = 0; bCount < 254; bCount++) //Maximum Data Length Limit : 255
{
ulCounter = 0;
while(gbRxBufferReadPointer == gbRxBufferWritePointer)
{
if(ulCounter++ > RX_TIMEOUT_COUNT2)
{
return bCount;
}
}
bpRxBuffer[bCount] = gbpInterruptRxBuffer[gbRxBufferReadPointer++];
}
return bCount;
}

byte TxPacket(byte *bpTxBuffer, byte bID, byte bInstruction, byte *bpParameter, byte bParameterLength)
{
byte bCount,bCheckSum,bPacketLength;

bpTxBuffer[0] = 0xff;
bpTxBuffer[1] = 0xff;
bpTxBuffer[2] = bID;
bpTxBuffer[3] = bParameterLength+2; //Length(Paramter,Instruction,Checksum)
bpTxBuffer[4] = bInstruction;
for(bCount = 0; bCount < bParameterLength; bCount++)
{
bpTxBuffer[bCount+5] = bpParameter[bCount];
}
bCheckSum = 0;
bPacketLength = bParameterLength+4+2;
for(bCount = 2; bCount < bPacketLength-1; bCount++) //except 0xff,checksum
{
bCheckSum += bpTxBuffer[bCount];
}
bpTxBuffer[bCount] = ~bCheckSum; //Writing Checksum with Bit Inversion

RS485_TXD; //Change 485 Direction to Transmission
for(bCount = 0; bCount < bPacketLength; bCount++)
{
TxD80(bpTxBuffer[bCount]);
}
while(!TXD_FINISH0); //Wait until TXD Shift register empty
RS485_RXD;
return(bPacketLength);
}

void PrintBuffer(byte *bpPrintBuffer, byte bLength)
{
byte bCount;
for(bCount = 0; bCount < bLength; bCount++)

Should wait until last data bit transmission is
completed.
Note.: ‘Shift register empty’ is differ from ‘Tx
Ready’. Tx Ready just means you can load the
data to CPU UART TxD Register. There can be
several Tx Buffering registers as what kind of
CPU