By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,075 Members | 950 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,075 IT Pros & Developers. It's quick & easy.

Converting to vb.net 2003

P: n/a
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[i];

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[i] << 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);
}

Sep 9 '07 #1
Share this Question
Share on Google+
12 Replies


P: n/a
cm,

For some people it is seen as an improvement that you can now use unsigned
values in VB.Net because that was impossible in version 2002/2003.

Cor

"cmdolcet69" <co************@hotmail.comschreef in bericht
news:11**********************@o80g2000hse.googlegr oups.com...
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[i];

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[i] << 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);
}
Sep 9 '07 #2

P: n/a
On Sep 9, 8:01 am, "Cor Ligthert[MVP]" <notmyfirstn...@planet.nl>
wrote:
cm,

For some people it is seen as an improvement that you can now use unsigned
values in VB.Net because that was impossible in version 2002/2003.

Cor

"cmdolcet69" <colin_dolce...@hotmail.comschreef in berichtnews:11**********************@o80g2000hse.g ooglegroups.com...
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[i];
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[i] << 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);
}- Hide quoted text -

- Show quoted text -
So your saying that i can;t convert this into vb?

Sep 9 '07 #3

P: n/a
(via C++ to VB Converter)
Note that automated conversion from C++ is just a first step. The code
produced below will almost certainly need further adjustments:

Public Class GlobalMembers
'var.c

' Global Union Variables:
Public Shared crc_value As word_byte ' system crc value
Public Shared adc_value As word_byte ' adc value read from table
Public Shared location_value As word_byte ' address of table to send ADC
value

' Global Array Variables
Public Shared pmsg As Byte() = New Byte(24){} ' crc buffer

' Global Variables
Public Shared tsize As UInteger

'Digital Indicator.c

Public Shared Sub table_upload_req()
Dim Len As Byte = &H08
Dim Cmd As Byte = &H09
adc_value.word16 = &H0000 ' read ADC value and put into storage var
location_value.word16 = &H0000
crc_value.word16 = 0

Dim msg_size As Byte = Len-2

pmsg(0) = ChrW(Len)
pmsg(1) = ChrW(Cmd)

Dim i As Integer =0
Do While i<tsize

' single table upload request packet
location_value.word16 += 1
adc_value.word16 = ADC_AVE(i)

pmsg(2) = CChar(adc_value.word16.high_byte)
pmsg(3) = CChar(adc_value.word16.low_byte)
pmsg(4) = CChar(location_value.word16.high_byte)
pmsg(5) = CChar(location_value.word16.low_byte)

crc_value.word16 = Make_Bitwise_CRC16(UInteger msg_size)

com1.Output = DefineConstants.BMS + pmsg(0) + pmsg(1) + pmsg(2) + pmsg(3)
+ pmsg(4) + pmsg(5) + CChar(crc_value.word16.high_byte) +
CChar(crc_value.word16.low_byte)
tsize += 1
Loop
End Sub

Friend Shared Friend Function Make_Bitwise_CRC16(ByVal msg_size As
UInteger) As Integer
Dim i As UInteger
Dim j As UInteger
Dim msg As UInteger

For i = 0 To msg_size - 1
msg = (pmsg(i) << 8)

For j = 0 To 7
If ((msg Xor crc_value.word16) >15) 0 Then
crc = (crc_value.word16 << 1) Xor DefineConstants.POLY
Else
crc_value.word16 <<= 1
End If
msg <<= 1
Next j
Next i
Return(crc_value.word16 Xor 0)
End Function
End Class
'def.h

' Global Type Definitions

' Global Structure Definitions
Public Class byte_low_hi
Public low_byte As Byte
Public high_byte As Byte
End Class

' Global Union Definitions
'C++ to VB CONVERTER TODO TASK: Unions are not supported in VB.
'ORIGINAL LINE: union word_byte
Public Structure word_byte
Public word16 As UInteger
Public byte8 As byte_low_hi
End Structure

'Code Constants
#Const BMS = True ' this represents the binary message start byte, value 0x2A
#Const PASSWD = True ' this represents the factory pass code, value 11548d
#Const POLY = True ' the polynomial used in the CRC algorithm

Friend NotInheritable Class DefineConstants
Public Const BMS As Char = "*"c
Public Const PASSWD As Integer = &H2D1C
Public Const POLY As Integer = &H8005
End Class
--
David Anton
http://www.tangiblesoftwaresolutions.com
Convert between VB, C#, C++, and Java
Instant C#
Instant VB
Instant C++
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter
"cmdolcet69" wrote:
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[i];

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[i] << 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);
}

Sep 9 '07 #4

P: n/a
On Sep 9, 11:12 am, David Anton <DavidAn...@discussions.microsoft.com>
wrote:
(via C++ to VB Converter)
Note that automated conversion from C++ is just a first step. The code
produced below will almost certainly need further adjustments:

Public Class GlobalMembers
'var.c

' Global Union Variables:
Public Shared crc_value As word_byte ' system crc value
Public Shared adc_value As word_byte ' adc value read from table
Public Shared location_value As word_byte ' address of table to send ADC
value

' Global Array Variables
Public Shared pmsg As Byte() = New Byte(24){} ' crc buffer

' Global Variables
Public Shared tsize As UInteger

'Digital Indicator.c

Public Shared Sub table_upload_req()
Dim Len As Byte = &H08
Dim Cmd As Byte = &H09
adc_value.word16 = &H0000 ' read ADC value and put into storage var
location_value.word16 = &H0000
crc_value.word16 = 0

Dim msg_size As Byte = Len-2

pmsg(0) = ChrW(Len)
pmsg(1) = ChrW(Cmd)

Dim i As Integer =0
Do While i<tsize

' single table upload request packet
location_value.word16 += 1
adc_value.word16 = ADC_AVE(i)

pmsg(2) = CChar(adc_value.word16.high_byte)
pmsg(3) = CChar(adc_value.word16.low_byte)
pmsg(4) = CChar(location_value.word16.high_byte)
pmsg(5) = CChar(location_value.word16.low_byte)

