IO OCX Interface
Home Page
Communications
Open(PortName, Setup)
Close()
WriteString(Data)
ReadString(Length)
WriteByte(Data)
ReadByte()
SetTimeOut(Time)
SetHandshaking(HSMethod)
WriteData(Data, Length)
ReadData(Length)
BytesRead()
ListPorts(Index, Type)
NumberRetries(Retries)
DataBuffer
Mode
StatusEventInterval
PortName
NumBytesRead
NumBytesWritten
GetPortHandle()
SetBufferSize(InSize, OutSize)
Status
ParallelStatus
SerialStatus
CharsInQue
CharsOutQue
Communications Events
IOStatusEvent(StatusType, IOStatus)
IOCompleteEvent(JobType, JobId, JobResult)
Parallel Specific
ParallelAddressOverride
Serial Specific (Advanced)
SerialCTSFlow(Value)
SerialDSRFlow(Value)
SerialDTRControl(long Value)
SerialDSRSensitivity(Value)
SerialTxContinueOnXoff(Value)
SerialOutX(Value)
SerialInX(Value)
SerialErrorReplacment(Value)
SerialNullStripping(Value)
SerialRTSControl(Value)
SerialXonLimit(Value)
SerialXoffLimit(Value)
SerialXonCharacter(Value)
SerialXoffCharacter(Value)
SerialErrorCharacter(Value)
SerialEndCharacter(Value)
Open(PortName, Setup)
Parameters
PortName is the name of the port to be opened.
Setup is a string that will set the mode of operation for a serial port. Not used with parallel ports.
Remarks
Opens a port for doing input and output.
Returns
1 if successful and 0 if the function fails.
Example
Result = IO1.Open("LPT1:", "") 'Open a parallel Port.
Result = IO1.Open("COM2:", "baud=9600 parity=N data=8 stop=1") 'Open a serial Port.
Close()
Parameters
None.
Remarks
Closes an open port.
Returns
1 if successful and 0 if the function fails.
Example
Result = IO1.Close()
WriteString(Data)
Parameters
Data The string to be written
Remarks
Writes a string to the previously opened port. For binary data use the WriteData function.
Returns
1 if successful and a 0 if the function fails.
Example
Result = IO1.WriteString("Hello World" + Chr(13) + Chr(10)) 'Sends "Hello World" to a printer or other device.
ReadString(Length)
Parameters
Length The number of characters to read from the port.
Remarks
Reads characters from an opened port and returns them as a string. For binary data use the function ReadData. When reading data from a parallel port, this function uses the RS1284 protocol for reading data from the parallel port.
Example
String = IO1.ReadString(30) 'Reads data from a port. Typically a request for data precedes this command.
WriteByte(Data)
Parameters
Data The byte/character to be written
Remarks
Writes a byte/character to the previously opened port.
Returns
1 if successful and a 0 if the function fails.
Example
Result = IO1.WriteByte(Chr(10)) 'Sends Line feed to a printer or other device.
ReadByte()
Parameters
None.
Remarks
Reads a byte/character from an opened port. When reading data from a parallel port, this function uses the RS1284 protocol for reading data from the parallel port.
Returns
The byte/character.
Example
Result = IO1.ReadByte() 'Reads 1 data byte from a port. Typically a request for data precedes this command.
SetTimeOut(Time)
Parameters
Time The base time in milliseconds. For Reading a port the timeout will be: Time + (number of characters to read) x Time .For writing to a port the time out will be: Time + (number of characters to write) x Time. A value of zero indicates that timeout are not used. Default timeout factor is 20.
Remarks
Sets the time out factor for a port. The write/read operation will be tried utill the time is expired. If the timeout expires, the function will return an error (0) result.
Returns
1 if successful and a 0 if the function fails.
Example
Result = IO1.SetTimeOut(20) 'Sets timeout factor, how long a request is tried before an error is returned.
SetHandshaking(HSMethod)
Parameters
HSMethod The type of handshaking protocol to be used with a serial port. 'Serial ports Only. 0 = None, 1 = Xon/Xoff, 2 = Hardware
Remarks
Sets the type of handshaking to be used with this port, the device must be configured to use the same type of handshaking protocol.
Returns
1 if successful and a 0 if the function fails.
Example
Result = IO1.SetHandshaking(2) 'Serial ports Only. 0 = None, 1 = Xon/Xoff, 2 = Hardware
WriteData(Data, Length)
Parameters
Data The binary data to be written, can include embedded nulls.
Length The length of data to be written.
Remarks
Writes data to the previously opened port.
Returns
The length of data written if successful and a 0 if the function fails.
Example
Result = IO1.WriteData("String1" + Chr(00) + "String2" + Chr(00) + "String3" + Chr(00) + Chr(00)) 'Sends 3 null terminated strings to the port, with the total data being double null terminated.
ReadData(Length)
Parameters
Length The number of bytes to read from the port.
Remarks
Reads bytes from an opened port and returns them in a string. The data can have null bytes. Even thought this function will return a string with embedded nulls other functions that operate on strings may not be null friendly. When reading data from a parallel port, this function uses the RS1284 protocol for reading data from the parallel port.
Returns
Binary data in a string.
Example
String = IO1.ReadData(30) 'Reads data from a port. Typically a request for data precedes this command.
BytesRead()
Parameters
None.
Remarks
Return the number of bytes previously read from the port. This value corresponds to the last read function done on this port. For use with the ReadData() function.
Returns
The number of bytes previously read function called.
Example
String = IO1.ReadData(30) 'Reads data from a port.
NumBytes = IO1.BytesRead() 'returns number of bytes read.
ListPorts(Index, Type)
Parameters
Index The nth item in the list to retrieve.
Type The type of port to be retrieve.
Remarks
Type is 1 for COM ports, 2 for LPT ports and, 4 for all ports. Note you can OR these values together to get a combination.
Returns
Returns the ports availble on the machine for the given index.
Example
For i = 0 To 10
Label2.Caption = Label2.Caption + IO1.ListPorts(i, 1) + " "
Next i
NumberRetries(Retries)
Parameters
Retries The number of times an I/O operation will be tried before a failure is returned.
Remarks
Default is 1 retry.
Returns
Returns 1.
Example
Result = IO1.NumberRetries(1)
DataBuffer (Property) R
Remarks
This buffer reflects the last read data. It is typically used during a IOCompleteEvent when a background read is completed.
Mode (Property) R/W
Remarks
Set this to 0 (MODE_NORMAL) for normal operation, or to 2 (MODE_ASYNC) for background I/O operations. In the background (or asynchronous) mode of operation, the IO control will perform read and write operations on a background process. Write operations will return a "Job ID" number. When then operation is complete, an IOComplete event will be fired signaling the completion of the operation and the result of the operation. This background operation will allow slow I/O operations to be done and not tie up the main application.
StatusEventInterval (Property) R/W
Remarks
Set this to control how often changes in port status is monitored. This affects how often IOStatusEvents are fired and how responsive status events are to changes in port status. If this is set to 0, status events are not fired and the thread monitoring status for status events is terminated until this property is set to non-zero.
PortName (Property) R
Remarks
PortName reflects the name of the open port. This is provided for the convience of the application, the application upon detecting an error condition can use PortName to display a message to the application user to take corrective action.
NumBytesRead (Property) R
Remarks
This reflects the number of byte/characters read during the last read operation.
NumBytesWritten (Property) R
Remarks
This reflects the number of byte/characters write during the last read operation.
GetPortHandle()
Parameters
None .
Remarks
This function returns the handle of the currently opened file. This function is provided to allow calls to the Windows API directly.
Returns
The handle of the currently opened file.
Example
Result = IO1.GetPortHandle()
SetBufferSize(InSize, OutSize)
Parameters
InSize. Specifies the size of the input buffer.
OutSize. Specifies the size of the output buffer.
Remarks
This function sets the size of the input and output buffer associated with the opened port. Caution should be taken when using this function, some hardware running Windows 95 can function incorrectly when overriding the default buffer size with a serial port.
Returns
0 if the function fails.
Example
Result = IO1.SetbufferSize(InSize, OutSize)
Status
ParallelStatus (Property) R
Remarks
This reflects the current status of the parallel/printer port as follows:
PARALLEL_PAPER_EMPTY
PARALLEL_OFF_LINE
PARALLEL_POWER_OFF
PARALLEL_NOT_CONNECTED
PARALLEL_BUSY
PARALLEL_SELECTED |
0x4
0x8
0x10
0x20
0x40
0x80 |
SerialStatus (Property) R
Remarks
This reflects the current status of the serial port as follows:
SERIAL_RXOVER
SERIAL_OVERRUN
SERIAL_RXPARITY
SERIAL_FRAME
SERIAL_BREAK
SERIAL_TXFULL
SERIAL_TXEMPTY
SERIAL_RXEMPTY
SERIAL_CTS_TXHOLD
SERIAL_DSR_TXHOLD
SERIAL_RLSD_TXHOLD
SERIAL_XOFF_TXHOLD
SERIAL_CTS_ON
SERIAL_DSR_ON
SERIAL_RING_ON
SERIAL_RLSD_ON |
0x0001
0x0002
0x0004
0x0008
0x0010
0x0100
0x0020
0x0040
0x0200
0x0400
0x0800
0x1000
0x010000
0x020000
0x040000
0x080000 |
An input buffer overflow has occurred. There is either no room in the input buffer, or a character was received after the end-of-file (EOF) character.
A character-buffer overrun has occurred. The next character is lost.
The hardware detected a parity error.
The hardware detected a framing error.
The hardware detected a break condition.
The application tried to transmit a character, but the output buffer was full.
The transmit buffer is empty.
The receive buffer is empty.
Transmission is waiting for the CTS (clear-to-send) signal to be sent.
Transmission is waiting for the DSR (data-set-ready) signal to be sent.
Transmission is waiting for the RLSD (receive-line-signal-detect) signal to be sent.
Transmission is waiting because the XOFF character was received.
The CTS (clear-to-send) signal is on.
The DSR (data-set-ready) signal is on.
The ring indicator signal is on.
The RLSD (receive-line-signal-detect) signal is on. |
CharsInQue (Property) R
Remarks
This reflects the number of byte/characters in the input buffer (waiting to be read).
CharsOutQue (Property) R
Remarks
This reflects the number of byte/characters in the output buffer (pending write to the port).
Events
IOStatusEvent(StatusType, IOStatus)
Parameters
StatusType. Specifies the type of status being reported.
STATUS_TYPE_PARALLEL 1
STATUS_TYPE_SERIAL 2
IOStatus. Specifies the status pertaining to the open port. See the definition of SerialStatus and ParallelStatus for the value of this parameter.
Remarks
This event is fired when ever a status change is detected on the port. How often status is checked and events are generated is set by StatusEventInterval.
IOCompleteEvent(JobType, JobId, JobResult)
Parameters
JobType. Specifies the type of Job being reported as finished.
BKJOB_WRITE 3
BKJOB_READ 4
JobId. Specifies the Id of the job submitted for background processing.
JobResult. Specifies the result of the job submitted for background processing.
Remarks
This event is fired when ever a background job is finished.
Parallel Specific
ParallelAddressOverride (Property) R
Remarks
This is used to override the address of the parallel port on Windows 95 where the parallel port is at a non-standard address.
Advanced Serial Communications functions
These functions are not typically needed to successfully do serial communication, but are provided to allow advanced control of the serial port. These functions should be called after the SetHandshaking() function is called, as SetHandshaking() will cancel these settings.
SerialCTSFlow(Value)
Parameters
Value 1 or 0. Undetermined results if set to other than 1 or 0.
Remarks
Specifies whether the CTS (clear-to-send) signal is monitored for output flow control. If it is 1 and CTS is low, output is suspended until CTS is high again. The CTS signal is under control of the device (usually a modem/printer), the host simply monitors the status of this signal, the host does not change it. This function should be called before the port is opened.
Returns
1 if successful or 0 if failed.
Example
Result = IO1.SerialCTSFlow(1)
...
Result = IO1.Open("COM2:", "baud=9600 parity=N data=8 stop=1") 'Open a serial Port.
SerialDSRFlow(Value)
Parameters
Value 1 or 0. Undetermined results if set to other than 1 or 0.
Remarks
Specifies whether the DSR (data-set-ready) signal is monitored for output flow control. If this member is 1 and DSR is low, output is suspended until DSR is high again. This signal is under the control of the attached device; the host(PC) only monitors this signal. This function should be called before the port is opened.
Returns
1 if successful or 0 if failed.
Example
Result = IO1.SerialDSRFlow(1)
...
Result = IO1.Open("COM2:", "baud=9600 parity=N data=8 stop=1") 'Open a serial Port.
SerialDTRControl(long Value)
Parameters
Value 0,1,2,5,6. Controls state of DTR line. Undetermined results if set to other than specified
Remarks
If 0 then the DTR line is lowered when the device is opened.
If 1 then the DTR line is raised when the device is opened.
If set to 2 enables DTR flow-control handshaking.
After the port is opened:
If called with a value of 5 sets DTR high. Only allowed if SerialDTRControl was set to 1 0r 0 before the port was opened.
If called with a value of 6 sets DTR low. Only allowed if SerialDTRControl was set to 1 0r 0 before the port was opened.
Returns
1 if successful or 0 if failed.
Example
Result = IO1.SerialDTRControl(0)
...
Result = IO1.Open("COM2:", "baud=9600 parity=N data=8 stop=1") 'Open a serial Port.
...
Result = IO1.SerialDTRControl(5)
SerialDSRSensitivity(Value)
Parameters
Value 1 or 0. Controls DSR Sensitivity. Undetermined results if set to other than 1 or 0.
Remarks
Specifies whether the communications driver is sensitive to the state of the DSR signal. If this is set to a 1, the driver ignores any bytes received, unless the DSR modem input line is high.
Returns
1 if successful or 0 if failed.
Example
Result = IO1.SerialDSRSensitivity(1)
...
Result = IO1.Open("COM2:", "baud=9600 parity=N data=8 stop=1") 'Open a serial Port.
SerialTxContinueOnXoff(Value)
Parameters
Value 1 or 0. Controls Xon/Xoff behavior. Undetermined results if set to other than 1 or 0.
Remarks
Specifies whether transmission stops when the input buffer is full and the driver has transmitted the XOFF character. If this is set to a 1, transmission continues after the XOFF character has been sent. If this is set to a 0, transmission does not continue until the input buffer is within SerialXonLim bytes of being empty and the driver has transmitted the XON character.
Returns
1 if successful or 0 if failed.
Example
Result = IO1.SerialTxContinueOnXoff(1)
...
Result = IO1.Open("COM2:", "baud=9600 parity=N data=8 stop=1") 'Open a serial Port.
SerialOutX(Value)
Parameters
Value 1 or 0. Controls Xon/Xoff behavior. Undetermined results if set to other than 1 or 0
Remarks
Specifies whether XON/XOFF flow control is used during transmission. If this member is a 1, transmission stops when the XOFF character is received and starts again when the XON character is received.
Returns
1 if successful or 0 if failed.
Example
Result = IO1.SerialOutX(1)
...
Result = IO1.Open("COM2:", "baud=9600 parity=N data=8 stop=1") 'Open a serial Port.
SerialInX(Value)
Parameters
Value 1 or 0. Controls Xon/Xoff behavior. Undetermined results if set to other than 1 or 0.
Remarks
Specifies whether XON/XOFF flow control is used during reception. If this is set to a 1, the XOFF character is sent when the input buffer comes within a preset limit of bytes of being full (see SerialXonLimit and SerialXoffLimit), and the XON character is sent when the input buffer comes within a preset limit of bytes of being empty.
Returns
1 if successful or 0 if failed.
Example
Result = IO1.SerialInX(1)
...
Result = IO1.Open("COM2:", "baud=9600 parity=N data=8 stop=1") 'Open a serial Port.
SerialErrorReplacment(Value)
Parameters
Value 1 or 0. Undetermined results if set to other than 1 or 0.
Remarks
Specifies whether bytes received with parity errors are replaced with the character specified by the SerialErrorCharacter member function. If this is set to a 1 and the Parity is set to a 1, replacement occurs.
Returns
1 if successful or 0 if failed.
Example
Result = IO1.SerialErrorReplacment(1)
...
Result = IO1.Open("COM2:", "baud=9600 parity=N data=8 stop=1") 'Open a serial Port.
SerialNullStripping(Value)
Parameters
Value 1 or 0. Undetermined results if set to other than 1 or 0.
Remarks
Specifies whether null bytes are discarded. If this is set to 1, null bytes are discarded when received.
Returns
1 if successful or 0 if failed.
Example
Result = IO1.SerialNullStripping(1)
...
Result = IO1.Open("COM2:", "baud=9600 parity=N data=8 stop=1") 'Open a serial Port.
SerialRTSControl(Value)
Parameters
Value 0,1,2,3,5,6. Controls state of RTS line. Undetermined results if set to other than specified
Remarks
If 0 then the RTS line is lowered when the device is opened.
If 1 then the RTS line is raised when the device is opened.
If set to 2 enables RTS flow-control handshaking. The driver raises the RTS line, enabling the attached device to send (when the input buffer has enough room to receive data). The driver lowers the RTS line, preventing the attached device from sending (when the input buffer does not have enough room to receive data).
If set to 3 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. (Not supported on Win95)
After the port is opened:
If called with a value of 5 sets RTS high. Only allowed if SerialRTSControl was set to 1 0r 0 before the port was opened.
If called with a value of 6 sets RTS low. Only allowed if SerialRTSControl was set to 1 0r 0 before the port was opened.
Returns
1 if successful or 0 if failed.
Example
Result = IO1.SerialRTSControl(0)
...
Result = IO1.Open("COM2:", "baud=9600 parity=N data=8 stop=1") 'Open a serial Port.
...
Result = IO1.SerialRTSControl(5)
SerialXonLimit(Value)
Parameters
Value Xon Limit.
Remarks
Specifies the minimum number of bytes allowed in the input buffer before the XON character is sent.
Returns
1 if successful or 0 if failed.
Example
Result = IO1.SerialXonLimit(256)
...
Result = IO1.Open("COM2:", "baud=9600 parity=N data=8 stop=1") 'Open a serial Port.
SerialXoffLimit(Value)
Parameters
Value Xoff Limit.
Remarks
Specifies the maximum number of bytes allowed in the input buffer before the XOFF character is sent.
Returns
1 if successful or 0 if failed.
Example
Result = IO1.SerialXoffLimit(100)
...
Result = IO1.Open("COM2:", "baud=9600 parity=N data=8 stop=1") 'Open a serial Port.
SerialXonCharacter(Value)
Parameters
Value Xon character.
Remarks
Specifies the Xon character.
Returns
1 if successful or 0 if failed.
Example
Result = IO1.SerialXonCharacter(17)
...
Result = IO1.Open("COM2:", "baud=9600 parity=N data=8 stop=1") 'Open a serial Port.
SerialXoffCharacter(Value)
Parameters
Value Xoff character.
Remarks
Specifies the Xoff character.
Returns
1 if successful or 0 if failed.
Example
Result = IO1.SerialXoffCharacter(19)
...
Result = IO1.Open("COM2:", "baud=9600 parity=N data=8 stop=1") 'Open a serial Port.
SerialErrorCharacter(Value)
Parameters
Value Error character.
Remarks
Specifies the Error character, the character used to replace bytes received with a parity error.
Returns
1 if successful or 0 if failed.
Example
Result = IO1.SerialErrorCharacter('?')
...
Result = IO1.Open("COM2:", "baud=9600 parity=N data=8 stop=1") 'Open a serial Port.
SerialEndCharacter(Value)
Parameters
Value End character.
Remarks
Specifies the End character, the character used to signal the end of data.
Returns
1 if successful or 0 if failed.
Example
Result = IO1.SerialEndCharacter(FF)
...
Result = IO1.Open("COM2:", "baud=9600 parity=N data=8 stop=1") 'Open a serial Port.
Copyright (c) 1998 by Stephen Payne