Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > ผมต้องการสร้าง CRC เพื่อนำไปทำ QR CODE ใครพอแนะนำ LIBRARY หรือ code ให้ได้บ้างครับ



 

ผมต้องการสร้าง CRC เพื่อนำไปทำ QR CODE ใครพอแนะนำ LIBRARY หรือ code ให้ได้บ้างครับ

 



Topic : 137149



โพสกระทู้ ( 22 )
บทความ ( 0 )



สถานะออฟไลน์




ตามหัวข้อครับ ผมมีข้อความ เช่น 12345678ADFG125 ผมต้องการหาค่า CRC 4 ตัว และแนบข้อความดังกล่าว โดยปกติแล้ว ผมจะใช้คำนวณจากเวบนี้ครับ https://www.lammertbies.nl/comm/info/crc-calculation แต่เพื่อความสะดวกอยากขอคำแนะนำ จากผู้รู้ด้วยครับว่าจะต้องทำอย่างไรบ้างครับ CRC ที่ผมใช้คือ ซีอาร์ซี-CCITT (0xFFFF) ครับ



Tag : PHP, MySQL, HTML, CSS, JavaScript, Laravel Framework







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2024-01-30 14:11:22 By : treethep View : 157 Reply : 2
 

 

No. 1

Guest


ผมมี code ภาษา C มีผู้รู้ท่านใดแปลงเป็น PHP ได้ไหมครับ

