luciopro Inserito: 10 gennaio 2008 Segnala Inserito: 10 gennaio 2008 Salve ragazzi,sto cercando una libreria per il calcolo del CRC16 in codesys.Esiste già o me la devo creare....grazie
luciopro Inserita: 10 gennaio 2008 Autore Segnala Inserita: 10 gennaio 2008 ok ragazzi,era + semplice di quanto pensassi.ecco il codice:VariabiliPROGRAM CalcoloCrc16VAR i:WORD; index:WORD; crc_Low:BYTE; crc_high:BYTE; ModbusFrame:ARRAY[0..30] OF BYTE; Length:WORD; value:WORD; startCRC16:BOOL;END_VARVAR CONSTANT crc_table: ARRAY [0..511] OF BYTE := 16#0,16#C1,16#81,16#40,16#1,16#C0,16#80,16#41,16#1,16#C0,16#80,16#41,16#0,16#C1,16#81,16#40,16#1,16#C0,16#80,16#41,16#0,16#C1,16#81,16#40,16#0,16#C1,16#81,16#40,16#1,16#C0, 16#80,16#41,16#1,16#C0,16#80,16#41,16#0,16#C1,16#81,16#40,16#0,16#C1,16#81,16#40,16#1,16#C0,16#80,16#41,16#0,16#C1,16#81,16#40,16#1,16#C0,16#80,16#41,16#1,16#C0,16#80,16#41, 16#0,16#C1,16#81,16#40,16#1,16#C0,16#80,16#41,16#0,16#C1,16#81,16#40,16#0,16#C1,16#81,16#40,16#1,16#C0,16#80,16#41,16#0,16#C1,16#81,16#40,16#1,16#C0,16#80,16#41,16#1,16#C0, 16#80,16#41,16#0,16#C1,16#81,16#40,16#0,16#C1,16#81,16#40,16#1,16#C0,16#80,16#41,16#1,16#C0,16#80,16#41,16#0,16#C1,16#81,16#40,16#1,16#C0,16#80,16#41,16#0,16#C1,16#81,16#40, 16#0,16#C1,16#81,16#40,16#1,16#C0,16#80,16#41,16#1,16#C0,16#80,16#41,16#0,16#C1,16#81,16#40,16#0,16#C1,16#81,16#40,16#1,16#C0,16#80,16#41,16#0,16#C1,16#81,16#40,16#1,16#C0, 16#80,16#41,16#1,16#C0,16#80,16#41,16#0,16#C1,16#81,16#40,16#0,16#C1,16#81,16#40,16#1,16#C0,16#80,16#41,16#1,16#C0,16#80,16#41,16#0,16#C1,16#81,16#40,16#1,16#C0,16#80,16#41, 16#0,16#C1,16#81,16#40,16#0,16#C1,16#81,16#40,16#1,16#C0,16#80,16#41,16#0,16#C1,16#81,16#40,16#1,16#C0,16#80,16#41,16#1,16#C0,16#80,16#41,16#0,16#C1,16#81,16#40,16#1,16#C0, 16#80,16#41,16#0,16#C1,16#81,16#40,16#0,16#C1,16#81,16#40,16#1,16#C0,16#80,16#41,16#1,16#C0,16#80,16#41,16#0,16#C1,16#81,16#40,16#0,16#C1,16#81,16#40,16#1,16#C0,16#80,16#41, 16#0,16#C1,16#81,16#40,16#1,16#C0,16#80,16#41,16#1,16#C0,16#80,16#41,16#0,16#C1,16#81,16#40,16#0,16#C0,16#C1,16#1,16#C3,16#3,16#2,16#C2,16#C6,16#6,16#7,16#C7,16#5,16#C5,16#C4, 16#4,16#CC,16#C,16#D,16#CD,16#F,16#CF,16#CE,16#E,16#A,16#CA,16#CB,16#B,16#C9,16#9,16#8,16#C8,16#D8,16#18,16#19,16#D9,16#1B,16#DB,16#DA,16#1A,16#1E,16#DE,16#DF,16#1F,16#DD, 16#1D,16#1C,16#DC,16#14,16#D4,16#D5,16#15,16#D7,16#17,16#16,16#D6,16#D2,16#12,16#13,16#D3,16#11,16#D1,16#D0,16#10,16#F0,16#30,16#31,16#F1,16#33,16#F3,16#F2,16#32,16#36,16#F6, 16#F7,16#37,16#F5,16#35,16#34,16#F4,16#3C,16#FC,16#FD,16#3D,16#FF,16#3F,16#3E,16#FE,16#FA,16#3A,16#3B,16#FB,16#39,16#F9,16#F8,16#38,16#28,16#E8,16#E9,16#29,16#EB,16#2B,16#2A, 16#EA,16#EE,16#2E,16#2F,16#EF,16#2D,16#ED,16#EC,16#2C,16#E4,16#24,16#25,16#E5,16#27,16#E7,16#E6,16#26,16#22,16#E2,16#E3,16#23,16#E1,16#21,16#20,16#E0,16#A0,16#60,16#61,16#A1, 16#63,16#A3,16#A2,16#62,16#66,16#A6,16#A7,16#67,16#A5,16#65,16#64,16#A4,16#6C,16#AC,16#AD,16#6D,16#AF,16#6F,16#6E,16#AE,16#AA,16#6A,16#6B,16#AB,16#69,16#A9,16#A8,16#68,16#78,16#B8, 16#B9,16#79,16#BB,16#7B,16#7A,16#BA,16#BE,16#7E,16#7F,16#BF,16#7D,16#BD,16#BC,16#7C,16#B4,16#74,16#75,16#B5,16#77,16#B7,16#B6,16#76,16#72,16#B2,16#B3,16#73,16#B1,16#71,16#70, 16#B0,16#50,16#90,16#91,16#51,16#93,16#53,16#52,16#92,16#96,16#56,16#57,16#97,16#55,16#95,16#94,16#54,16#9C,16#5C,16#5D,16#9D,16#5F,16#9F,16#9E,16#5E,16#5A,16#9A,16#9B,16#5B,16#99, 16#59,16#58,16#98,16#88,16#48,16#49,16#89,16#4B,16#8B,16#8A,16#4A,16#4E,16#8E,16#8F,16#4F,16#8D,16#4D,16#4C,16#8C,16#44,16#84,16#85,16#45,16#87,16#47,16#46,16#86,16#82,16#42,16#43, 16#83,16#41,16#81,16#80,16#40;END_VARProgramma:IF StartCRC16 THEN crc_Low:=16#FF; crc_high:=16#FF; FOR i:= 0 TO 30 BY 1 DO IF i<Length THEN index := crc_High XOR modbusframe; crc_High := crc_Low XOR crc_table[index] ; crc_Low := crc_table[index + 256]; END_IF END_FOR StartCRC16:=0; value:=crc_High*256+crc_Low;END_IF(*crc_table[0] 16#0;crc_table[1] 16#C1;crc_table[2] 16#81;crc_table[3] 16#40;crc_table[4] := 16#1;crc_table[5] := 16#C0;crc_table[6] := 16#80;crc_table[7] := 16#41;crc_table[8] := 16#1;crc_table[9] := 16#C0;crc_table[10] := 16#80;crc_table[11] := 16#41;crc_table[12] := 16#0;crc_table[13] := 16#C1;crc_table[14] := 16#81;crc_table[15] := 16#40;crc_table[16] := 16#1;crc_table[17] := 16#C0;crc_table[18] := 16#80;crc_table[19] := 16#41;crc_table[20] := 16#0;crc_table[21] := 16#C1;crc_table[22] := 16#81;crc_table[23] := 16#40;crc_table[24] := 16#0;crc_table[25] := 16#C1;crc_table[26] := 16#81;crc_table[27] := 16#40;crc_table[28] := 16#1;crc_table[29] := 16#C0;crc_table[30] := 16#80;crc_table[31] := 16#41;crc_table[32] := 16#1;crc_table[33] := 16#C0;crc_table[34] := 16#80;crc_table[35] := 16#41;crc_table[36] := 16#0;crc_table[37] := 16#C1;crc_table[38] := 16#81;crc_table[39] := 16#40;crc_table[40] := 16#0;crc_table[41] := 16#C1;crc_table[42] := 16#81;crc_table[43] := 16#40;crc_table[44] := 16#1;crc_table[45] := 16#C0;crc_table[46] := 16#80;crc_table[47] := 16#41;crc_table[48] := 16#0;crc_table[49] := 16#C1;crc_table[50] := 16#81;crc_table[51] := 16#40;crc_table[52] := 16#1;crc_table[53] := 16#C0;crc_table[54] := 16#80;crc_table[55] := 16#41;crc_table[56] := 16#1;crc_table[57] := 16#C0;crc_table[58] := 16#80;crc_table[59] := 16#41;crc_table[60] := 16#0;crc_table[61] := 16#C1;crc_table[62] := 16#81;crc_table[63] := 16#40;crc_table[64] := 16#1;crc_table[65] := 16#C0;crc_table[66] := 16#80;crc_table[67] := 16#41;crc_table[68] := 16#0;crc_table[69] := 16#C1;crc_table[70] := 16#81;crc_table[71] := 16#40;crc_table[72] := 16#0;crc_table[73] := 16#C1;crc_table[74] := 16#81;crc_table[75] := 16#40;crc_table[76] := 16#1;crc_table[77] := 16#C0;crc_table[78] := 16#80;crc_table[79] := 16#41;crc_table[80] := 16#0;crc_table[81] := 16#C1;crc_table[82] := 16#81;crc_table[83] := 16#40;crc_table[84] := 16#1;crc_table[85] := 16#C0;crc_table[86] := 16#80;crc_table[87] := 16#41;crc_table[88] := 16#1;crc_table[89] := 16#C0;crc_table[90] := 16#80;crc_table[91] := 16#41;crc_table[92] := 16#0;crc_table[93] := 16#C1;crc_table[94] := 16#81;crc_table[95] := 16#40;crc_table[96] := 16#0;crc_table[97] := 16#C1;crc_table[98] := 16#81;crc_table[99] := 16#40;crc_table[100] := 16#1;crc_table[101] := 16#C0;crc_table[102] := 16#80;crc_table[103] := 16#41;crc_table[104] := 16#1;crc_table[105] := 16#C0;crc_table[106] := 16#80;crc_table[107] := 16#41;crc_table[108] := 16#0;crc_table[109] := 16#C1;crc_table[110] := 16#81;crc_table[111] := 16#40;crc_table[112] := 16#1;crc_table[113] := 16#C0;crc_table[114] := 16#80;crc_table[115] := 16#41;crc_table[116] := 16#0;crc_table[117] := 16#C1;crc_table[118] := 16#81;crc_table[119] := 16#40;crc_table[120] := 16#0;crc_table[121] := 16#C1;crc_table[122] := 16#81;crc_table[123] := 16#40;crc_table[124] := 16#1;crc_table[125] := 16#C0;crc_table[126] := 16#80;crc_table[127] := 16#41;crc_table[128] := 16#1;crc_table[129] := 16#C0;crc_table[130] := 16#80;crc_table[131] := 16#41;crc_table[132] := 16#0;crc_table[133] := 16#C1;crc_table[134] := 16#81;crc_table[135] := 16#40;crc_table[136] := 16#0;crc_table[137] := 16#C1;crc_table[138] := 16#81;crc_table[139] := 16#40;crc_table[140] := 16#1;crc_table[141] := 16#C0;crc_table[142] := 16#80;crc_table[143] := 16#41;crc_table[144] := 16#0;crc_table[145] := 16#C1;crc_table[146] := 16#81;crc_table[147] := 16#40;crc_table[148] := 16#1;crc_table[149] := 16#C0;crc_table[150] := 16#80;crc_table[151] := 16#41;crc_table[152] := 16#1;crc_table[153] := 16#C0;crc_table[154] := 16#80;crc_table[155] := 16#41;crc_table[156] := 16#0;crc_table[157] := 16#C1;crc_table[158] := 16#81;crc_table[159] := 16#40;crc_table[160] := 16#0;crc_table[161] := 16#C1;crc_table[162] := 16#81;crc_table[163] := 16#40;crc_table[164] := 16#1;crc_table[165] := 16#C0;crc_table[166] := 16#80;crc_table[167] := 16#41;crc_table[168] := 16#1;crc_table[169] := 16#C0;crc_table[170] := 16#80;crc_table[171] := 16#41;crc_table[172] := 16#0;crc_table[173] := 16#C1;crc_table[174] := 16#81;crc_table[175] := 16#40;crc_table[176] := 16#1;crc_table[177] := 16#C0;crc_table[178] := 16#80;crc_table[179] := 16#41;crc_table[180] := 16#0;crc_table[181] := 16#C1;crc_table[182] := 16#81;crc_table[183] := 16#40;crc_table[184] := 16#0;crc_table[185] := 16#C1;crc_table[186] := 16#81;crc_table[187] := 16#40;crc_table[188] := 16#1;crc_table[189] := 16#C0;crc_table[190] := 16#80;crc_table[191] := 16#41;crc_table[192] := 16#0;crc_table[193] := 16#C1;crc_table[194] := 16#81;crc_table[195] := 16#40;crc_table[196] := 16#1;crc_table[197] := 16#C0;crc_table[198] := 16#80;crc_table[199] := 16#41;crc_table[200] := 16#1;crc_table[201] := 16#C0;crc_table[202] := 16#80;crc_table[203] := 16#41;crc_table[204] := 16#0;crc_table[205] := 16#C1;crc_table[206] := 16#81;crc_table[207] := 16#40;crc_table[208] := 16#1;crc_table[209] := 16#C0;crc_table[210] := 16#80;crc_table[211] := 16#41;crc_table[212] := 16#0;crc_table[213] := 16#C1;crc_table[214] := 16#81;crc_table[215] := 16#40;crc_table[216] := 16#0;crc_table[217] := 16#C1;crc_table[218] := 16#81;crc_table[219] := 16#40;crc_table[220] := 16#1;crc_table[221] := 16#C0;crc_table[222] := 16#80;crc_table[223] := 16#41;crc_table[224] := 16#1;crc_table[225] := 16#C0;crc_table[226] := 16#80;crc_table[227] := 16#41;crc_table[228] := 16#0;crc_table[229] := 16#C1;crc_table[230] := 16#81;crc_table[231] := 16#40;crc_table[232] := 16#0;crc_table[233] := 16#C1;crc_table[234] := 16#81;crc_table[235] := 16#40;crc_table[236] := 16#1;crc_table[237] := 16#C0;crc_table[238] := 16#80;crc_table[239] := 16#41;crc_table[240] := 16#0;crc_table[241] := 16#C1;crc_table[242] := 16#81;crc_table[243] := 16#40;crc_table[244] := 16#1;crc_table[245] := 16#C0;crc_table[246] := 16#80;crc_table[247] := 16#41;crc_table[248] := 16#1;crc_table[249] := 16#C0;crc_table[250] := 16#80;crc_table[251] := 16#41;crc_table[252] := 16#0;crc_table[253] := 16#C1;crc_table[254] := 16#81;crc_table[255] := 16#40;crc_table[256] := 16#0;crc_table[257] := 16#C0;crc_table[258] := 16#C1;crc_table[259] := 16#1;crc_table[260] := 16#C3;crc_table[261] := 16#3;crc_table[262] := 16#2;crc_table[263] := 16#C2;crc_table[264] := 16#C6;crc_table[265] := 16#6;crc_table[266] := 16#7;crc_table[267] := 16#C7;crc_table[268] := 16#5;crc_table[269] := 16#C5;crc_table[270] := 16#C4;crc_table[271] := 16#4;crc_table[272] := 16#CC;crc_table[273] := 16#C;crc_table[274] := 16#D;crc_table[275] := 16#CD;crc_table[276] := 16#F;crc_table[277] := 16#CF;crc_table[278] := 16#CE;crc_table[279] := 16#E;crc_table[280] := 16#A;crc_table[281] := 16#CA;crc_table[282] := 16#CB;crc_table[283] := 16#B;crc_table[284] := 16#C9;crc_table[285] := 16#9;crc_table[286] := 16#8;crc_table[287] := 16#C8;crc_table[288] := 16#D8;crc_table[289] := 16#18;crc_table[290] := 16#19;crc_table[291] := 16#D9;crc_table[292] := 16#1B;crc_table[293] := 16#DB;crc_table[294] := 16#DA;crc_table[295] := 16#1A;crc_table[296] := 16#1E;crc_table[297] := 16#DE;crc_table[298] := 16#DF;crc_table[299] := 16#1F;crc_table[300] := 16#DD;crc_table[301] := 16#1D;crc_table[302] := 16#1C;crc_table[303] := 16#DC;crc_table[304] := 16#14;crc_table[305] := 16#D4;crc_table[306] := 16#D5;crc_table[307] := 16#15;crc_table[308] := 16#D7;crc_table[309] := 16#17;crc_table[310] := 16#16;crc_table[311] := 16#D6;crc_table[312] := 16#D2;crc_table[313] := 16#12;crc_table[314] := 16#13;crc_table[315] := 16#D3;crc_table[316] := 16#11;crc_table[317] := 16#D1;crc_table[318] := 16#D0;crc_table[319] := 16#10;crc_table[320] := 16#F0;crc_table[321] := 16#30;crc_table[322] := 16#31;crc_table[323] := 16#F1;crc_table[324] := 16#33;crc_table[325] := 16#F3;crc_table[326] := 16#F2;crc_table[327] := 16#32;crc_table[328] := 16#36;crc_table[329] := 16#F6;crc_table[330] := 16#F7;crc_table[331] := 16#37;crc_table[332] := 16#F5;crc_table[333] := 16#35;crc_table[334] := 16#34;crc_table[335] := 16#F4;crc_table[336] := 16#3C;crc_table[337] := 16#FC;crc_table[338] := 16#FD;crc_table[339] := 16#3D;crc_table[340] := 16#FF;crc_table[341] := 16#3F;crc_table[342] := 16#3E;crc_table[343] := 16#FE;crc_table[344] := 16#FA;crc_table[345] := 16#3A;crc_table[346] := 16#3B;crc_table[347] := 16#FB;crc_table[348] := 16#39;crc_table[349] := 16#F9;crc_table[350] := 16#F8;crc_table[351] := 16#38;crc_table[352] := 16#28;crc_table[353] := 16#E8;crc_table[354] := 16#E9;crc_table[355] := 16#29;crc_table[356] := 16#EB;crc_table[357] := 16#2B;crc_table[358] := 16#2A;crc_table[359] := 16#EA;crc_table[360] := 16#EE;crc_table[361] := 16#2E;crc_table[362] := 16#2F;crc_table[363] := 16#EF;crc_table[364] := 16#2D;crc_table[365] := 16#ED;crc_table[366] := 16#EC;crc_table[367] := 16#2C;crc_table[368] := 16#E4;crc_table[369] := 16#24;crc_table[370] := 16#25;crc_table[371] := 16#E5;crc_table[372] := 16#27;crc_table[373] := 16#E7;crc_table[374] := 16#E6;crc_table[375] := 16#26;crc_table[376] := 16#22;crc_table[377] := 16#E2;crc_table[378] := 16#E3;crc_table[379] := 16#23;crc_table[380] := 16#E1;crc_table[381] := 16#21;crc_table[382] := 16#20;crc_table[383] := 16#E0;crc_table[384] := 16#A0;crc_table[385] := 16#60;crc_table[386] := 16#61;crc_table[387] := 16#A1;crc_table[388] := 16#63;crc_table[389] := 16#A3;crc_table[390] := 16#A2;crc_table[391] := 16#62;crc_table[392] := 16#66;crc_table[393] := 16#A6;crc_table[394] := 16#A7;crc_table[395] := 16#67;crc_table[396] := 16#A5;crc_table[397] := 16#65;crc_table[398] := 16#64;crc_table[399] := 16#A4;crc_table[400] := 16#6C;crc_table[401] := 16#AC;crc_table[402] := 16#AD;crc_table[403] := 16#6D;crc_table[404] := 16#AF;crc_table[405] := 16#6F;crc_table[406] := 16#6E;crc_table[407] := 16#AE;crc_table[408] := 16#AA;crc_table[409] := 16#6A;crc_table[410] := 16#6B;crc_table[411] := 16#AB;crc_table[412] := 16#69;crc_table[413] := 16#A9;crc_table[414] := 16#A8;crc_table[415] := 16#68;crc_table[416] := 16#78;crc_table[417] := 16#B8;crc_table[418] := 16#B9;crc_table[419] := 16#79;crc_table[420] := 16#BB;crc_table[421] := 16#7B;crc_table[422] := 16#7A;crc_table[423] := 16#BA;crc_table[424] := 16#BE;crc_table[425] := 16#7E;crc_table[426] := 16#7F;crc_table[427] := 16#BF;crc_table[428] := 16#7D;crc_table[429] := 16#BD;crc_table[430] := 16#BC;crc_table[431] := 16#7C;crc_table[432] := 16#B4;crc_table[433] := 16#74;crc_table[434] := 16#75;crc_table[435] := 16#B5;crc_table[436] := 16#77;crc_table[437] := 16#B7;crc_table[438] := 16#B6;crc_table[439] := 16#76;crc_table[440] := 16#72;crc_table[441] := 16#B2;crc_table[442] := 16#B3;crc_table[443] := 16#73;crc_table[444] := 16#B1;crc_table[445] := 16#71;crc_table[446] := 16#70;crc_table[447] := 16#B0;crc_table[448] := 16#50;crc_table[449] := 16#90;crc_table[450] := 16#91;crc_table[451] := 16#51;crc_table[452] := 16#93;crc_table[453] := 16#53;crc_table[454] := 16#52;crc_table[455] := 16#92;crc_table[456] := 16#96;crc_table[457] := 16#56;crc_table[458] := 16#57;crc_table[459] := 16#97;crc_table[460] := 16#55;crc_table[461] := 16#95;crc_table[462] := 16#94;crc_table[463] := 16#54;crc_table[464] := 16#9C;crc_table[465] := 16#5C;crc_table[466] := 16#5D;crc_table[467] := 16#9D;crc_table[468] := 16#5F;crc_table[469] := 16#9F;crc_table[470] := 16#9E;crc_table[471] := 16#5E;crc_table[472] := 16#5A;crc_table[473] := 16#9A;crc_table[474] := 16#9B;crc_table[475] := 16#5B;crc_table[476] := 16#99;crc_table[477] := 16#59;crc_table[478] := 16#58;crc_table[479] := 16#98;crc_table[480] := 16#88;crc_table[481] := 16#48;crc_table[482] := 16#49;crc_table[483] := 16#89;crc_table[484] := 16#4B;crc_table[485] := 16#8B;crc_table[486] := 16#8A;crc_table[487] := 16#4A;crc_table[488] := 16#4E;crc_table[489] := 16#8E;crc_table[490] := 16#8F;crc_table[491] := 16#4F;crc_table[492] := 16#8D;crc_table[493] := 16#4D;crc_table[494] := 16#4C;crc_table[495] := 16#8C;crc_table[496] := 16#44;crc_table[497] := 16#84;crc_table[498] := 16#85;crc_table[499] := 16#45;crc_table[500] := 16#87;crc_table[501] := 16#47;crc_table[502] := 16#46;crc_table[503] := 16#86;crc_table[504] := 16#82;crc_table[505] := 16#42;crc_table[506] := 16#43;crc_table[507] := 16#83;crc_table[508] := 16#41;crc_table[509] := 16#81;crc_table[510] := 16#80;crc_table[511] := 16#40;*)
Messaggi consigliati
Crea un account o accedi per commentare
Devi essere un utente per poter lasciare un commento
Crea un account
Registrati per un nuovo account nella nostra comunità. è facile!
Registra un nuovo accountAccedi
Hai già un account? Accedi qui.
Accedi ora