crc_value.word16 = Make_Bitwise_CRC16(UInteger msg_size)

com1.Output = DefineConstants.BMS + pmsg(0) + pmsg(1) + pmsg(2) + pmsg(3)
+ pmsg(4) + pmsg(5) + CChar(crc_value.word16.high_byte) +
CChar(crc_value.word16.low_byte)
tsize += 1
Loop
End Sub

Friend Shared Friend Function Make_Bitwise_CRC16(ByVal msg_size As
UInteger) As Integer
Dim i As UInteger
Dim j As UInteger
Dim msg As UInteger

For i = 0 To msg_size - 1
msg = (pmsg(i) << 8)

For j = 0 To 7
If ((msg Xor crc_value.word16) >15) 0 Then
crc = (crc_value.word16 << 1) Xor DefineConstants.POLY
Else
crc_value.word16 <<= 1
End If
msg <<= 1
Next j
Next i
Return(crc_value.word16 Xor 0)
End Function
End Class
'def.h

' Global Type Definitions

' Global Structure Definitions
Public Class byte_low_hi
Public low_byte As Byte
Public high_byte As Byte
End Class

' Global Union Definitions
'C++ to VB CONVERTER TODO TASK: Unions are not supported in VB.
'ORIGINAL LINE: union word_byte
Public Structure word_byte
Public word16 As UInteger
Public byte8 As byte_low_hi
End Structure

'Code Constants
#Const BMS = True ' this represents the binary message start byte, value 0x2A
#Const PASSWD = True ' this represents the factory pass code, value 11548d
#Const POLY = True ' the polynomial used in the CRC algorithm

Friend NotInheritable Class DefineConstants
Public Const BMS As Char = "*"c
Public Const PASSWD As Integer = &H2D1C
Public Const POLY As Integer = &H8005
End Class
--
David Antonhttp://www.tangiblesoftwaresolutions.com
Convert between VB, C#, C++, and Java
Instant C#
Instant VB
Instant C++
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter

"cmdolcet69" wrote:
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[i];
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[i] << 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);
}- Hide quoted text -

- Show quoted text -
How do i decalre UInteger (unsinged integers) in vb 2003

Sep 9 '07 #5

P: n/a
System.UInt32
--
David Anton
http://www.tangiblesoftwaresolutions.com
Convert between VB, C#, C++, and Java
Instant C#
Instant VB
Instant C++
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter
"cmdolcet69" wrote:
On Sep 9, 11:12 am, David Anton <DavidAn...@discussions.microsoft.com>
wrote:
(via C++ to VB Converter)
Note that automated conversion from C++ is just a first step. The code
produced below will almost certainly need further adjustments:

Public Class GlobalMembers
'var.c

' Global Union Variables:
Public Shared crc_value As word_byte ' system crc value
Public Shared adc_value As word_byte ' adc value read from table
Public Shared location_value As word_byte ' address of table to send ADC
value

' Global Array Variables
Public Shared pmsg As Byte() = New Byte(24){} ' crc buffer

' Global Variables
Public Shared tsize As UInteger

'Digital Indicator.c

Public Shared Sub table_upload_req()
Dim Len As Byte = &H08
Dim Cmd As Byte = &H09
adc_value.word16 = &H0000 ' read ADC value and put into storage var
location_value.word16 = &H0000
crc_value.word16 = 0

Dim msg_size As Byte = Len-2

pmsg(0) = ChrW(Len)
pmsg(1) = ChrW(Cmd)

Dim i As Integer =0
Do While i<tsize

' single table upload request packet
location_value.word16 += 1
adc_value.word16 = ADC_AVE(i)

pmsg(2) = CChar(adc_value.word16.high_byte)
pmsg(3) = CChar(adc_value.word16.low_byte)
pmsg(4) = CChar(location_value.word16.high_byte)
pmsg(5) = CChar(location_value.word16.low_byte)

crc_value.word16 = Make_Bitwise_CRC16(UInteger msg_size)

com1.Output = DefineConstants.BMS + pmsg(0) + pmsg(1) + pmsg(2) + pmsg(3)
+ pmsg(4) + pmsg(5) + CChar(crc_value.word16.high_byte) +
CChar(crc_value.word16.low_byte)
tsize += 1
Loop
End Sub

Friend Shared Friend Function Make_Bitwise_CRC16(ByVal msg_size As
UInteger) As Integer
Dim i As UInteger
Dim j As UInteger
Dim msg As UInteger

For i = 0 To msg_size - 1
msg = (pmsg(i) << 8)

For j = 0 To 7
If ((msg Xor crc_value.word16) >15) 0 Then
crc = (crc_value.word16 << 1) Xor DefineConstants.POLY
Else
crc_value.word16 <<= 1
End If
msg <<= 1
Next j
Next i
Return(crc_value.word16 Xor 0)
End Function
End Class
'def.h

' Global Type Definitions

' Global Structure Definitions
Public Class byte_low_hi
Public low_byte As Byte
Public high_byte As Byte
End Class

' Global Union Definitions
'C++ to VB CONVERTER TODO TASK: Unions are not supported in VB.
'ORIGINAL LINE: union word_byte
Public Structure word_byte
Public word16 As UInteger
Public byte8 As byte_low_hi
End Structure

'Code Constants
#Const BMS = True ' this represents the binary message start byte, value 0x2A
#Const PASSWD = True ' this represents the factory pass code, value 11548d
#Const POLY = True ' the polynomial used in the CRC algorithm

Friend NotInheritable Class DefineConstants
Public Const BMS As Char = "*"c
Public Const PASSWD As Integer = &H2D1C
Public Const POLY As Integer = &H8005
End Class
--
David Antonhttp://www.tangiblesoftwaresolutions.com
Convert between VB, C#, C++, and Java
Instant C#
Instant VB
Instant C++
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter

