Serial Port Interrupts and io.intenabled
The ser. object uses your device's interrupt lines in three cases:
- When operating in the UART mode (ser.mode = 0 — PL_SER_MODE_UART) with RTS/CTS flow control enabled (ser.flowcontrol = 1 — PL_SER_FC_RTSCTS).
- When operating in the Wiegand mode (ser.mode = 1 — PL_SER_MODE_WIEGAND).
- When operating in the clock/data mode (ser.mode = 2 — PL_SER_MODE_CLOCKDATA).
The same set of interrupts lines is available to your application through the io. object, its io.intnum and io.intenabled properties, and the io_on_int() event.
Depending on the platform, the use of interrupt lines by the ser. object and the use of interrupt lines by the io. object may be either independent or interdependent.
Platforms With Independent Handling of ser. and io. Interrupts
On such platforms, you can enable and disable interrupt lines (through io.intnum and io.intenabled) without disturbing the operation of the serial port. For example, if a serial port on the EM1000 is running in the Wiegand mode and uses the interrupt line 0 as a W0&1in line, you can enable this interrupt line in the io. object, then disable it, and the operation of the serial port won't be disturbed.
At the same time, the use of an interrupt line by the serial port does not show in the value of the io.intenabled property.
Platforms With Interdependent Handling of ser. and io. Interrupts
On some platforms (for example, the TPP2) the ser. object openly uses the io. object's interrupts. The rules:
- Whenever a serial port is enabled and configured in a way that requires the use of an interrupt line (see above), the corresponding interrupt line of the io. object will show that it is enabled (io.intenabled = 1 — ENABLED).
- Disabling the serial port or configuring in a way that does not require the use of an interrupt line will disable the corresponding interrupt line (io.intenabled to 0 — DISABLED).
- Attempting to disable this interrupt line (setting io.intenabled = 0 — DISABLED) while this line is in use by a serial port will not work and the line will remain enabled.
This Test Code Shows the Difference
Run the following test code on a device with dependent interrupts (such as the EM1000) and a device with interdependent interrupts (such as the EM2000).
sub on_sys_init() ser.num=0 'for clarity ser.mode=PL_SER_MODE_WIEGAND 'this will require the use of the interrupt line 0 ser.enabled=YES io.intnum=0 'for clarity if io.intenabled=NO then sys.debugprint("Int line 0 appears disabled, even though the serial port 0 is using it.\x0D") sys.debugprint("Enabling the int line 0...\x0D") io.intenabled=YES 'enable the line else sys.debugprint("Int line 0 is enabled -- this is because the serial port 0 is using it.\x0D") end if sys.debugprint("Now will try to disable the line...\x0D") io.intenabled=NO if io.intenabled=NO then sys.debugprint("The int line 0 was successfully disabled.\x0D") else sys.debugprint("The int line 0 is still enabled (ser. object is preventing this.\x0D") sys.debugprint("Disable serial port and try again...\x0D") ser.enabled=NO if io.enabled=NO then sys.debugprint("Now that the serial port is closed the int line is disabled.\x0D") else sys.debugprint("Hmmmm.... how did this happen.\x0D") end if end if end sub
Here is the Debug pane output for the EM1000:
Enabling the int line 0...
Now will try to disable the line...
The int line 0 was successfully disabled.
And now for the EM2000:
Now will try to disable the line...
The int line 0 is still enabled (ser. object is preventing this.
Disable serial port and try again...
Now that the serial port is closed the line is disabled.