C
cmdolcet69
Can anyone give me some ideas on how to convert the following program
to vb 2003? I would like to jsut take this code and implement it in
vb.
def.h
/* Global Type Definitions */
typedef unsigned char byte; // 'byte' is an 8-bit
unsigned value
typedef unsigned int word; // 'word' is a 16-bit
unsigned value
/* Global Structure Definitions */
struct byte_low_hi {
byte low_byte;
byte high_byte;
};
/* Global Union Definitions */
union word_byte {
word word16;
struct byte_low_hi byte8;
};
//Code Constants
#define BMS '*' // this
represents the binary message start byte, value 0x2A
#define PASSWD 0x2D1C // this represents the
factory pass code, value 11548d
#define POLY 0x8005 // the polynomial used
in the CRC algorithm
var.c
// Global Union Variables:
union word_byte crc_value; // system crc value
union word_byte adc_value; // adc value read from
table
union word_byte location_value; // address of table to
send ADC value
// Global Array Variables
byte pmsg [25]; // crc buffer
// Global Variables
word tsize;
Digital Indicator.c
void table_upload_req(void) {
byte Len = 0x08;
byte Cmd = 0x09;
adc_value.word16 = 0x0000; // read ADC value and put
into storage var
location_value.word16 = 0x0000;
crc_value.word16 = 0;
byte msg_size = Len-2;
pmsg[0] = Char(Len);
pmsg[1] = Char(Cmd);
for(int i=0; i<tsize; tsize++) {
// single table upload request packet
location_value.word16++;
adc_value.word16 = ADC_AVE;
pmsg[2] = Char(adc_value.word16.high_byte);
pmsg[3] = Char(adc_value.word16.low_byte);
pmsg[4] = Char(location_value.word16.high_byte);
pmsg[5] = Char(location_value.word16.low_byte);
crc_value.word16 = Make_Bitwise_CRC16(word msg_size);
com1.Output = BMS +
pmsg[0] +
pmsg[1] +
pmsg[2] +
pmsg[3] +
pmsg[4] +
pmsg[5] +
Char(crc_value.word16.high_byte) +
Char(crc_value.word16.low_byte);
}
}
static private int Make_Bitwise_CRC16(word msg_size) {
word i, j, msg;
for(i = 0; i < msg_size; i ++) {
msg = (pmsg << 8) ;
for(j = 0; j < 8; j++) {
if ( ((msg ^ crc_value.word16) >> 15) > 0)
crc = (crc_value.word16 << 1) ^ POLY;
else
crc_value.word16 <<= 1;
msg <<= 1;
}
}
return(crc_value.word16 ^ 0);
}
to vb 2003? I would like to jsut take this code and implement it in
vb.
def.h
/* Global Type Definitions */
typedef unsigned char byte; // 'byte' is an 8-bit
unsigned value
typedef unsigned int word; // 'word' is a 16-bit
unsigned value
/* Global Structure Definitions */
struct byte_low_hi {
byte low_byte;
byte high_byte;
};
/* Global Union Definitions */
union word_byte {
word word16;
struct byte_low_hi byte8;
};
//Code Constants
#define BMS '*' // this
represents the binary message start byte, value 0x2A
#define PASSWD 0x2D1C // this represents the
factory pass code, value 11548d
#define POLY 0x8005 // the polynomial used
in the CRC algorithm
var.c
// Global Union Variables:
union word_byte crc_value; // system crc value
union word_byte adc_value; // adc value read from
table
union word_byte location_value; // address of table to
send ADC value
// Global Array Variables
byte pmsg [25]; // crc buffer
// Global Variables
word tsize;
Digital Indicator.c
void table_upload_req(void) {
byte Len = 0x08;
byte Cmd = 0x09;
adc_value.word16 = 0x0000; // read ADC value and put
into storage var
location_value.word16 = 0x0000;
crc_value.word16 = 0;
byte msg_size = Len-2;
pmsg[0] = Char(Len);
pmsg[1] = Char(Cmd);
for(int i=0; i<tsize; tsize++) {
// single table upload request packet
location_value.word16++;
adc_value.word16 = ADC_AVE;
pmsg[2] = Char(adc_value.word16.high_byte);
pmsg[3] = Char(adc_value.word16.low_byte);
pmsg[4] = Char(location_value.word16.high_byte);
pmsg[5] = Char(location_value.word16.low_byte);
crc_value.word16 = Make_Bitwise_CRC16(word msg_size);
com1.Output = BMS +
pmsg[0] +
pmsg[1] +
pmsg[2] +
pmsg[3] +
pmsg[4] +
pmsg[5] +
Char(crc_value.word16.high_byte) +
Char(crc_value.word16.low_byte);
}
}
static private int Make_Bitwise_CRC16(word msg_size) {
word i, j, msg;
for(i = 0; i < msg_size; i ++) {
msg = (pmsg << 8) ;
for(j = 0; j < 8; j++) {
if ( ((msg ^ crc_value.word16) >> 15) > 0)
crc = (crc_value.word16 << 1) ^ POLY;
else
crc_value.word16 <<= 1;
msg <<= 1;
}
}
return(crc_value.word16 ^ 0);
}