"cmdolcet69" wrote:
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[i];
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[i] << 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);
}- Hide quoted text -
- Show quoted text -

How do i decalre UInteger (unsinged integers) in vb 2003

Sep 9 '07 #6

P: n/a
On Sep 9, 12:32 pm, David Anton <DavidAn...@discussions.microsoft.com>
wrote:
System.UInt32
--
David Antonhttp://www.tangiblesoftwaresolutions.com
Convert between VB, C#, C++, and Java
Instant C#
Instant VB
Instant C++
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter

"cmdolcet69" wrote:
On Sep 9, 11:12 am, David Anton <DavidAn...@discussions.microsoft.com>
wrote:
(via C++ to VB Converter)
Note that automated conversion from C++ is just a first step. The code
produced below will almost certainly need further adjustments:
Public Class GlobalMembers
'var.c
' Global Union Variables:
Public Shared crc_value As word_byte ' system crc value
Public Shared adc_value As word_byte ' adc value read from table
Public Shared location_value As word_byte ' address of table to send ADC
value
' Global Array Variables
Public Shared pmsg As Byte() = New Byte(24){} ' crc buffer
' Global Variables
Public Shared tsize As UInteger
'Digital Indicator.c
Public Shared Sub table_upload_req()
Dim Len As Byte = &H08
Dim Cmd As Byte = &H09
adc_value.word16 = &H0000 ' read ADC value and put into storage var
location_value.word16 = &H0000
crc_value.word16 = 0
Dim msg_size As Byte = Len-2
pmsg(0) = ChrW(Len)
pmsg(1) = ChrW(Cmd)
Dim i As Integer =0
Do While i<tsize
' single table upload request packet
location_value.word16 += 1
adc_value.word16 = ADC_AVE(i)
pmsg(2) = CChar(adc_value.word16.high_byte)
pmsg(3) = CChar(adc_value.word16.low_byte)
pmsg(4) = CChar(location_value.word16.high_byte)
pmsg(5) = CChar(location_value.word16.low_byte)
crc_value.word16 = Make_Bitwise_CRC16(UInteger msg_size)
com1.Output = DefineConstants.BMS + pmsg(0) + pmsg(1) + pmsg(2) + pmsg(3)
+ pmsg(4) + pmsg(5) + CChar(crc_value.word16.high_byte) +
CChar(crc_value.word16.low_byte)
tsize += 1
Loop
End Sub
Friend Shared Friend Function Make_Bitwise_CRC16(ByVal msg_size As
UInteger) As Integer
Dim i As UInteger
Dim j As UInteger
Dim msg As UInteger
For i = 0 To msg_size - 1
msg = (pmsg(i) << 8)
For j = 0 To 7
If ((msg Xor crc_value.word16) >15) 0 Then
crc = (crc_value.word16 << 1) Xor DefineConstants.POLY
Else
crc_value.word16 <<= 1
End If
msg <<= 1
Next j
Next i
Return(crc_value.word16 Xor 0)
End Function
End Class
'def.h
' Global Type Definitions
' Global Structure Definitions
Public Class byte_low_hi
Public low_byte As Byte
Public high_byte As Byte
End Class
' Global Union Definitions
'C++ to VB CONVERTER TODO TASK: Unions are not supported in VB.
'ORIGINAL LINE: union word_byte
Public Structure word_byte
Public word16 As UInteger
Public byte8 As byte_low_hi
End Structure
'Code Constants
#Const BMS = True ' this represents the binary message start byte, value 0x2A
#Const PASSWD = True ' this represents the factory pass code, value 11548d
#Const POLY = True ' the polynomial used in the CRC algorithm
Friend NotInheritable Class DefineConstants
Public Const BMS As Char = "*"c
Public Const PASSWD As Integer = &H2D1C
Public Const POLY As Integer = &H8005
End Class
--
David Antonhttp://www.tangiblesoftwaresolutions.com
Convert between VB, C#, C++, and Java
Instant C#
Instant VB
Instant C++
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter
"cmdolcet69" wrote:
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[i];
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[i] << 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);
}- Hide quoted text -
- Show quoted text -
How do i decalre UInteger (unsinged integers) in vb 2003- Hide quoted text -

- Show quoted text -
David can you explaine why when i add in the following it says "
UInteger is not defined"

Public Structure word_byte
Public word16 As UInteger
Public byte8 As byte_low_hi
End Structure
When i add Imports System.UInt32 and change it to Uint16 I get the
error on

Public Structure word_byte
Public word16 As UInt16
Public byte8 As byte_low_hi
End Structure

adc_value.word16 = &H0 ' read ADC value and put into storage var
location_value.word16 = &H0
crc_value.word16 = 0
The location_value.word16 = &H0 gives an error "Value of type integer
cannot be converted to System.Uint16

Sep 9 '07 #7

P: n/a
The VB type aliases UInteger, ULong, and UShort are only available in VB 2005
and beyond.
For the second problem, just use a cast.
--
David Anton
http://www.tangiblesoftwaresolutions.com
Convert between VB, C#, C++, and Java
Instant C#
Instant VB
Instant C++
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter
"cmdolcet69" wrote:
On Sep 9, 12:32 pm, David Anton <DavidAn...@discussions.microsoft.com>
wrote:
System.UInt32
--
David Antonhttp://www.tangiblesoftwaresolutions.com
Convert between VB, C#, C++, and Java
Instant C#
Instant VB
Instant C++
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter

