C # using Activex to read RFID from a Web Client

Source: Internet
Author: User

Because RFID reading is used in Web projects, it is necessary to develop Activex. Generally, Activex is developed using VC, VB, etc. However, these two parts are not very familiar, therefore, C # is used to compile Activex. For more information, see network 1. compile WindowsFromControls2. publish WindowsFormControls to Activex3. use this Activex in the web. First, compile the windows Control and do not elaborate on it. (Note that a guid is generated by using the vs tool, which will be used below. My0CBD6597-3953-4B88-8C9F-F58B1B023413) Important classes:
View sourceprint? Using System; using System. runtime. interopServices; namespace RFIDReader {public class ReadRfid {[DllImport ("MasterRD. dll ")] private static extern int rf_init_com (int port, int baud); [DllImport (" MasterRD. dll ")] private static extern int rf_request (short icdev, byte model, ref short TagType); [DllImport (" MasterRD. dll ")] private static extern int rf_write (int icdev, char _ Adr, char _ Data); [DllImp Ort ("MasterRD. dll ")] private static extern int rf_anticoll (short icdev, byte bcnt, ref byte PSNR, ref byte pRLength); [DllImport (" MasterRD. dll ")] private static extern int rf_ClosePort (); public string CardNum {get {return getCardNum () ;}} private string getCardNum () {int post = 4; // call the COM1 port int baud = 9600; int I =-1; byte model = 82; byte b1 = 4; short TagType = 4; byte [] buf1 = new byte [2 00]; try {rf_init_com (post, baud); rf_request (0, model, ref TagType); rf_anticoll (0, 4, ref buf1 [0], ref b1 ); string s1 = ""; for (I = 0; I <b1; I ++) {s1 = s1 + System. convert. toString (long. parse (buf1 [I]. toString (), 16 ). toUpper ();} rf_ClosePort (); if (s1 = "0000") {throw (new Exception ();} return s1 ;} catch (Exception) {} return "" ;}}} view sourceprint? View sourceprint? Using System; using System. collections. generic; using System. linq; using System. text; using System. runtime. interopServices; namespace RFIDReader {[ComImport, guidattriort ("<SPAN style =" COLOR: #800000 "> 0CBD6597-3953-4B88-8C9F-F58B1B023413 </SPAN> <SPAN style =" COLOR: #800000 "> </SPAN>")] [InterfaceTypeAttribute (ComInterfaceType. interfaceIsIUnknown)] public interface IObjectSafety {[PreserveSig] void GetInterfacceSafyOptions (int riid, out int trim, out int pdwEnabledOptions); [PreserveSig] void trim (int riid, int trim, int dwEnabledOptions) ;}} using System; using System. collections. generic; using System. componentModel; using System. drawing; using System. data; using System. linq; using System. text; using System. windows. forms; using System. runtime. interopServices; using CJ; namespace RFIDReader {[Guid ("0CBD6597-3953-4B88-8C9F-F58B1B

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.