ANALYSEUR (SNIFFER) DE TRAMES RS ( SERIE) ET IP

Signaler
Messages postés
412
Date d'inscription
mercredi 19 décembre 2001
Statut
Membre
Dernière intervention
7 avril 2008
-
surfzoid
Messages postés
467
Date d'inscription
vendredi 15 août 2003
Statut
Membre
Dernière intervention
21 avril 2010
-
Cette discussion concerne un article du site. Pour la consulter dans son contexte d'origine, cliquez sur le lien ci-dessous.

https://codes-sources.commentcamarche.net/source/38136-analyseur-sniffer-de-trames-rs-serie-et-ip

surfzoid
Messages postés
467
Date d'inscription
vendredi 15 août 2003
Statut
Membre
Dernière intervention
21 avril 2010

Je viens d"en retrouver ma version C# :-) :
using System;

namespace ComADIByEric

{

/// <summary>

/// Module de gestion du CRC16

/// </summary>

/// <remarks></remarks>

static class CRC16

{

/// <summary>

/// Tableau qui accueuil les 512 valeurs du CRC16

/// </summary>

/// <remarks></remarks>

public static byte[] CRCTable = new byte[512];

/// <summary>

/// Les variables poids fort et poid faible

/// </summary>

/// <remarks></remarks>

public static byte CRC_Low;

public static byte CRC_High;

/// <summary>

/// Definisson le CRC 16

/// </summary>

/// <returns>C'est une fonction, mais elle ne renvoit rien</returns>

/// <remarks></remarks>

public static object crc16def()

{

//Definisson le CRC 16

CRCTable[0] = 0;

CRCTable[1] = 193;

CRCTable[2] = 129;

CRCTable[3] = 64;

CRCTable[4] = 1;

CRCTable[5] = 192;

CRCTable[6] = 128;

CRCTable[7] = 65;

CRCTable[8] = 1;

CRCTable[9] = 192;

CRCTable[10] = 128;

CRCTable[11] = 65;

CRCTable[12] = 0;

CRCTable[13] = 193;

CRCTable[14] = 129;

CRCTable[15] = 64;

CRCTable[16] = 1;

CRCTable[17] = 192;

CRCTable[18] = 128;

CRCTable[19] = 65;

CRCTable[20] = 0;

CRCTable[21] = 193;

CRCTable[22] = 129;

CRCTable[23] = 64;

CRCTable[24] = 0;

CRCTable[25] = 193;

CRCTable[26] = 129;

CRCTable[27] = 64;

CRCTable[28] = 1;

CRCTable[29] = 192;

CRCTable[30] = 128;

CRCTable[31] = 65;

CRCTable[32] = 1;

CRCTable[33] = 192;

CRCTable[34] = 128;

CRCTable[35] = 65;

CRCTable[36] = 0;

CRCTable[37] = 193;

CRCTable[38] = 129;

CRCTable[39] = 64;

CRCTable[40] = 0;

CRCTable[41] = 193;

CRCTable[42] = 129;

CRCTable[43] = 64;

CRCTable[44] = 1;

CRCTable[45] = 192;

CRCTable[46] = 128;

CRCTable[47] = 65;

CRCTable[48] = 0;

CRCTable[49] = 193;

CRCTable[50] = 129;

CRCTable[51] = 64;

CRCTable[52] = 1;

CRCTable[53] = 192;

CRCTable[54] = 128;

CRCTable[55] = 65;

CRCTable[56] = 1;

CRCTable[57] = 192;

CRCTable[58] = 128;

CRCTable[59] = 65;

CRCTable[60] = 0;

CRCTable[61] = 193;

CRCTable[62] = 129;

CRCTable[63] = 64;

CRCTable[64] = 1;

CRCTable[65] = 192;

CRCTable[66] = 128;

CRCTable[67] = 65;

CRCTable[68] = 0;

CRCTable[69] = 193;

CRCTable[70] = 129;

CRCTable[71] = 64;

CRCTable[72] = 0;

CRCTable[73] = 193;

CRCTable[74] = 129;

CRCTable[75] = 64;

CRCTable[76] = 1;

CRCTable[77] = 192;

CRCTable[78] = 128;

CRCTable[79] = 65;

CRCTable[80] = 0;

CRCTable[81] = 193;

CRCTable[82] = 129;

CRCTable[83] = 64;

CRCTable[84] = 1;

CRCTable[85] = 192;

CRCTable[86] = 128;

CRCTable[87] = 65;

CRCTable[88] = 1;

CRCTable[89] = 192;

CRCTable[90] = 128;

CRCTable[91] = 65;

CRCTable[92] = 0;

CRCTable[93] = 193;

CRCTable[94] = 129;

CRCTable[95] = 64;

CRCTable[96] = 0;

CRCTable[97] = 193;

CRCTable[98] = 129;

CRCTable[99] = 64;

CRCTable[100] = 1;

CRCTable[101] = 192;

CRCTable[102] = 128;

CRCTable[103] = 65;

CRCTable[104] = 1;

CRCTable[105] = 192;

CRCTable[106] = 128;

CRCTable[107] = 65;

CRCTable[108] = 0;

CRCTable[109] = 193;

CRCTable[110] = 129;

CRCTable[111] = 64;

CRCTable[112] = 1;

CRCTable[113] = 192;

CRCTable[114] = 128;

CRCTable[115] = 65;

CRCTable[116] = 0;

CRCTable[117] = 193;

CRCTable[118] = 129;

CRCTable[119] = 64;

CRCTable[120] = 0;

CRCTable[121] = 193;

CRCTable[122] = 129;

CRCTable[123] = 64;

CRCTable[124] = 1;

CRCTable[125] = 192;

CRCTable[126] = 128;

CRCTable[127] = 65;

CRCTable[128] = 1;

CRCTable[129] = 192;

CRCTable[130] = 128;

CRCTable[131] = 65;

CRCTable[132] = 0;

CRCTable[133] = 193;

CRCTable[134] = 129;

CRCTable[135] = 64;

CRCTable[136] = 0;

CRCTable[137] = 193;

CRCTable[138] = 129;

CRCTable[139] = 64;

CRCTable[140] = 1;

CRCTable[141] = 192;

CRCTable[142] = 128;

CRCTable[143] = 65;

CRCTable[144] = 0;

CRCTable[145] = 193;

CRCTable[146] = 129;

CRCTable[147] = 64;

CRCTable[148] = 1;

CRCTable[149] = 192;

CRCTable[150] = 128;

CRCTable[151] = 65;

CRCTable[152] = 1;

CRCTable[153] = 192;

CRCTable[154] = 128;

CRCTable[155] = 65;

CRCTable[156] = 0;

CRCTable[157] = 193;

CRCTable[158] = 129;

CRCTable[159] = 64;

CRCTable[160] = 0;

CRCTable[161] = 193;

CRCTable[162] = 129;

CRCTable[163] = 64;

CRCTable[164] = 1;

CRCTable[165] = 192;

CRCTable[166] = 128;

CRCTable[167] = 65;

CRCTable[168] = 1;

CRCTable[169] = 192;

CRCTable[170] = 128;

CRCTable[171] = 65;

CRCTable[172] = 0;

CRCTable[173] = 193;

CRCTable[174] = 129;

CRCTable[175] = 64;

CRCTable[176] = 1;

CRCTable[177] = 192;

CRCTable[178] = 128;

CRCTable[179] = 65;

CRCTable[180] = 0;

CRCTable[181] = 193;

CRCTable[182] = 129;

CRCTable[183] = 64;

CRCTable[184] = 0;

CRCTable[185] = 193;

CRCTable[186] = 129;

CRCTable[187] = 64;

CRCTable[188] = 1;

CRCTable[189] = 192;

CRCTable[190] = 128;

CRCTable[191] = 65;

CRCTable[192] = 0;

CRCTable[193] = 193;

CRCTable[194] = 129;

CRCTable[195] = 64;

CRCTable[196] = 1;

CRCTable[197] = 192;

CRCTable[198] = 128;

CRCTable[199] = 65;

CRCTable[200] = 1;

CRCTable[201] = 192;

CRCTable[202] = 128;

CRCTable[203] = 65;

CRCTable[204] = 0;

CRCTable[205] = 193;

CRCTable[206] = 129;

CRCTable[207] = 64;

CRCTable[208] = 1;

CRCTable[209] = 192;

CRCTable[210] = 128;

CRCTable[211] = 65;

CRCTable[212] = 0;

CRCTable[213] = 193;

CRCTable[214] = 129;

CRCTable[215] = 64;

CRCTable[216] = 0;

CRCTable[217] = 193;

CRCTable[218] = 129;

CRCTable[219] = 64;

CRCTable[220] = 1;

CRCTable[221] = 192;

CRCTable[222] = 128;

CRCTable[223] = 65;

CRCTable[224] = 1;

CRCTable[225] = 192;

CRCTable[226] = 128;

CRCTable[227] = 65;

CRCTable[228] = 0;

CRCTable[229] = 193;

CRCTable[230] = 129;

CRCTable[231] = 64;

CRCTable[232] = 0;

CRCTable[233] = 193;

CRCTable[234] = 129;

CRCTable[235] = 64;

CRCTable[236] = 1;

CRCTable[237] = 192;

CRCTable[238] = 128;

CRCTable[239] = 65;

CRCTable[240] = 0;

CRCTable[241] = 193;

CRCTable[242] = 129;

CRCTable[243] = 64;

CRCTable[244] = 1;

CRCTable[245] = 192;

CRCTable[246] = 128;

CRCTable[247] = 65;

CRCTable[248] = 1;

CRCTable[249] = 192;

CRCTable[250] = 128;

CRCTable[251] = 65;

CRCTable[252] = 0;

CRCTable[253] = 193;

CRCTable[254] = 129;

CRCTable[255] = 64;

CRCTable[256] = 0;

CRCTable[257] = 192;

CRCTable[258] = 193;

CRCTable[259] = 1;

CRCTable[260] = 195;

CRCTable[261] = 3;

CRCTable[262] = 2;

CRCTable[263] = 194;

CRCTable[264] = 198;

CRCTable[265] = 6;

CRCTable[266] = 7;

CRCTable[267] = 199;

CRCTable[268] = 5;

CRCTable[269] = 197;

CRCTable[270] = 196;

CRCTable[271] = 4;

CRCTable[272] = 204;

CRCTable[273] = 12;

CRCTable[274] = 13;

CRCTable[275] = 205;

CRCTable[276] = 15;

CRCTable[277] = 207;

CRCTable[278] = 206;

CRCTable[279] = 14;

CRCTable[280] = 10;

CRCTable[281] = 202;

CRCTable[282] = 203;

CRCTable[283] = 11;

CRCTable[284] = 201;

CRCTable[285] = 9;

CRCTable[286] = 8;

CRCTable[287] = 200;

CRCTable[288] = 216;

CRCTable[289] = 24;

CRCTable[290] = 25;

CRCTable[291] = 217;

CRCTable[292] = 27;

CRCTable[293] = 219;

CRCTable[294] = 218;

CRCTable[295] = 26;

CRCTable[296] = 30;

CRCTable[297] = 222;

CRCTable[298] = 223;

CRCTable[299] = 31;

CRCTable[300] = 221;

CRCTable[301] = 29;

CRCTable[302] = 28;

CRCTable[303] = 220;

CRCTable[304] = 20;

CRCTable[305] = 212;

CRCTable[306] = 213;

CRCTable[307] = 21;

CRCTable[308] = 215;

CRCTable[309] = 23;

CRCTable[310] = 22;

CRCTable[311] = 214;

CRCTable[312] = 210;

CRCTable[313] = 18;

CRCTable[314] = 19;

CRCTable[315] = 211;

CRCTable[316] = 17;

CRCTable[317] = 209;

CRCTable[318] = 208;

CRCTable[319] = 16;

CRCTable[320] = 240;

CRCTable[321] = 48;

CRCTable[322] = 49;

CRCTable[323] = 241;

CRCTable[324] = 51;

CRCTable[325] = 243;

CRCTable[326] = 242;

CRCTable[327] = 50;

CRCTable[328] = 54;

CRCTable[329] = 246;

CRCTable[330] = 247;

CRCTable[331] = 55;

CRCTable[332] = 245;

CRCTable[333] = 53;

CRCTable[334] = 52;

CRCTable[335] = 244;

CRCTable[336] = 60;

CRCTable[337] = 252;

CRCTable[338] = 253;

CRCTable[339] = 61;

CRCTable[340] = 255;

CRCTable[341] = 63;

CRCTable[342] = 62;

CRCTable[343] = 254;

CRCTable[344] = 250;

CRCTable[345] = 58;

CRCTable[346] = 59;

CRCTable[347] = 251;

CRCTable[348] = 57;

CRCTable[349] = 249;

CRCTable[350] = 248;

CRCTable[351] = 56;

CRCTable[352] = 40;

CRCTable[353] = 232;

CRCTable[354] = 233;

CRCTable[355] = 41;

CRCTable[356] = 235;

CRCTable[357] = 43;

CRCTable[358] = 42;

CRCTable[359] = 234;

CRCTable[360] = 238;

CRCTable[361] = 46;

CRCTable[362] = 47;

CRCTable[363] = 239;

CRCTable[364] = 45;

CRCTable[365] = 237;

CRCTable[366] = 236;

CRCTable[367] = 44;

CRCTable[368] = 228;

CRCTable[369] = 36;

CRCTable[370] = 37;

CRCTable[371] = 229;

CRCTable[372] = 39;

CRCTable[373] = 231;

CRCTable[374] = 230;

CRCTable[375] = 38;

CRCTable[376] = 34;

CRCTable[377] = 226;

CRCTable[378] = 227;

CRCTable[379] = 35;

CRCTable[380] = 225;

CRCTable[381] = 33;

CRCTable[382] = 32;

CRCTable[383] = 224;

CRCTable[384] = 160;

CRCTable[385] = 96;

CRCTable[386] = 97;

CRCTable[387] = 161;

CRCTable[388] = 99;

CRCTable[389] = 163;

CRCTable[390] = 162;

CRCTable[391] = 98;

CRCTable[392] = 102;

CRCTable[393] = 166;

CRCTable[394] = 167;

CRCTable[395] = 103;

CRCTable[396] = 165;

CRCTable[397] = 101;

CRCTable[398] = 100;

CRCTable[399] = 164;

CRCTable[400] = 108;

CRCTable[401] = 172;

CRCTable[402] = 173;

CRCTable[403] = 109;

CRCTable[404] = 175;

CRCTable[405] = 111;

CRCTable[406] = 110;

CRCTable[407] = 174;

CRCTable[408] = 170;

CRCTable[409] = 106;

CRCTable[410] = 107;

CRCTable[411] = 171;

CRCTable[412] = 105;

CRCTable[413] = 169;

CRCTable[414] = 168;

CRCTable[415] = 104;

CRCTable[416] = 120;

CRCTable[417] = 184;

CRCTable[418] = 185;

CRCTable[419] = 121;

CRCTable[420] = 187;

CRCTable[421] = 123;

CRCTable[422] = 122;

CRCTable[423] = 186;

CRCTable[424] = 190;

CRCTable[425] = 126;

CRCTable[426] = 127;

CRCTable[427] = 191;

CRCTable[428] = 125;

CRCTable[429] = 189;

CRCTable[430] = 188;

CRCTable[431] = 124;

CRCTable[432] = 180;

CRCTable[433] = 116;

CRCTable[434] = 117;

CRCTable[435] = 181;

CRCTable[436] = 119;

CRCTable[437] = 183;

CRCTable[438] = 182;

CRCTable[439] = 118;

CRCTable[440] = 114;

CRCTable[441] = 178;

CRCTable[442] = 179;

CRCTable[443] = 115;

CRCTable[444] = 177;

CRCTable[445] = 113;

CRCTable[446] = 112;

CRCTable[447] = 176;

CRCTable[448] = 80;

CRCTable[449] = 144;

CRCTable[450] = 145;

CRCTable[451] = 81;

CRCTable[452] = 147;

CRCTable[453] = 83;

CRCTable[454] = 82;

CRCTable[455] = 146;

CRCTable[456] = 150;

CRCTable[457] = 86;

CRCTable[458] = 87;

CRCTable[459] = 151;

CRCTable[460] = 85;

CRCTable[461] = 149;

CRCTable[462] = 148;

CRCTable[463] = 84;

CRCTable[464] = 156;

CRCTable[465] = 92;

CRCTable[466] = 93;

CRCTable[467] = 157;

CRCTable[468] = 95;

CRCTable[469] = 159;

CRCTable[470] = 158;

CRCTable[471] = 94;

CRCTable[472] = 90;

CRCTable[473] = 154;

CRCTable[474] = 155;

CRCTable[475] = 91;

CRCTable[476] = 153;

CRCTable[477] = 89;

CRCTable[478] = 88;

CRCTable[479] = 152;

CRCTable[480] = 136;

CRCTable[481] = 72;

CRCTable[482] = 73;

CRCTable[483] = 137;

CRCTable[484] = 75;

CRCTable[485] = 139;

CRCTable[486] = 138;

CRCTable[487] = 74;

CRCTable[488] = 78;

CRCTable[489] = 142;

CRCTable[490] = 143;

CRCTable[491] = 79;

CRCTable[492] = 141;

CRCTable[493] = 77;

CRCTable[494] = 76;

CRCTable[495] = 140;

CRCTable[496] = 68;

CRCTable[497] = 132;

CRCTable[498] = 133;

CRCTable[499] = 69;

CRCTable[500] = 135;

CRCTable[501] = 71;

CRCTable[502] = 70;

CRCTable[503] = 134;

CRCTable[504] = 130;

CRCTable[505] = 66;

CRCTable[506] = 67;

CRCTable[507] = 131;

CRCTable[508] = 65;

CRCTable[509] = 129;

CRCTable[510] = 128;

CRCTable[511] = 64;

return null;

}

/// <summary>

/// Calcul proprement dit du CRC16

/// </summary>

/// Les données(la trame) pour lesquel ont calcul le CRC16

/// Taille(longueur) de la trame sans les deux Byte du CRC16

/// <remarks></remarks>

public static void CRC_16(string Data, int Length)

{

int i = 0;

byte IndEx = 0;

CRC_Low = 255;

CRC_High = 255;

for (i = 1; i <= Length; i++) {

IndEx = Convert.ToByte(CRC_High ^ Bibliodefonction.Asc(Data.Substring(i, 1)));

CRC_High = Convert.ToByte(CRC_Low ^ CRCTable[IndEx]);

CRC_Low = CRCTable[IndEx + 256];

}

}

}

}
Adn56
Messages postés
1172
Date d'inscription
jeudi 24 mai 2007
Statut
Membre
Dernière intervention
28 septembre 2013
1
ok merci
surfzoid
Messages postés
467
Date d'inscription
vendredi 15 août 2003
Statut
Membre
Dernière intervention
21 avril 2010

Je dois avouer que mon code remonte a loin, mais il me semble, qu'il faut l'appeler qu'une fois, a un moment précis, sinon, libre a toi de la modifier en sub et voir ce que ça donne.
Je crois aussi, que sur les divers exemple, c'est comme ça qu elle est ecrite.
Adn56
Messages postés
1172
Date d'inscription
jeudi 24 mai 2007
Statut
Membre
Dernière intervention
28 septembre 2013
1
salut, surfzoid, revenons à ton code si tu veux bien ;)
pourquoi dasn le module de crc13 tu utilise une fonction plutot qu'une sub ?
il y a une raison ?

Public Function crc16def()
...*512*...
return nothing
end function
@ te lire