"cmdolcet69" wrote:
On Sep 9, 11:12 am, David Anton <DavidAn...@discussions.microsoft.com>
wrote:
(via C++ to VB Converter)
Note that automated conversion from C++ is just a first step. The code
produced below will almost certainly need further adjustments:
Public Class GlobalMembers
'var.c
' Global Union Variables:
Public Shared crc_value As word_byte ' system crc value
Public Shared adc_value As word_byte ' adc value read from table
Public Shared location_value As word_byte ' address of table to send ADC
value
' Global Array Variables
Public Shared pmsg As Byte() = New Byte(24){} ' crc buffer
' Global Variables
Public Shared tsize As UInteger
'Digital Indicator.c
Public Shared Sub table_upload_req()
Dim Len As Byte = &H08
Dim Cmd As Byte = &H09
adc_value.word16 = &H0000 ' read ADC value and put into storage var
location_value.word16 = &H0000
crc_value.word16 = 0
Dim msg_size As Byte = Len-2
pmsg(0) = ChrW(Len)
pmsg(1) = ChrW(Cmd)
Dim i As Integer =0
Do While i<tsize
' single table upload request packet
location_value.word16 += 1
adc_value.word16 = ADC_AVE(i)
pmsg(2) = CChar(adc_value.word16.high_byte)
pmsg(3) = CChar(adc_value.word16.low_byte)
pmsg(4) = CChar(location_value.word16.high_byte)
pmsg(5) = CChar(location_value.word16.low_byte)
crc_value.word16 = Make_Bitwise_CRC16(UInteger msg_size)
com1.Output = DefineConstants.BMS + pmsg(0) + pmsg(1) + pmsg(2) + pmsg(3)
+ pmsg(4) + pmsg(5) + CChar(crc_value.word16.high_byte) +
CChar(crc_value.word16.low_byte)
tsize += 1
Loop
End Sub
Friend Shared Friend Function Make_Bitwise_CRC16(ByVal msg_size As
UInteger) As Integer
Dim i As UInteger
Dim j As UInteger
Dim msg As UInteger
For i = 0 To msg_size - 1
msg = (pmsg(i) << 8)
For j = 0 To 7
If ((msg Xor crc_value.word16) >15) 0 Then
crc = (crc_value.word16 << 1) Xor DefineConstants.POLY
Else
crc_value.word16 <<= 1
End If
msg <<= 1
Next j
Next i
Return(crc_value.word16 Xor 0)
End Function
End Class
'def.h
' Global Type Definitions
' Global Structure Definitions
Public Class byte_low_hi
Public low_byte As Byte
Public high_byte As Byte
End Class
' Global Union Definitions
'C++ to VB CONVERTER TODO TASK: Unions are not supported in VB.
'ORIGINAL LINE: union word_byte
Public Structure word_byte
Public word16 As UInteger
Public byte8 As byte_low_hi
End Structure
'Code Constants
#Const BMS = True ' this represents the binary message start byte, value 0x2A
#Const PASSWD = True ' this represents the factory pass code, value 11548d
#Const POLY = True ' the polynomial used in the CRC algorithm
Friend NotInheritable Class DefineConstants
Public Const BMS As Char = "*"c
Public Const PASSWD As Integer = &H2D1C
Public Const POLY As Integer = &H8005
End Class
--
David Antonhttp://www.tangiblesoftwaresolutions.com
Convert between VB, C#, C++, and Java
Instant C#
Instant VB
Instant C++
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter
"cmdolcet69" wrote:
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[i];
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[i] << 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);
}- Hide quoted text -
- Show quoted text -
How do i decalre UInteger (unsinged integers) in vb 2003- Hide quoted text -
- Show quoted text -

David can you explaine why when i add in the following it says "
UInteger is not defined"

Public Structure word_byte
Public word16 As UInteger
Public byte8 As byte_low_hi
End Structure
When i add Imports System.UInt32 and change it to Uint16 I get the
error on

Public Structure word_byte
Public word16 As UInt16
Public byte8 As byte_low_hi
End Structure

adc_value.word16 = &H0 ' read ADC value and put into storage var
location_value.word16 = &H0
crc_value.word16 = 0
The location_value.word16 = &H0 gives an error "Value of type integer
cannot be converted to System.Uint16

Sep 9 '07 #8

P: n/a
On Sep 9, 3:40 pm, David Anton <DavidAn...@discussions.microsoft.com>
wrote:
The VB type aliases UInteger, ULong, and UShort are only available in VB 2005
and beyond.
For the second problem, just use a cast.
--
David Antonhttp://www.tangiblesoftwaresolutions.com
Convert between VB, C#, C++, and Java
Instant C#
Instant VB
Instant C++
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter

