beautypg.com

Rane ECS v2 RaneWare (RaneWare 2.1) User Manual

Page 33

background image

RW Manual-33

Example Packet Expansion code for RW 232 Messages

// 09-10-96

- Devin Cook (Derived from RW232.CPP code)

//--------------------------------------------------------------------------
// This code only deals with the Body of an RW 232 message (Command/Data)
//
// The steps needed to fully communicate with an RW 232 device are as follows:
//
// 1. Send the Address: [FB xx FB xx]
// 2. Get the returned Device Type and Device ID flags
// 3. Send the FB expanded Body
// 4. Get and check the returned ComStat byte

// Take a simple command and expand it into a full packet.
//
// Input:
//

Buff

- BYTE array with the unexpanded message and lots of extra room

//

MsgLen - Unexpanded message length

//
// Steps required are:
// 1. Add Packet size. This is simply the Command length + 1 for the checksum
// 2. Duplicate 0xFBs
// 3. Calculate Checksum
// 4. Add Checksum to packet (Check for a 0xFB Checksum!)
// 5. Copy Packet back to the buffer
// 6. Return the new Packet Size
//
// Note: The buffer must be large enough to accept the expanded data.
// No checking is done to verify it is, so be careful!

// A packet into this routine consists of the one byte Command and any Data

int CmdToPacket(BYTE Buff[], int MsgLen)
{
BYTE L_MSB = ((MsgLen+1) >> 8) & 0xFF;

// Grab MSB of Size

BYTE L_LSB = (MsgLen+1) & 0xFF;

// Grab LSB of Size

// FBs is the number of 0xFB bytes in the messages
int FBs = 0;

// Don’t forget to check message length for FBs
if (L_MSB == 0xFB)
FBs ++;

if (L_LSB == 0xFB)
FBs ++;

// Calculate Checksum of Message Length bytes along with bytes in the packet
int CheckSum = L_MSB + L_LSB;

for (int x=0;x{
CheckSum += Buff[x];
if (Buff[x] == 0xFB)
FBs ++;
}

©Rane Corporation 10802 47th Ave. W., Mukilteo WA 98275-5098 TEL (425)355-6000 FAX (425)347-7757 WEB http://www.rane.com

DOC 103063 PN 10280 5-00