void table_upload_req(void){ byte Len = 0x08; byte Cmd = 0x09; adc_value .word16 = 0x0000; //读取ADC值并将 存入存储器中 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 ++){ //单表上传请求包 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;我< 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); } Can anyone give me some ideas on how to convert the following programto vb 2003? I would like to jsut take this code and implement it invb.def.h/* Global Type Definitions */typedef unsigned char byte; // ''byte'' is an 8-bitunsigned valuetypedef unsigned int word; // ''word'' is a 16-bitunsigned 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 ''*'' // thisrepresents the binary message start byte, value 0x2A#define PASSWD 0x2D1C // this represents thefactory pass code, value 11548d#define POLY 0x8005 // the polynomial usedin the CRC algorithmvar.c// Global Union Variables:union word_byte crc_value; // system crc valueunion word_byte adc_value; // adc value read fromtableunion word_byte location_value; // address of table tosend ADC value// Global Array Variablesbyte pmsg [25]; // crc buffer// Global Variablesword tsize;Digital Indicator.cvoid table_upload_req(void) {byte Len = 0x08;byte Cmd = 0x09;adc_value.word16 = 0x0000; // read ADC value and putinto storage varlocation_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 packetlocation_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;elsecrc_value.word16 <<= 1;msg <<= 1;}}return(crc_value.word16 ^ 0);} 解决方案 cm,For some people it is seen as an improvement that you can now use unsignedvalues in VB.Net because that was impossible in version 2002/2003.Cor"cmdolcet69" <co************@hotmail.comschreef in berichtnews:11**********************@o80g2000hse.googlegr oups.com...Can anyone give me some ideas on how to convert the following programto vb 2003? I would like to jsut take this code and implement it invb.def.h/* Global Type Definitions */typedef unsigned char byte; // ''byte'' is an 8-bitunsigned valuetypedef unsigned int word; // ''word'' is a 16-bitunsigned 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 ''*'' // thisrepresents the binary message start byte, value 0x2A#define PASSWD 0x2D1C // this represents thefactory pass code, value 11548d#define POLY 0x8005 // the polynomial usedin the CRC algorithmvar.c// Global Union Variables:union word_byte crc_value; // system crc valueunion word_byte adc_value; // adc value read fromtableunion word_byte location_value; // address of table tosend ADC value// Global Array Variablesbyte pmsg [25]; // crc buffer// Global Variablesword tsize;Digital Indicator.cvoid table_upload_req(void) { byte Len = 0x08; byte Cmd = 0x09; adc_value.word16 = 0x0000; // read ADC value and putinto 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);} On Sep 9, 8:01 am, "Cor Ligthert[MVP]" <[email protected]>wrote:cm,For some people it is seen as an improvement that you can now use unsignedvalues in VB.Net because that was impossible in version 2002/2003.Cor"cmdolcet69" <[email protected] 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? (via C++ to VB Converter)Note that automated conversion from C++ is just a first step. The codeproduced below will almost certainly need further adjustments:Public Class GlobalMembers''var.c'' Global Union Variables:Public Shared crc_value As word_byte '' system crc valuePublic Shared adc_value As word_byte '' adc value read from tablePublic Shared location_value As word_byte '' address of table to send ADCvalue'' Global Array VariablesPublic Shared pmsg As Byte() = New Byte(24){} '' crc buffer'' Global VariablesPublic Shared tsize As UInteger''Digital Indicator.cPublic Shared Sub table_upload_req()Dim Len As Byte = &H08Dim Cmd As Byte = &H09adc_value.word16 = &H0000 '' read ADC value and put into storage varlocation_value.word16 = &H0000crc_value.word16 = 0Dim msg_size As Byte = Len-2pmsg(0) = ChrW(Len)pmsg(1) = ChrW(Cmd)Dim i As Integer =0Do While i<tsize'' single table upload request packetlocation_value.word16 += 1adc_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 += 1LoopEnd SubFriend Shared Friend Function Make_Bitwise_CRC16(ByVal msg_size AsUInteger) As IntegerDim i As UIntegerDim j As UIntegerDim msg As UIntegerFor i = 0 To msg_size - 1msg = (pmsg(i) << 8)For j = 0 To 7If ((msg Xor crc_value.word16) >15) 0 Thencrc = (crc_value.word16 << 1) Xor DefineConstants.POLYElsecrc_value.word16 <<= 1End Ifmsg <<= 1Next jNext iReturn(crc_value.word16 Xor 0)End FunctionEnd Class''def.h'' Global Type Definitions'' Global Structure DefinitionsPublic Class byte_low_hiPublic low_byte As BytePublic high_byte As ByteEnd Class'' Global Union Definitions''C++ to VB CONVERTER TODO TASK: Unions are not supported in VB.''ORIGINAL LINE: union word_bytePublic Structure word_bytePublic word16 As UIntegerPublic byte8 As byte_low_hiEnd 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 algorithmFriend NotInheritable Class DefineConstantsPublic Const BMS As Char = "*"cPublic Const PASSWD As Integer = &H2D1CPublic Const POLY As Integer = &H8005End Class--David Anton http://www.tangiblesoftwaresolutions.comConvert between VB, C#, C++, and JavaInstant C#Instant VBInstant C++C++ to C# ConverterC++ to VB ConverterC++ to Java Converter"cmdolcet69" wrote:Can anyone give me some ideas on how to convert the following programto vb 2003? I would like to jsut take this code and implement it invb.def.h/* Global Type Definitions */typedef unsigned char byte; // ''byte'' is an 8-bitunsigned valuetypedef unsigned int word; // ''word'' is a 16-bitunsigned 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 ''*'' // thisrepresents the binary message start byte, value 0x2A#define PASSWD 0x2D1C // this represents thefactory pass code, value 11548d#define POLY 0x8005 // the polynomial usedin the CRC algorithmvar.c// Global Union Variables:union word_byte crc_value; // system crc valueunion word_byte adc_value; // adc value read fromtableunion word_byte location_value; // address of table tosend ADC value// Global Array Variablesbyte pmsg [25]; // crc buffer// Global Variablesword tsize;Digital Indicator.cvoid table_upload_req(void) { byte Len = 0x08; byte Cmd = 0x09; adc_value.word16 = 0x0000; // read ADC value and putinto 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);} 这篇关于转换为vb.net 2003的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-29 01:01