"cmdolcet69" wrote:
On Sep 9, 12:32 pm, David Anton <DavidAn...@discussions.microsoft.com>
wrote:
System.UInt32
--
David Antonhttp://www.tangiblesoftwaresolutions.com
Convert between VB, C#, C++, and Java
Instant C#
Instant VB
Instant C++
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter
"cmdolcet69" wrote:
On Sep 9, 11:12 am, David Anton <DavidAn...@discussions.microsoft.com>
wrote:
(via C++ to VB Converter)
Note that automated conversion from C++ is just a first step. The code
produced below will almost certainly need further adjustments:
Public Class GlobalMembers
'var.c
' Global Union Variables:
Public Shared crc_value As word_byte ' system crc value
Public Shared adc_value As word_byte ' adc value read from table
Public Shared location_value As word_byte ' address of table to send ADC
value
' Global Array Variables
Public Shared pmsg As Byte() = New Byte(24){} ' crc buffer
' Global Variables
Public Shared tsize As UInteger
'Digital Indicator.c
Public Shared Sub table_upload_req()
Dim Len As Byte = &H08
Dim Cmd As Byte = &H09
adc_value.word16 = &H0000 ' read ADC value and put into storage var
location_value.word16 = &H0000
crc_value.word16 = 0
Dim msg_size As Byte = Len-2
pmsg(0) = ChrW(Len)
pmsg(1) = ChrW(Cmd)
Dim i As Integer =0
Do While i<tsize
' single table upload request packet
location_value.word16 += 1
adc_value.word16 = ADC_AVE(i)
pmsg(2) = CChar(adc_value.word16.high_byte)
pmsg(3) = CChar(adc_value.word16.low_byte)
pmsg(4) = CChar(location_value.word16.high_byte)
pmsg(5) = CChar(location_value.word16.low_byte)
crc_value.word16 = Make_Bitwise_CRC16(UInteger msg_size)
com1.Output = DefineConstants.BMS + pmsg(0) + pmsg(1) + pmsg(2) + pmsg(3)
+ pmsg(4) + pmsg(5) + CChar(crc_value.word16.high_byte) +
CChar(crc_value.word16.low_byte)
tsize += 1
Loop
End Sub
Friend Shared Friend Function Make_Bitwise_CRC16(ByVal msg_size As
UInteger) As Integer
Dim i As UInteger
Dim j As UInteger
Dim msg As UInteger
For i = 0 To msg_size - 1
msg = (pmsg(i) << 8)
For j = 0 To 7
If ((msg Xor crc_value.word16) >15) 0 Then
crc = (crc_value.word16 << 1) Xor DefineConstants.POLY
Else
crc_value.word16 <<= 1
End If
msg <<= 1
Next j
Next i
Return(crc_value.word16 Xor 0)
End Function
End Class
'def.h
' Global Type Definitions
' Global Structure Definitions
Public Class byte_low_hi
Public low_byte As Byte
Public high_byte As Byte
End Class
' Global Union Definitions
'C++ to VB CONVERTER TODO TASK: Unions are not supported in VB.
'ORIGINAL LINE: union word_byte
Public Structure word_byte
Public word16 As UInteger
Public byte8 As byte_low_hi
End Structure
'Code Constants
#Const BMS = True ' this represents the binary message start byte, value 0x2A
#Const PASSWD = True ' this represents the factory pass code, value 11548d
#Const POLY = True ' the polynomial used in the CRC algorithm
Friend NotInheritable Class DefineConstants
Public Const BMS As Char = "*"c
Public Const PASSWD As Integer = &H2D1C
Public Const POLY As Integer = &H8005
End Class
--
David Antonhttp://www.tangiblesoftwaresolutions.com
Convert between VB, C#, C++, and Java
Instant C#
Instant VB
Instant C++
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter
"cmdolcet69" wrote:
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[i];
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[i] << 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);
}- Hide quoted text -
- Show quoted text -
How do i decalre UInteger (unsinged integers) in vb 2003- Hide quoted text -
- Show quoted text -
David can you explaine why when i add in the following it says "
UInteger is not defined"
Public Structure word_byte
Public word16 As UInteger
Public byte8 As byte_low_hi
End Structure
When i add Imports System.UInt32 and change it to Uint16 I get the
error on
Public Structure word_byte
Public word16 As UInt16
Public byte8 As byte_low_hi
End Structure
adc_value.word16 = &H0 ' read ADC value and put into storage var
location_value.word16 = &H0
crc_value.word16 = 0
The location_value.word16 = &H0 gives an error "Value of type integer
cannot be converted to System.Uint16- Hide quoted text -

- Show quoted text -
So for the first issue would i just set it to Integer?

Sep 9 '07 #9

P: n/a
Use System.UInt32 instead of UInteger for VB 2003.
--
David Anton
http://www.tangiblesoftwaresolutions.com
Convert between VB, C#, C++, and Java
Instant C#
Instant VB
Instant C++
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter
"cmdolcet69" wrote:
On Sep 9, 3:40 pm, David Anton <DavidAn...@discussions.microsoft.com>
wrote:
The VB type aliases UInteger, ULong, and UShort are only available in VB 2005
and beyond.
For the second problem, just use a cast.
--
David Antonhttp://www.tangiblesoftwaresolutions.com
Convert between VB, C#, C++, and Java
Instant C#
Instant VB
Instant C++
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter

"cmdolcet69" wrote:
On Sep 9, 12:32 pm, David Anton <DavidAn...@discussions.microsoft.com>
wrote:
System.UInt32
--
David Antonhttp://www.tangiblesoftwaresolutions.com
Convert between VB, C#, C++, and Java
Instant C#
Instant VB
Instant C++
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter
"cmdolcet69" wrote:
On Sep 9, 11:12 am, David Anton <DavidAn...@discussions.microsoft.com>
wrote:
(via C++ to VB Converter)
Note that automated conversion from C++ is just a first step. The code
produced below will almost certainly need further adjustments:
Public Class GlobalMembers
'var.c
' Global Union Variables:
Public Shared crc_value As word_byte ' system crc value
Public Shared adc_value As word_byte ' adc value read from table
Public Shared location_value As word_byte ' address of table to send ADC
value
' Global Array Variables
Public Shared pmsg As Byte() = New Byte(24){} ' crc buffer
' Global Variables
Public Shared tsize As UInteger
'Digital Indicator.c
Public Shared Sub table_upload_req()
Dim Len As Byte = &H08
Dim Cmd As Byte = &H09
adc_value.word16 = &H0000 ' read ADC value and put into storage var
location_value.word16 = &H0000
crc_value.word16 = 0
Dim msg_size As Byte = Len-2
pmsg(0) = ChrW(Len)
pmsg(1) = ChrW(Cmd)
Dim i As Integer =0
Do While i<tsize
' single table upload request packet
location_value.word16 += 1
adc_value.word16 = ADC_AVE(i)
pmsg(2) = CChar(adc_value.word16.high_byte)
pmsg(3) = CChar(adc_value.word16.low_byte)
pmsg(4) = CChar(location_value.word16.high_byte)
pmsg(5) = CChar(location_value.word16.low_byte)
crc_value.word16 = Make_Bitwise_CRC16(UInteger msg_size)
com1.Output = DefineConstants.BMS + pmsg(0) + pmsg(1) + pmsg(2) + pmsg(3)
+ pmsg(4) + pmsg(5) + CChar(crc_value.word16.high_byte) +
CChar(crc_value.word16.low_byte)
tsize += 1
Loop
End Sub
Friend Shared Friend Function Make_Bitwise_CRC16(ByVal msg_size As
UInteger) As Integer
Dim i As UInteger
Dim j As UInteger
Dim msg As UInteger
For i = 0 To msg_size - 1
msg = (pmsg(i) << 8)
For j = 0 To 7
If ((msg Xor crc_value.word16) >15) 0 Then
crc = (crc_value.word16 << 1) Xor DefineConstants.POLY
Else
crc_value.word16 <<= 1
End If
msg <<= 1
Next j
Next i
Return(crc_value.word16 Xor 0)
End Function
End Class
'def.h
' Global Type Definitions
' Global Structure Definitions
Public Class byte_low_hi
Public low_byte As Byte
Public high_byte As Byte
End Class
' Global Union Definitions
'C++ to VB CONVERTER TODO TASK: Unions are not supported in VB.
'ORIGINAL LINE: union word_byte
Public Structure word_byte
Public word16 As UInteger
Public byte8 As byte_low_hi
End Structure
'Code Constants
#Const BMS = True ' this represents the binary message start byte, value 0x2A
#Const PASSWD = True ' this represents the factory pass code, value 11548d
#Const POLY = True ' the polynomial used in the CRC algorithm
Friend NotInheritable Class DefineConstants
Public Const BMS As Char = "*"c
Public Const PASSWD As Integer = &H2D1C
Public Const POLY As Integer = &H8005
End Class
--
David Antonhttp://www.tangiblesoftwaresolutions.com
Convert between VB, C#, C++, and Java
Instant C#
Instant VB
Instant C++
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter
"cmdolcet69" wrote:
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[i];
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[i] << 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);
}- Hide quoted text -
- Show quoted text -
How do i decalre UInteger (unsinged integers) in vb 2003- Hide quoted text -
- Show quoted text -
David can you explaine why when i add in the following it says "
UInteger is not defined"
Public Structure word_byte
Public word16 As UInteger
Public byte8 As byte_low_hi
End Structure
When i add Imports System.UInt32 and change it to Uint16 I get the
error on
Public Structure word_byte
Public word16 As UInt16
Public byte8 As byte_low_hi
End Structure
adc_value.word16 = &H0 ' read ADC value and put into storage var
location_value.word16 = &H0
crc_value.word16 = 0
The location_value.word16 = &H0 gives an error "Value of type integer
cannot be converted to System.Uint16- Hide quoted text -
- Show quoted text -

