Ok, I have looked at your code and can precise a little the preceding pseudo-code. Look at this new version:
int i, array[20];
unsigned char buf[20];
//----------------------------------------
// Configure the port for communication
//----------------------------------------
OpenComConfig
SetComTime
//----------------------------------------
// Establish communication
//----------------------------------------
ComWrt ("ATEST EQUIPMENT\r")
ComRd (buf) // "Buf" is the string into which device response is stored
// Test lenght of response
if (strlen (buf) < 16) goto Error;
if (strcmp (buf, "ATEST EQUIPMENT\r")) goto Error;
// If you are here, the communication is established
//----------------------------------------
// Communicate with the equipment
//----------------------------------------
// Manipulate array values
array[0] = 65;
array[1] = 66;
...
array[13] = 70;
// Compute and add the checksum
array[14] = CheckSum (array);
// Send the command to the device
for (i = 0; i < 14; i++) ComWrtByte (1, array[i]);
ComWrtByte (1, 13); // Add carriage return
// Wait response
ComRd (buf)
// Again, test response lenght
if (strlen (buf) < 16) error routine
// Test response
for (i = 0; i < 16; i++) { // For every byte
// Decode individual bits by testing with the "&" operator: if =0 bit off else bit on
bit0 = buf[i] & 0x1 ? 1 : 0
bit1 = buf[i] & 0x2 ? 1 : 0
...
bit4 = buf[i] & 0x10 ? 1 : 0
bit5 = buf[i] & 0x20 ? 1 : 0
...
}
int CheckSum (int *array)
// Compute the checksum
{
unsigned int i, cs, sum = 0;
for (i = 0; i < 14; i++) sum += array[i];
...
...
...
return cs;
}
Message Edited by Roberto Bozzolo on 05-10-2005 11:15 PM