Port that disappears and reappears is correct port. Note: If any of the following occur, driver for USB-to-serial adapter is not properly installed. Refer to installation CD and instructions that came with adapter, or visit manufacturer's website to locate correct driver to install. After the main files are installed on devices, contact CTS customer support at svc-admin@coloradotime.com or call 970-667-1000, option 3, for a link to the second set of files. This includes 2 files: one for the Dolphin Timers and one for the Dolphin Starter.
-->Defines the control setting for a serial communications device.
Syntax
Members
DCBlength
The length of the structure, in bytes. The caller must set this member tosizeof(DCB)
.
BaudRate
The baud rate at which the communications device operates. This member can be an actual baud rate value, orone of the following indexes.
Value | Meaning |
---|---|
| 110 bps |
| 300 bps |
| 600 bps |
| 1200 bps |
| 2400 bps |
| 4800 bps |
| 9600 bps |
| 14400 bps |
| 19200 bps |
| 38400 bps |
| 57600 bps |
| 115200 bps |
| 128000 bps |
| 256000 bps |
fBinary
If this member is TRUE, binary mode is enabled. Windows does not supportnonbinary mode transfers, so this member must be TRUE.
fParity
If this member is TRUE, parity checking is performed and errors arereported.
fOutxCtsFlow
If this member is TRUE, the CTS (clear-to-send) signal is monitored for outputflow control. If this member is TRUE and CTS is turned off, output is suspended untilCTS is sent again.
fOutxDsrFlow
If this member is TRUE, the DSR (data-set-ready) signal is monitored for outputflow control. If this member is TRUE and DSR is turned off, output is suspended untilDSR is sent again.
fDtrControl
The DTR (data-terminal-ready) flow control. This member can be one of the following values.
Value | Meaning |
---|---|
| Disables the DTR line when the device is opened and leaves it disabled. |
| Enables the DTR line when the device is opened and leaves it on. |
| Enables DTR handshaking. If handshaking is enabled, it is an error for the application to adjust the line by using the EscapeCommFunction function. |
fDsrSensitivity
If this member is TRUE, the communications driver is sensitive to the state ofthe DSR signal. The driver ignores any bytes received, unless the DSR modem input line is high.
Cts Port Devices Drivers
fTXContinueOnXoff
If this member is TRUE, transmission continues after the input buffer has comewithin XoffLim bytes of being full and the driver has transmitted theXoffChar character to stop receiving bytes. If this member isFALSE, transmission does not continue until the input buffer is withinXonLim bytes of being empty and the driver has transmittedthe XonChar character to resume reception.
fOutX
Indicates whether XON/XOFF flow control is used during transmission. If this member isTRUE, transmission stops when the XoffChar character isreceived and starts again when the XonChar character is received.
fInX
Indicates whether XON/XOFF flow control is used during reception. If this member isTRUE, the XoffChar character is sent when the input buffercomes within XoffLim bytes of being full, and the XonCharcharacter is sent when the input buffer comes within XonLim bytes of beingempty.
fErrorChar
Indicates whether bytes received with parity errors are replaced with the character specified by theErrorChar member. If this member is TRUE and thefParity member is TRUE, replacement occurs.
fNull
If this member is TRUE, null bytes are discarded when received.
fRtsControl
The RTS (request-to-send) flow control. This member can be one of the following values.
Value | Meaning |
---|---|
| Disables the RTS line when the device is opened and leaves it disabled. |
| Enables the RTS line when the device is opened and leaves it on. |
| Enables RTS handshaking. The driver raises the RTS line when the 'type-ahead' (input) buffer is less than one-half full and lowers the RTS line when the buffer is more than three-quarters full. If handshaking is enabled, it is an error for the application to adjust the line by using the EscapeCommFunction function. |
| Specifies that the RTS line will be high if bytes are available for transmission. After all buffered bytes have been sent, the RTS line will be low. |
fAbortOnError
If this member is TRUE, the driver terminates all read and write operations withan error status if an error occurs. The driver will not accept any further communications operations until theapplication has acknowledged the error by calling theClearCommError function.
fDummy2
Reserved; do not use.
wReserved
Reserved; must be zero.
XonLim
The minimum number of bytes in use allowed in the input buffer before flow control is activated to allowtransmission by the sender. This assumes that either XON/XOFF, RTS, or DTR input flow control is specified inthe fInX, fRtsControl, orfDtrControl members.
XoffLim
The minimum number of free bytes allowed in the input buffer before flow control is activated to inhibitthe sender. Note that the sender may transmit characters after the flow control signal has been activated, sothis value should never be zero. This assumes that either XON/XOFF, RTS, or DTR input flow control is specifiedin the fInX, fRtsControl, orfDtrControl members. The maximum number of bytes in use allowed is calculated bysubtracting this value from the size, in bytes, of the input buffer.
ByteSize
The number of bits in the bytes transmitted and received.
Parity
The parity scheme to be used. This member can be one of the following values.
Value | Meaning |
---|---|
| Even parity. |
| Mark parity. |
| No parity. |
| Odd parity. |
| Space parity. |
StopBits
The number of stop bits to be used. This member can be one of the following values.
Value | Meaning |
---|---|
| 1 stop bit. |
| 1.5 stop bits. |
| 2 stop bits. |
XonChar
The value of the XON character for both transmission and reception.
XoffChar
The value of the XOFF character for both transmission and reception.
ErrorChar
The value of the character used to replace bytes received with a parity error.
EofChar
The value of the character used to signal the end of data.
EvtChar
The value of the character used to signal an event.
wReserved1
Reserved; do not use.
Remarks
When a DCB structure is used to configure the 8250, thefollowing restrictions apply to the values specified for the ByteSize andStopBits members:
- The number of data bits must be 5 to 8 bits.
- The use of 5 data bits with 2 stop bits is an invalid combination, as is 6, 7, or 8 data bits with 1.5 stop bits.
Requirements
Minimum supported client | Windows XP |
Minimum supported server | Windows Server 2003 |
Header | winbase.h (include Windows.h) |
See also
- SYNOPSIS
- DESCRIPTION
- Win32::SerialPort & Win32API::CommPort
Device::SerialPort - Linux/POSIX emulation of Win32::SerialPort functions.
Constructors
Configuration Utility Methods
Configuration Parameter Methods
Operating Methods
Methods used with Tied FileHandles
Destructors
Methods for I/O Processing
This module provides an object-based user interface essentially identical to the one provided by the Win32::SerialPort module.
Initialization
The primary constructor is new with either a PortName, or a Configuretion File specified. With a PortName, this will open the port and create the object. The port is not yet ready for read/write access. First, the desired parameter settings must be established. Since these are tuning constants for an underlying hardware driver in the Operating System, they are all checked for validity by the methods that set them. The write_settings method updates the port (and will return True under POSIX). Ports are opened for binary transfers. A separate binmode
is not needed.
The $quiet
parameter is ignored and is only there for compatibility with Win32::SerialPort. The $lockfile
parameter is optional. It will attempt to create a file (containing just the current process id) at the location specified. This file will be automatically deleted when the $PortObj
is no longer used (by DESTROY). You would usually request $lockfile
with $quiet
true to disable messages while attempting to obtain exclusive ownership of the port via the lock. Lockfiles are experimental in Version 0.07. They are intended for use with other applications. No attempt is made to resolve port aliases (/dev/modem /dev/ttySx) or to deal with login processes such as getty and uugetty.
Using a Configuration File with new or by using second constructor, start, scripts can be simplified if they need a constant setup. It executes all the steps from new to write_settings based on a previously saved configuration. This constructor will return undef
on a bad configuration file or failure of a validity check. The returned object is ready for access. This is new and experimental for Version 0.055.
The third constructor, tie, will combine the start with Perl's support for tied FileHandles (see perltie). Device::SerialPort will implement the complete set of methods: TIEHANDLE, PRINT, PRINTF, WRITE, READ, GETC, READLINE, CLOSE, and DESTROY. Tied FileHandle support is new with Version 0.04 and the READ and READLINE methods were added in Version 0.06. In 'scalar context', READLINE sets stty_icanon to do character processing and calls lookfor. It restores stty_icanon after the read. In 'list context', READLINE does Canonical (line) reads if stty_icanon is set or calls streamline if it is not. (stty_icanon is not altered). The streamline choice allows duplicating the operation of Win32::SerialPort for cross-platform scripts.
The implementation attempts to mimic STDIN/STDOUT behaviour as closely as possible: calls block until done and data strings that exceed internal buffers are divided transparently into multiple calls. In Version 0.06, the output separators $,
and $
are also applied to PRINT if set. The output_record_separator and output_field_separator methods can set Port-FileHandle-Specific versions of $,
and $
if desired. Since PRINTF is treated internally as a single record PRINT, $
will be applied. Output separators are not applied to WRITE (called as syswrite FH, $scalar, $length, [$offset]
). The input_record_separator $/
is not explicitly supported - but an identical function can be obtained with a suitable are_match setting.
The tied FileHandle methods may be combined with the Device::SerialPort methods for read, input, and write as well as other methods. The typical restrictions against mixing print with syswrite do not apply. Since both (tied) read and sysread call the same $ob->READ
method, and since a separate $ob->read
method has existed for some time in Device::SerialPort, you should always use sysread with the tied interface (when it is implemented).
Certain parameters SHOULD be set before executing write_settings. Others will attempt to deduce defaults from the hardware or from other parameters. The Required parameters are:
baudrate
Any legal value.
parity
One of the following: 'none', 'odd', 'even'.
By default, incoming parity is not checked. This mimics the behavior of most terminal programs (like 'minicom'). If you need parity checking enabled, please use the 'stty_inpck' and 'stty_istrip' functions.
databits
An integer from 5 to 8.
stopbits
Legal values are 1 and 2.
handshake
One of the following: 'none', 'rts', 'xoff'.
Some individual parameters (eg. baudrate) can be changed after the initialization is completed. These will be validated and will update the serial driver as required. The save method will write the current parameters to a file that start, tie, and restart can use to reestablish a functional setup.
Configuration Utility Methods
Use alias to convert the name used by 'built-in' messages.
Starting in Version 0.07, a number of Application Variables are saved in $Configuration_File. These parameters are not used internally. But methods allow setting and reading them. The intent is to facilitate the use of separate configuration scripts to create the files. Then an application can use start as the Constructor and not bother with command line processing or managing its own small configuration file. The default values and number of parameters is subject to change.
Configuration and Capability Methods
The Win32 Serial Comm API provides extensive information concerning the capabilities and options available for a specific port (and instance). This module will return suitable responses to facilitate porting code from that environment.
The get_tick_count method is a clone of the Win32::GetTickCount() function. It matches a corresponding method in Win32::CommPort. It returns time in milliseconds - but can be used in cross-platform scripts.
Binary selections will accept as true any of the following: ('YES', 'Y', 'ON', 'TRUE', 'T', '1', 1)
(upper/lower/mixed case) Anything else is false.
There are a large number of possible configuration and option parameters. To facilitate checking option validity in scripts, most configuration methods can be used in two different ways:
method called with an argument
The parameter is set to the argument, if valid. An invalid argument returns false (undef) and the parameter is unchanged. The function will also carp if $user_msg is true. The port will be updated immediately if allowed (an automatic write_settings is called).
method called with no argument in scalar context
The current value is returned. If the value is not initialized either directly or by default, return 'undef' which will parse to false. For binary selections (true/false), return the current value. All current values from 'multivalue' selections will parse to true.
method called with no argument in list context
Methods which only accept a limited number of specific input values return a list consisting of all acceptable choices. The null list (undef)
will be returned for failed calls in list context (e.g. for an invalid or unexpected argument). Only the baudrate, parity, databits, stopbits, and handshake methods currently support this feature.
Operating Methods
Version 0.04 adds pulse methods for the RTS, BREAK, and DTR bits. The pulse methods assume the bit is in the opposite state when the method is called. They set the requested state, delay the specified number of milliseconds, set the opposite state, and again delay the specified time. These methods are designed to support devices, such as the X10 'FireCracker' control and some modems, which require pulses on these lines to signal specific events or data. Timing for the active part of pulse_break_on is handled by POSIX::tcsendbreak(0), which sends a 250-500 millisecond BREAK pulse. It is NOT guaranteed to block until done.
In Version 0.05, these calls and the rts_active and dtr_active calls verify the parameters and any required ioctl constants, and return undef
unless the call succeeds. You can use the can_ioctl method to see if the required constants are available. On Version 0.04, the module would not load unless asm/termios.ph was found at startup.
Stty Shortcuts
Version 0.06 adds primitive methods to modify port parameters that would otherwise require a system('stty..');
command. These act much like the identically-named methods in Win32::SerialPort. However, they are initialized from 'current stty settings' when the port is opened rather than from defaults. And like stty settings, they are passed to the serial driver and apply to all operations rather than only to I/O processed via the lookfor method or the tied FileHandle methods. Each returns the current setting for the parameter. There are no 'global' or 'combination' parameters - you still need system('stty..')
for that.
The methods which handle CHAR parameters set and return values as ord(CHAR)
. This corresponds to the settings in the POSIX termios cc_field array. You are unlikely to actually want to modify most of these. They reflect the special characters which can be set by stty.
Binary settings supported by POSIX will return 0 or 1. Several parameters settable by stty do not yet have shortcut methods. Contact me if you need one that is not supported. These are the common choices. Try man stty
if you are not sure what they do.
The following methods require successfully loading ioctl constants. They will return undef
if the needed constants are not found. But the method calls may still be used without syntax errors or warnings even in that case.
Lookfor and I/O Processing
Some communications programs have a different need - to collect (or discard) input until a specific pattern is detected. For lines, the pattern is a line-termination. But there are also requirements to search for other strings in the input such as 'username:' and 'password:'. The lookfor method provides a consistant mechanism for solving this problem. It searches input character-by-character looking for a match to any of the elements of an array set using the are_match method. It returns the entire input up to the match pattern if a match is found. If no match is found, it returns ' unless an input error or abort is detected (which returns undef).
Unlike Win32::SerialPort, lookfor does not handle backspace, echo, and other character processing. It expects the serial driver to handle those and to be controlled via stty. For interacting with humans, you will probably want stty_icanon(1)
during lookfor to obtain familiar command-line response. The actual match and the characters after it (if any) may also be viewed using the lastlook method. It also adopts the convention from Expect.pm that match strings are literal text (tested using index) unless preceeded in the are_match list by a '-re', entry. The default are_match list is ('n')
, which matches complete lines.
Everything in lookfor is still experimental. Please let me know if you use it (or can't use it), so I can confirm bug fixes don't break your code. For literal strings, $match
and $pattern
should be identical. The $instead
value returns the internal buffer tested by the match logic. A successful match or a lookclear resets it to ' - so it is only useful for error handling such as timeout processing or reporting unexpected responses.
The lookfor method is designed to be sampled periodically (polled). Any characters after the match pattern are saved for a subsequent lookfor. Internally, lookfor is implemented using the nonblocking input method when called with no parameter. If called with a count, lookfor calls $PortObj->read(count)
which blocks until the read is Complete or a Timeout occurs. The blocking alternative should not be used unless a fault time has been defined using read_interval, read_const_time, and read_char_time. It exists mostly to support the tied FileHandle functions sysread, getc, and <FH>. When stty_icanon is active, even the non-blocking calls will not return data until the line is complete.
The internal buffers used by lookfor may be purged by the lookclear method (which also clears the last match). For testing, lookclear can accept a string which is 'looped back' to the next input. This feature is enabled only when set_test_mode_active(1)
. Normally, lookclear will return undef
if given parameters. It still purges the buffers and last_match in that case (but nothing is 'looped back'). You will want stty_echo(0) when exercising loopback.
The matchclear method is designed to handle the 'special case' where the match string is the first character(s) received by lookfor. In this case, $lookfor_return '
, lookfor does not provide a clear indication that a match was found. The matchclear returns the same $match
that would be returned by lastlook and resets it to ' without resetting any of the other buffers. Since the lookfor already searched through the match, matchclear is used to both detect and step-over 'blank' lines.
The character-by-character processing used by lookfor is fine for interactive activities and tasks which expect short responses. But it has too much 'overhead' to handle fast data streams.There is also a streamline method which is a fast, line-oriented alternative with just pattern searching. Since streamline uses the same internal buffers, the lookclear, lastlook, are_match, and matchclear methods act the same in both cases. In fact, calls to streamline and lookfor can be interleaved if desired (e.g. an interactive task that starts an upload and returns to interactive activity when it is complete).
There are two additional methods for supporting 'list context' input: lastline sets an 'end_of_file' Regular Expression, and linesize permits changing the 'packet size' in the blocking read operation to allow tuning performance to data characteristics. These two only apply during READLINE. The default for linesize is 1. There is no default for the lastline method.
The Regular Expressions set by are_match and lastline will be pre-compiled using the qr// construct on Perl 5.005 and higher. This doubled lookfor and streamline speed in my tests with Regular Expressions - but actual improvements depend on both patterns and input data.
The functionality of lookfor includes a limited subset of the capabilities found in Austin Schutz's Expect.pm for Unix (and Tcl's expect which it resembles). The $before, $match, $pattern, and $after
return values are available if someone needs to create an 'expect' subroutine for porting a script. When using multiple patterns, there is one important functional difference: Expect.pm looks at each pattern in turn and returns the first match found; lookfor and streamline test all patterns and return the one found earliest in the input if more than one matches.
Exports
Nothing is exported by default. The following tags can be used to have large sets of symbols exported:
Utility subroutines and constants for parameter setting and test:
The Constants named BM_* and CE_* are omitted. But the modem status (MS_*) Constants are defined for possible use with modemlines and wait_modemlines. They are assigned to corresponding functions, but the bit position will be different from that on Win32.
Which incoming bits are active:
If you want to write more POSIX-looking code, you can use the constants seen there, instead of the Win32 versions:
Offsets into the array returned by status:
All of the above. Except for the test suite, there is not really a good reason to do this.
Here is a handy pinout map, showing each line and signal on a standard DB9 connector:
Data Carrier Detect
Receive Data
Transmit Data
Data Terminal Ready
Signal Ground
Data Set Ready
Request to Send
Clear to Send
The HSM USB Serial Driver version 3.4.9 can be downloaded from under Software Barcode Scanners Software Drivers Honeywell Scanning (HSM) USB Serial Driver. File 1 HSM USB Serial Driver version 3.4.9.zip File 2. From Windows 10 and onwards, Microsoft includes a standard USB serial / COM Port driver with their OS distributions, which will enumerate a COM port when a Honeywell scanner, configured for USB Serial (TRMUSB130) is connected. This driver has limited support, but will transmit barcode data via an emulated generic COM port. Honeywell usb devices driver downloads. HSM USB Serial Driver 3.5.9 can be found on the Software download Site. See this article: How to access the new software download server? This is a completely silent install. There aren't any 'Trust Honeywell' nags that must be addressed like in the previous versions of drivers that supported silent install. (3.5.5 and 3.5.7).
Ring Indicator
Microsoft cd-rom driver download for windows 10. The object returned by new is NOT a Filehandle. You will be disappointed if you try to use it as one.
e.g. the following is WRONG!!
This module uses POSIX termios extensively. Raw API calls are very unforgiving. You will certainly want to start perl with the -w switch. If you can, use strict as well. Try to ferret out all the syntax and usage problems BEFORE issuing the API calls (many of which modify tuning constants in hardware device drivers..not where you want to look for bugs).
With all the options, this module needs a good tutorial. It doesn't have one yet.
It is recommended to always use 'read(255)' due to some unexpected behavior with the termios under some operating systems (Linux and Solaris at least). To deal with this, a routine is usually needed to read from the serial port until you have what you want. This is a quick example of how to do that:
For a serial port to work under Unix, you need the ability to do several types of operations. With POSIX, these operations are implemented with a set of 'tc*' functions. However, not all Unix systems follow this correctly. In those cases, the functions change, but the variables used as parameters generally turn out to be the same.
This is only available through the bit-set(TIOCMBIS)/bit-clear(TIOCMBIC) ioctl function using the RTS value(TIOCM_RTS).
This is available through the bit-set(TIOCMBIS)/bit-clear(TIOCMBIC) ioctl function using the DTR value(TIOCM_DTR)
or available through the DTRSET/DTRCLEAR ioctl functions, if they exist.
To read Clear To Send (CTS), Data Set Ready (DSR), Ring Indicator (RING), and Carrier Detect (CD/RLSD), the TIOCMGET ioctl function must be used.
To decode the individual modem lines, some bits have multiple possible constants:
TIOCM_CTS
TIOCM_DSR
TIOCM_RNG TIOCM_RI
TIOCM_CAR TIOCM_CD
To get information about the state of the serial port input and output buffers, the TIOCINQ and TIOCOUTQ ioctl functions must be used. I'm not totally sure what is returned by these functions across all Unix systems. Under Linux, it is the integer number of characters in the buffer.
Cts Port Devices Driver Vga
To get information about the state of the serial transmission line (to see if a write has made its way totally out of the serial port buffer), the TIOCSERGETLSR ioctl function must be used. Additionally, the 'Get Buffer Status' methods must be functioning, as well as having the first bit of the result set (Linux is TIOCSER_TEMT, others unknown, but we've been using TIOCM_LE even though that should be returned from the TIOCMGET ioctl).
Some Unix systems require special TCGETX/TCSETX ioctls functions and the CTSXON/RTSXOFF constants to turn on and off CTS/RTS 'hard' flow control instead of just using the normal POSIX tcsetattr calls.
The current version of the module has been tested with Perl 5.003 and above. It was initially ported from Win32 and was designed to be used without requiring a compiler or using XS. Since everything is (sometimes convoluted but still pure) Perl, you can fix flaws and change limits if required. But please file a bug report if you do.
The read method, and tied methods which call it, currently can use a fixed timeout which approximates behavior of the Win32::SerialPortread_const_time and read_char_time methods. It is used internally by select. If the timeout is set to zero, the read call will return immediately. A read larger than 255 bytes will be split internally into 255-byte POSIX calls due to limitations of select and VMIN. The timeout is reset for each 255-byte segment. Hence, for large reads, use a read_const_time suitable for a 255-byte read. All of this is expeimental in Version 0.055.
The timing model defines the total time allowed to complete the operation. A fixed overhead time is added to the product of bytes and per_byte_time.
Read_Total = read_const_time + (read_char_time * bytes_to_read)
Write timeouts and read_interval timeouts are not currently supported.
On some machines, reads larger than 4,096 bytes may be truncated at 4,096, regardless of the read size or read timing settings used. In this case, try turning on or increasing the inter-character delay on your serial device. Also try setting the read size to
and performing multiple reads until the transfer is completed.
See the limitations about lockfiles. Experiment if you like.
With all the currently unimplemented features, we don't need any more. But there probably are some.
Please send comments and bug reports to kees@outflux.net.
Win32::SerialPort Functions Not Currently Supported
Functions Handled in a POSIX system by 'stty'
Win32::SerialPort Functions Not Ported to POSIX
Win32API::CommPort Functions Not Ported to POSIX
'raw' Win32 API Calls and Constants
A large number of Win32-specific elements have been omitted. Most of these are only available in Win32::SerialPort and Win32API::CommPort as optional Exports. The list includes the following:
The API Wrapper Methods and Constants used only to support them including PURGE_*, SET*, CLR*, EV_*, and ERROR_IO*
The Constants used for Feature and Properties Detection including BAUD_*, PST_*, PCF_*, SP_*, DATABITS_*, STOPBITS_*, PARITY_*, and COMMPROP_INITIALIZED
The constants for the Win32 Device Control Block including CBR_*, DTR_*, RTS_*, *PARITY, *STOPBIT*, and FM_*
Compatibility
This code implements the functions required to support the MisterHouse Home Automation software by Bruce Winter. It does not attempt to support functions from Win32::SerialPort such as stty_emulation that already have POSIX implementations or to replicate Win32 idosyncracies. However, the supported functions are intended to clone the equivalent functions in Win32::SerialPort and Win32API::CommPort. Any discrepancies or omissions should be considered bugs and reported to the maintainer.
Win32API::CommPort
Win32::SerialPort
perltoot - Tom Christiansen's Object-Oriented Tutorial
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
2 POD Errors
The following errors were encountered while parsing the POD:
You can't have =items (as at line 2653) unless the first thing after the =over is an =item
You can't have =items (as at line 2747) unless the first thing after the =over is an =item
To install Device::SerialPort, copy and paste the appropriate command in to your terminal.
For more information on module installation, please visit the detailed CPAN module installation guide.