So for the first issue would i just set it to Integer?

Sep 9 '07 #10

P: n/a
On Sep 9, 3:40 pm, David Anton <DavidAn...@discussions.microsoft.com>
wrote:
The VB type aliases UInteger, ULong, and UShort are only available in VB 2005
and beyond.
For the second problem, just use a cast.
--
David Antonhttp://www.tangiblesoftwaresolutions.com
Convert between VB, C#, C++, and Java
Instant C#
Instant VB
Instant C++
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter

"cmdolcet69" wrote:
On Sep 9, 12:32 pm, David Anton <DavidAn...@discussions.microsoft.com>
wrote:
System.UInt32
--
David Antonhttp://www.tangiblesoftwaresolutions.com
Convert between VB, C#, C++, and Java
Instant C#
Instant VB
Instant C++
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter
"cmdolcet69" wrote:
On Sep 9, 11:12 am, David Anton <DavidAn...@discussions.microsoft.com>
wrote:
(via C++ to VB Converter)
Note that automated conversion from C++ is just a first step. The code
produced below will almost certainly need further adjustments:
Public Class GlobalMembers
'var.c
' Global Union Variables:
Public Shared crc_value As word_byte ' system crc value
Public Shared adc_value As word_byte ' adc value read from table
Public Shared location_value As word_byte ' address of table to send ADC
value
' Global Array Variables
Public Shared pmsg As Byte() = New Byte(24){} ' crc buffer
' Global Variables
Public Shared tsize As UInteger
'Digital Indicator.c
Public Shared Sub table_upload_req()
Dim Len As Byte = &H08
Dim Cmd As Byte = &H09
adc_value.word16 = &H0000 ' read ADC value and put into storage var
location_value.word16 = &H0000
crc_value.word16 = 0
Dim msg_size As Byte = Len-2
pmsg(0) = ChrW(Len)
pmsg(1) = ChrW(Cmd)
Dim i As Integer =0
Do While i<tsize
' single table upload request packet
location_value.word16 += 1
adc_value.word16 = ADC_AVE(i)
pmsg(2) = CChar(adc_value.word16.high_byte)
pmsg(3) = CChar(adc_value.word16.low_byte)
pmsg(4) = CChar(location_value.word16.high_byte)
pmsg(5) = CChar(location_value.word16.low_byte)
crc_value.word16 = Make_Bitwise_CRC16(UInteger msg_size)
com1.Output = DefineConstants.BMS + pmsg(0) + pmsg(1) + pmsg(2) + pmsg(3)
+ pmsg(4) + pmsg(5) + CChar(crc_value.word16.high_byte) +
CChar(crc_value.word16.low_byte)
tsize += 1
Loop
End Sub
Friend Shared Friend Function Make_Bitwise_CRC16(ByVal msg_size As
UInteger) As Integer
Dim i As UInteger
Dim j As UInteger
Dim msg As UInteger
For i = 0 To msg_size - 1
msg = (pmsg(i) << 8)
For j = 0 To 7
If ((msg Xor crc_value.word16) >15) 0 Then
crc = (crc_value.word16 << 1) Xor DefineConstants.POLY
Else
crc_value.word16 <<= 1
End If
msg <<= 1
Next j
Next i
Return(crc_value.word16 Xor 0)
End Function
End Class
'def.h
' Global Type Definitions
' Global Structure Definitions
Public Class byte_low_hi
Public low_byte As Byte
Public high_byte As Byte
End Class
' Global Union Definitions
'C++ to VB CONVERTER TODO TASK: Unions are not supported in VB.
'ORIGINAL LINE: union word_byte
Public Structure word_byte
Public word16 As UInteger
Public byte8 As byte_low_hi
End Structure
'Code Constants
#Const BMS = True ' this represents the binary message start byte, value 0x2A
#Const PASSWD = True ' this represents the factory pass code, value 11548d
#Const POLY = True ' the polynomial used in the CRC algorithm
Friend NotInheritable Class DefineConstants
Public Const BMS As Char = "*"c
Public Const PASSWD As Integer = &H2D1C
Public Const POLY As Integer = &H8005
End Class
--
David Antonhttp://www.tangiblesoftwaresolutions.com
Convert between VB, C#, C++, and Java
Instant C#
Instant VB
Instant C++
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter
"cmdolcet69" wrote:
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[i];
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[i] << 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);
}- Hide quoted text -
- Show quoted text -
How do i decalre UInteger (unsinged integers) in vb 2003- Hide quoted text -
- Show quoted text -
David can you explaine why when i add in the following it says "
UInteger is not defined"
Public Structure word_byte
Public word16 As UInteger
Public byte8 As byte_low_hi
End Structure
When i add Imports System.UInt32 and change it to Uint16 I get the
error on
Public Structure word_byte
Public word16 As UInt16
Public byte8 As byte_low_hi
End Structure
adc_value.word16 = &H0 ' read ADC value and put into storage var
location_value.word16 = &H0
crc_value.word16 = 0
The location_value.word16 = &H0 gives an error "Value of type integer
cannot be converted to System.Uint16- Hide quoted text -