Code
/* * Library: libcrc * File: examples/tstcrc.c * Author: Lammert Bies * * This file is licensed under the MIT License as stated below * * Copyright (c) 1999-2016 Lammert Bies * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * * Description * ----------- * The file tstx_crc.c contains a small sample program which demonstrates the * use of the functions for calculating the CRC-CCITT, CRC-16 and CRC-32 values * of data. The program calculates the three different CRC's for a file who's * name is either provided at the command line, or data typed in right the * program has started. */ #include <inttypes.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include "../include/checksum.h" #define MAX_STRING_SIZE 2048 /* * int main( int argc, char *argv[] ); * * The function main() is the entry point of the example program which * calculates several CRC values from the contents of files, or data from * stdin. */ int main( int argc, char *argv[] ) { char input_string[MAX_STRING_SIZE]; unsigned char *ptr; unsigned char *dest; unsigned char hex_val; unsigned char prev_byte; uint16_t crc_16_val; uint16_t crc_16_modbus_val; uint16_t crc_ccitt_ffff_val; uint16_t crc_ccitt_0000_val; uint16_t crc_ccitt_1d0f_val; uint16_t crc_dnp_val; uint16_t crc_sick_val; uint16_t crc_kermit_val; uint32_t crc_32_val; uint16_t low_byte; uint16_t high_byte; int a; int ch; bool do_ascii; bool do_hex; FILE *fp; do_ascii = false; do_hex = false; printf( "\ntstcrc: CRC algorithm sample program\nCopyright (c) 1999-2016 Lammert Bies\n\n" ); if ( argc < 2 ) { printf( "Usage: tst_crc [-a|-x] file1 ...\n\n" ); printf( " -a Program asks for ASCII input. Following parameters ignored.\n" ); printf( " -x Program asks for hexadecimal input. Following parameters ignored.\n" ); printf( " All other parameters are treated like filenames. The CRC values\n" ); printf( " for each separate file will be calculated.\n" ); exit( 0 ); } if ( ! strcmp( argv[1], "-a" ) || ! strcmp( argv[1], "-A" ) ) do_ascii = true; if ( ! strcmp( argv[1], "-x" ) || ! strcmp( argv[1], "-X" ) ) do_hex = true; if ( do_ascii || do_hex ) { printf( "Input: " ); fgets( input_string, MAX_STRING_SIZE-1, stdin ); } if ( do_ascii ) { ptr = (unsigned char *) input_string; while ( *ptr && *ptr != '\r' && *ptr != '\n' ) ptr++; *ptr = 0; } if ( do_hex ) { ptr = (unsigned char *) input_string; dest = (unsigned char *) input_string; while( *ptr && *ptr != '\r' && *ptr != '\n' ) { if ( *ptr >= '0' && *ptr <= '9' ) *dest++ = (unsigned char) ( (*ptr) - '0' ); if ( *ptr >= 'A' && *ptr <= 'F' ) *dest++ = (unsigned char) ( (*ptr) - 'A' + 10 ); if ( *ptr >= 'a' && *ptr <= 'f' ) *dest++ = (unsigned char) ( (*ptr) - 'a' + 10 ); ptr++; } * dest = '\x80'; *(dest+1) = '\x80'; } a = 1; do { crc_16_val = 0x0000; crc_16_modbus_val = 0xffff; crc_dnp_val = 0x0000; crc_sick_val = 0x0000; crc_ccitt_0000_val = 0x0000; crc_ccitt_ffff_val = 0xffff; crc_ccitt_1d0f_val = 0x1d0f; crc_kermit_val = 0x0000; crc_32_val = 0xffffffffL; if ( do_ascii ) { prev_byte = 0; ptr = (unsigned char *) input_string; while ( *ptr ) { crc_16_val = update_crc_16( crc_16_val, *ptr ); crc_16_modbus_val = update_crc_16( crc_16_modbus_val, *ptr ); crc_dnp_val = update_crc_dnp( crc_dnp_val, *ptr ); crc_sick_val = update_crc_sick( crc_sick_val, *ptr, prev_byte ); crc_ccitt_0000_val = update_crc_ccitt( crc_ccitt_0000_val, *ptr ); crc_ccitt_ffff_val = update_crc_ccitt( crc_ccitt_ffff_val, *ptr ); crc_ccitt_1d0f_val = update_crc_ccitt( crc_ccitt_1d0f_val, *ptr ); crc_kermit_val = update_crc_kermit( crc_kermit_val, *ptr ); crc_32_val = update_crc_32( crc_32_val, *ptr ); prev_byte = *ptr; ptr++; } } else if ( do_hex ) { prev_byte = 0; ptr = (unsigned char *) input_string; while ( *ptr != '\x80' ) { hex_val = (unsigned char) ( ( * ptr & '\x0f' ) << 4 ); hex_val |= (unsigned char) ( ( *(ptr+1) & '\x0f' ) ); crc_16_val = update_crc_16( crc_16_val, hex_val ); crc_16_modbus_val = update_crc_16( crc_16_modbus_val, hex_val ); crc_dnp_val = update_crc_dnp( crc_dnp_val, hex_val ); crc_sick_val = update_crc_sick( crc_sick_val, hex_val, prev_byte ); crc_ccitt_0000_val = update_crc_ccitt( crc_ccitt_0000_val, hex_val ); crc_ccitt_ffff_val = update_crc_ccitt( crc_ccitt_ffff_val, hex_val ); crc_ccitt_1d0f_val = update_crc_ccitt( crc_ccitt_1d0f_val, hex_val ); crc_kermit_val = update_crc_kermit( crc_kermit_val, hex_val ); crc_32_val = update_crc_32( crc_32_val, hex_val ); prev_byte = hex_val; ptr += 2; } input_string[0] = 0; } else { prev_byte = 0; #if defined(_MSC_VER) fp = NULL; fopen_s( & fp, argv[a], "rb" ); #else fp = fopen( argv[a], "rb" ); #endif if ( fp != NULL ) { while( ( ch=fgetc( fp ) ) != EOF ) { crc_16_val = update_crc_16( crc_16_val, (unsigned char) ch ); crc_16_modbus_val = update_crc_16( crc_16_modbus_val, (unsigned char) ch ); crc_dnp_val = update_crc_dnp( crc_dnp_val, (unsigned char) ch ); crc_sick_val = update_crc_sick( crc_sick_val, (unsigned char) ch, prev_byte ); crc_ccitt_0000_val = update_crc_ccitt( crc_ccitt_0000_val, (unsigned char) ch ); crc_ccitt_ffff_val = update_crc_ccitt( crc_ccitt_ffff_val, (unsigned char) ch ); crc_ccitt_1d0f_val = update_crc_ccitt( crc_ccitt_1d0f_val, (unsigned char) ch ); crc_kermit_val = update_crc_kermit( crc_kermit_val, (unsigned char) ch ); crc_32_val = update_crc_32( crc_32_val, (unsigned char) ch ); prev_byte = (unsigned char) ch; } fclose( fp ); } else printf( "%s : cannot open file\n", argv[a] ); } crc_32_val ^= 0xffffffffL; crc_dnp_val = ~crc_dnp_val; low_byte = (crc_dnp_val & 0xff00) >> 8; high_byte = (crc_dnp_val & 0x00ff) << 8; crc_dnp_val = low_byte | high_byte; low_byte = (crc_sick_val & 0xff00) >> 8; high_byte = (crc_sick_val & 0x00ff) << 8; crc_sick_val = low_byte | high_byte; low_byte = (crc_kermit_val & 0xff00) >> 8; high_byte = (crc_kermit_val & 0x00ff) << 8; crc_kermit_val = low_byte | high_byte; printf( "%s%s%s :\nCRC16 = 0x%04" PRIX16 " / %" PRIu16 "\n" "CRC16 (Modbus) = 0x%04" PRIX16 " / %" PRIu16 "\n" "CRC16 (Sick) = 0x%04" PRIX16 " / %" PRIu16 "\n" "CRC-CCITT (0x0000) = 0x%04" PRIX16 " / %" PRIu16 "\n" "CRC-CCITT (0xffff) = 0x%04" PRIX16 " / %" PRIu16 "\n" "CRC-CCITT (0x1d0f) = 0x%04" PRIX16 " / %" PRIu16 "\n" "CRC-CCITT (Kermit) = 0x%04" PRIX16 " / %" PRIu16 "\n" "CRC-DNP = 0x%04" PRIX16 " / %" PRIu16 "\n" "CRC32 = 0x%08" PRIX32 " / %" PRIu32 "\n" , ( do_ascii || do_hex ) ? "\"" : "" , ( ! do_ascii && ! do_hex ) ? argv[a] : input_string , ( do_ascii || do_hex ) ? "\"" : "" , crc_16_val, crc_16_val , crc_16_modbus_val, crc_16_modbus_val , crc_sick_val, crc_sick_val , crc_ccitt_0000_val, crc_ccitt_0000_val , crc_ccitt_ffff_val, crc_ccitt_ffff_val , crc_ccitt_1d0f_val, crc_ccitt_1d0f_val , crc_kermit_val, crc_kermit_val , crc_dnp_val, crc_dnp_val , crc_32_val, crc_32_val ); a++; } while ( a < argc ); return 0; } /* main (tstcrc.c) */







แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2024-02-07 10:05:56 By : treethep
 


 

No. 2



โพสกระทู้ ( 5,146 )
บทความ ( 26 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์


Code (PHP)
require_once "vendor/autoload.php";

use voku\helper\HtmlDomParser;

$links = 'https://www.lammertbies.nl/include/crc-calculation.php?crc=123456789&method=ascii';

function getCRC($url)
{
    $datalist = array();

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36");
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    $pageHtml = curl_exec($curl);
    curl_close($curl);

    $scrapDATA = HtmlDomParser::str_get_html($pageHtml);
    $DATAElement = $scrapDATA->find("table.pinout>tr>td");
    foreach ($DATAElement as $k => $v) { 
        if ($k > 1)
            $datalist[] = $v->plaintext; 
    }
    return $datalist;
}
$data = getCRC($links);
echo "<pre>";
print_r($data);


ถ้าแปลงเองไม่ได้ ก็ scraping จากเว็บมาใช้เลยก็ได้ครับ

deawx
LINE 0890499359
[email protected]
ปรึกษา PHP ฟรีจ้า
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2024-03-04 10:09:34 By : deawx
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ผมต้องการสร้าง CRC เพื่อนำไปทำ QR CODE ใครพอแนะนำ LIBRARY หรือ code ให้ได้บ้างครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 02
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่