locked
Create a service object that read from virtual COM port RRS feed

  • General discussion

  • I have a RFID scanner which communicate with Windows through a virtual serial port (COM3). I implemented a custom Service Object to manage the device but the DataEvent is not raised when the scanner read a tag. Is there any way to read data from COM port using only the Service Object?

    Here is my code for Service Object

        [ServiceObject(DeviceType.RFIDScanner,
                        "RFID Scanner",
                       "Service object for RFID Scanner", 1, 14)]
    
       public class RFIDReader : RFIDScannerBase
        {
     
            SerialPort port = new SerialPort("COM3",9600,Parity.None,8,StopBits.One);
    
            public RFIDReader()
            {
                Properties.DeviceDescription = "RFID Scanner";
            }
    
            ~RFIDReader()
            {
                Dispose(false);
            }
    
            protected override void Dispose(bool disposing)
            {
                try
                {
                    // Your code here.
                }
                finally
                {
                    // Must call base class Dispose.
                    base.Dispose(disposing);
                }
            }
    
            private string checkhealthtext;
            public override string CheckHealthText
            {
                get
                {
                    // Verify that device is open
                    VerifyState(false, false);
    
                    return checkhealthtext;
                }
            }
    
    
            public override string CheckHealth(HealthCheckLevel level)
            {
                // Verify that device is open, claimed and enabled
                VerifyState(true, true);
    
                // TODO: check the health of the device and return a descriptive string 
    
                // Cache result in the CheckHealthText property
                checkhealthtext = "Ok";
                return checkhealthtext;
            }
    
            public override DirectIOData DirectIO(int command, int data, object obj)
            {
                // Verify that device is open
                VerifyState(false, false);
    
                return new DirectIOData(data, obj);
            }
    
            public override void Open()
            {
                base.Open();
    
                port.Open();
    
                checkhealthtext = "";
    
                // Set values for common statistics
                SetStatisticValue(StatisticManufacturerName, "Promag");
                SetStatisticValue(StatisticManufactureDate, "2004-05-23");
                SetStatisticValue(StatisticModelName, "PCR300A");
                SetStatisticValue(StatisticMechanicalRevision, "1.0");
                SetStatisticValue(StatisticInterface, "COM");
            }

    Friday, August 28, 2015 4:33 PM

All replies

  • You should register the event handler before you open the port.

    Please search MSDN by following text, then refer to the example of that page.

    "SerialPort::DataReceived Event"


    • Edited by Kunif3 Thursday, September 24, 2015 9:19 PM
    Thursday, September 24, 2015 9:18 PM