- Show quoted text -
Sorry for that blank post...anyways How would i then represent this in
vb 2003?

Sep 9 '07 #11

P: n/a
On Sep 9, 4:04 pm, David Anton <DavidAn...@discussions.microsoft.com>
wrote:
Use System.UInt32 instead of UInteger for VB 2003.
--
David Antonhttp://www.tangiblesoftwaresolutions.com
Convert between VB, C#, C++, and Java
Instant C#
Instant VB
Instant C++
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter

"cmdolcet69" wrote:
On Sep 9, 3:40 pm, David Anton <DavidAn...@discussions.microsoft.com>
wrote:
The VB type aliases UInteger, ULong, and UShort are only available inVB 2005
and beyond.
For the second problem, just use a cast.
--
David Antonhttp://www.tangiblesoftwaresolutions.com
Convert between VB, C#, C++, and Java
Instant C#
Instant VB
Instant C++
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter
"cmdolcet69" wrote:
On Sep 9, 12:32 pm, David Anton <DavidAn...@discussions.microsoft.com>
wrote:
System.UInt32
--
David Antonhttp://www.tangiblesoftwaresolutions.com
Convert between VB, C#, C++, and Java
Instant C#
Instant VB
Instant C++
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter
"cmdolcet69" wrote:
On Sep 9, 11:12 am, David Anton <DavidAn...@discussions.microsoft.com>
wrote:
(via C++ to VB Converter)
Note that automated conversion from C++ is just a first step.The code
produced below will almost certainly need further adjustments:
Public Class GlobalMembers
'var.c
' Global Union Variables:
Public Shared crc_value As word_byte ' system crc value
Public Shared adc_value As word_byte ' adc value readfrom table
Public Shared location_value As word_byte ' address of table to send ADC
value
' Global Array Variables
Public Shared pmsg As Byte() = New Byte(24){} ' crcbuffer
' Global Variables
Public Shared tsize As UInteger
'Digital Indicator.c
Public Shared Sub table_upload_req()
Dim Len As Byte = &H08
Dim Cmd As Byte = &H09
adc_value.word16 = &H0000 ' read ADC value and put into storage var
location_value.word16 = &H0000
crc_value.word16 = 0
Dim msg_size As Byte = Len-2
pmsg(0) = ChrW(Len)
pmsg(1) = ChrW(Cmd)
Dim i As Integer =0
Do While i<tsize
' single table upload request packet
location_value.word16 += 1
adc_value.word16 = ADC_AVE(i)
pmsg(2) = CChar(adc_value.word16.high_byte)
pmsg(3) = CChar(adc_value.word16.low_byte)
pmsg(4) = CChar(location_value.word16.high_byte)
pmsg(5) = CChar(location_value.word16.low_byte)
crc_value.word16 = Make_Bitwise_CRC16(UInteger msg_size)
com1.Output = DefineConstants.BMS +pmsg(0) + pmsg(1) + pmsg(2) + pmsg(3)
+ pmsg(4) + pmsg(5) + CChar(crc_value.word16.high_byte) +
CChar(crc_value.word16.low_byte)
tsize += 1
Loop
End Sub
Friend Shared Friend Function Make_Bitwise_CRC16(ByVal msg_size As
UInteger) As Integer
Dim i As UInteger
Dim j As UInteger
Dim msg As UInteger
For i = 0 To msg_size - 1
msg = (pmsg(i) << 8)
For j = 0 To 7
If ((msg Xor crc_value.word16) >15) 0 Then
crc = (crc_value.word16 << 1) Xor DefineConstants.POLY
Else
crc_value.word16 <<= 1
End If
msg <<= 1
Next j
Next i
Return(crc_value.word16 Xor 0)
End Function
End Class
'def.h
' Global Type Definitions
' Global Structure Definitions
Public Class byte_low_hi
Public low_byte As Byte
Public high_byte As Byte
End Class
' Global Union Definitions
'C++ to VB CONVERTER TODO TASK: Unions are not supported in VB.
'ORIGINAL LINE: union word_byte
Public Structure word_byte
Public word16 As UInteger
Public byte8 As byte_low_hi
End Structure
'Code Constants
#Const BMS = True ' this represents the binary message start byte, value 0x2A
#Const PASSWD = True ' this represents the factory pass code, value 11548d
#Const POLY = True ' the polynomial used in the CRC algorithm
Friend NotInheritable Class DefineConstants
Public Const BMS As Char = "*"c
Public Const PASSWD As Integer = &H2D1C
Public Const POLY As Integer = &H8005
End Class
--
David Antonhttp://www.tangiblesoftwaresolutions.com
Convert between VB, C#, C++, and Java
Instant C#
Instant VB
Instant C++
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter
"cmdolcet69" wrote:
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 an8-bit
unsigned value
typedef unsigned int word; // 'word' is a16-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 crcvalue
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[i];
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[i] << 8) ;
for(j = 0; j < 8; j++) {
if ( ((msg ^ crc_value.word16) >15) 0)
crc

...

read more - Hide quoted text -

- Show quoted text -
How can i fix this issue?

I get the following error - "Operator '+' is not define for types
System.Int32 and Integer"

location_value.word16 += 1

Sep 9 '07 #12

P: n/a
It should also be noted that because unsigned numbers are non-CLS compliant,
VB 2003 does not support operations (+, -, /, *, etc.) on unsigned numbers.
C# 2003 does support unsigned numbers, but it is still non-CLS compliant. It
is a "language feature". This "langauage feature" was then extended to VB
2005, but it is still non-CLS compliant.

I personally would use VB2005.

"cmdolcet69" wrote:
On Sep 9, 4:04 pm, David Anton <DavidAn...@discussions.microsoft.com>
wrote:
Use System.UInt32 instead of UInteger for VB 2003.
--
David Antonhttp://www.tangiblesoftwaresolutions.com
Convert between VB, C#, C++, and Java
Instant C#
Instant VB
Instant C++
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter

"cmdolcet69" wrote:
On Sep 9, 3:40 pm, David Anton <DavidAn...@discussions.microsoft.com>
wrote:
The VB type aliases UInteger, ULong, and UShort are only available in VB 2005
and beyond.
For the second problem, just use a cast.
--
David Antonhttp://www.tangiblesoftwaresolutions.com
Convert between VB, C#, C++, and Java
Instant C#
Instant VB
Instant C++
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter
"cmdolcet69" wrote:
On Sep 9, 12:32 pm, David Anton <DavidAn...@discussions.microsoft.com>
wrote:
System.UInt32
--
David Antonhttp://www.tangiblesoftwaresolutions.com
Convert between VB, C#, C++, and Java
Instant C#
Instant VB
Instant C++
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter
"cmdolcet69" wrote:
On Sep 9, 11:12 am, David Anton <DavidAn...@discussions.microsoft.com>
wrote:
(via C++ to VB Converter)
Note that automated conversion from C++ is just a first step. The code
produced below will almost certainly need further adjustments:
Public Class GlobalMembers
'var.c
' Global Union Variables:
Public Shared crc_value As word_byte ' system crc value
Public Shared adc_value As word_byte ' adc value read from table
Public Shared location_value As word_byte ' address of table to send ADC
value
' Global Array Variables
Public Shared pmsg As Byte() = New Byte(24){} ' crc buffer
' Global Variables
Public Shared tsize As UInteger
'Digital Indicator.c
Public Shared Sub table_upload_req()
Dim Len As Byte = &H08
Dim Cmd As Byte = &H09
adc_value.word16 = &H0000 ' read ADC value and put into storage var
location_value.word16 = &H0000
crc_value.word16 = 0
Dim msg_size As Byte = Len-2
pmsg(0) = ChrW(Len)
pmsg(1) = ChrW(Cmd)
Dim i As Integer =0
Do While i<tsize
' single table upload request packet
location_value.word16 += 1
adc_value.word16 = ADC_AVE(i)
pmsg(2) = CChar(adc_value.word16.high_byte)
pmsg(3) = CChar(adc_value.word16.low_byte)
pmsg(4) = CChar(location_value.word16.high_byte)
pmsg(5) = CChar(location_value.word16.low_byte)
crc_value.word16 = Make_Bitwise_CRC16(UInteger msg_size)
com1.Output = DefineConstants.BMS + pmsg(0) + pmsg(1) + pmsg(2) + pmsg(3)
+ pmsg(4) + pmsg(5) + CChar(crc_value.word16.high_byte) +
CChar(crc_value.word16.low_byte)
tsize += 1
Loop
End Sub
Friend Shared Friend Function Make_Bitwise_CRC16(ByVal msg_size As
UInteger) As Integer
Dim i As UInteger
Dim j As UInteger
Dim msg As UInteger
For i = 0 To msg_size - 1
msg = (pmsg(i) << 8)
For j = 0 To 7
If ((msg Xor crc_value.word16) >15) 0 Then
crc = (crc_value.word16 << 1) Xor DefineConstants.POLY
Else
crc_value.word16 <<= 1
End If
msg <<= 1
Next j
Next i
Return(crc_value.word16 Xor 0)
End Function
End Class
'def.h
' Global Type Definitions
' Global Structure Definitions
Public Class byte_low_hi
Public low_byte As Byte
Public high_byte As Byte
End Class
' Global Union Definitions
'C++ to VB CONVERTER TODO TASK: Unions are not supported in VB.
'ORIGINAL LINE: union word_byte
Public Structure word_byte
Public word16 As UInteger
Public byte8 As byte_low_hi
End Structure
'Code Constants
#Const BMS = True ' this represents the binary message start byte, value 0x2A
#Const PASSWD = True ' this represents the factory pass code, value 11548d
#Const POLY = True ' the polynomial used in the CRC algorithm
Friend NotInheritable Class DefineConstants
Public Const BMS As Char = "*"c
Public Const PASSWD As Integer = &H2D1C
Public Const POLY As Integer = &H8005
End Class
--
David Antonhttp://www.tangiblesoftwaresolutions.com
Convert between VB, C#, C++, and Java
Instant C#
Instant VB
Instant C++
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter
"cmdolcet69" wrote:
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[i];
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[i] << 8) ;
for(j = 0; j < 8; j++) {
if ( ((msg ^ crc_value.word16) >15) 0)
crc
...

read more ;- Hide quoted text -

- Show quoted text -

How can i fix this issue?

I get the following error - "Operator '+' is not define for types
System.Int32 and Integer"

location_value.word16 += 1

Sep 10 '07 #13

This discussion thread is closed

Replies have been disabled for this discussion.