Sequential File Extensions
The following IOCTL commands can be use to manipulate sequential files.
JIOCTL_COMMAND_SEQ_NO_DELIMITER |
Suppress SEQ delimiter |
JIOCTL_COMMAND_SEQ_CHANGE_DELIMITER |
Change SEQ delimiter |
JIOCTL_COMMAND_SEQ_CHANGE_RECORDSIZE |
Change SEQ Record size |
JIOCTL_COMMAND_SEQ_CHANGE_PADCHAR |
Change SEQ Pad char |
JIOCTL_COMMAND_SEEK |
Reposition the pointer to a specified position in the SEQ file |
EXAMPLES
INCLUDE JBC.h
OPENSEQ "SeqFile" TO FILE ELSE STOP 201,"SeqFile"
*IF IOCTL(FILE, JIOCTL_COMMAND_SEQ_NO_DELIMITER, ") ELSE STOP
*IF IOCTL(FILE, JIOCTL_COMMAND_SEQ_CHANGE_DELIMITER, ",") ELSE STOP
*IF IOCTL(FILE, JIOCTL_COMMAND_SEQ_CHANGE_RECORDSIZE,"10") ELSE STOP
*IF IOCTL(FILE, JIOCTL_COMMAND_SEQ_CHANGE_PADCHAR,".") ELSE STOP
FOR I = 1 TO 10
WRITESEQ "Data":I ON FILE ELSE STOP
NEXT I
CLOSESEQ FILE
OPENSEQ "SeqFile" TO FILE ELSE STOP 201,"SeqFile"
*IF IOCTL(FILE, JIOCTL_COMMAND_SEQ_NO_DELIMITER, ") ELSE STOP
*IF IOCTL(FILE, JIOCTL_COMMAND_SEQ_CHANGE_RECORDSIZE,"3") ELSE STOP
*IF IOCTL(FILE, JIOCTL_COMMAND_SEQ_CHANGE_DELIMITER, ",") ELSE STOP
FOR I = 1 TO 10
READSEQ RECORD FROM FILE ELSE STOP
CRT "Record:":I:" Len:":LEN(RECORD):"
Data:":RECORD
NEXT I
* IOCTL(file, JIOCTL_COMMAND_SEEK, parameter)
* Where 'parameter' should be of the form:
* "offset, blocknumber"
* Examples:
* "0,0" repositions to the start
of the file...
* IF IOCTL(FILE, JIOCTL_COMMAND_SEEK,"0,0") ELSE
STOP
*
* To set the position at the 100th byte of the 42nd block,
* a 'block' being defined by the delimiter character...
* IF IOCTL(FILE, JIOCTL_COMMAND_SEEK,"100,42") ELSE
* PRINT "IOCTL() failed!"
* STOP
* END
*
* This next example illustrates how to seek to a specific location
* when there is no delimiter, and only the 'blocksize' is defined...
*
* First set the delimiter to null
* IF IOCTL(FILE, JIOCTL_COMMAND_SEQ_NO_DELIMITER, '') ELSE
STOP
* Define the blocksize, in this case it will be a 2k block
* IF IOCTL(FILE, JIOCTL_COMMAND_SEQ_CHANGE_RECORDSIZE, 2048)
ELSE STOP
* Now set the position (seek) to the middle (1025th character) of 123rd block
* IF IOCTL(FILE, JIOCTL_COMMAND_SEEK, "1025,123")
*
SERIAL IO EXTENSIONS
Serial IO to the com ports on NT and to device files on Unix can be achieved using the
sequential file statements. In addition certain control operations can be performed using
the ioctl function.
OPENSEQ
The specified Port, such as "COM2", is opened to FileVar for exclusive access,
therefore this command will fail if any other process has the COM port open.
READSEQ
Reads 512 bytes from the previously opened Serial port. By default, the read will block
until the required number of characters are available, however, the actual number to read,
and any timeout value can be set using the IOCTL() function.
WRITESEQ
The variable is written to the previously opened serial port. Normally this data will not
have a CRLF appended to it, but using an IOCTL command can change this action.
IOCTL
This function returns a Boolean TRUE if the command was successful and FALSE if it failed.
The general jBASE include file "JBC.h" should be included in order to get the
system equates for the commands.
SERIAL IO EXTENSIONS
The following IOCTL commands can be use to manipulate serial io.
JIOCTL_COMMAND_SERIAL_GET_STATE
JIOCTL_COMMAND_SERIAL_SET_STATE
Get or Set the serial port line state, in the format
"BaudRate,Parity,NoBits,FlowControl"
Where:
Baudrate |
The value of the baud rate, |
Parity |
0 _ None, 1 - Even, 2 - Odd, 3 - Mark. |
NoBits |
The number of bits, normally 7 or 8, |
FlowControl |
Bit mask; 0x1 Xon/Xoff; 0x2 RTS/CTS; 0x4 DTR/DSR |
e.g. "9600,1,7,1" 9600 Baud, 7 bit even parity, Xon/Xoff flow control.
Note: the jBASE command jsetport can also be used to set/get the setting for a serial
port(jsetport COM2)
JIOCTL_COMMAND_SERIAL_SET_TIMEOUT
Set the Timeout value for a read, the value for the argument is:
0 |
No timeout, all reads will block until the specified number of characters
have been read (This is the Default) |
-1 |
Non blocked read, the Read will return immediately, with however many
characters are in the buffer |
> 0 |
The read will return with either the number of requested characters, or
after the specified number of milliseconds |
JIOCTL_COMMAND_SERIAL_SET_CRLF
Append a CRLF to each WRITESEQ.
JIOCTL_COMMAND_SERIAL_SET_RAW
Do not append a CRLF after each write (Default).
JIOCTL_COMMAND_SERIAL_READ_LEN
Specify how many characters each READSEQ will read, the default is 512.
JIOCTL_COMMAND_SERIAL_FLUSH
Purge any buffered input/output.
EXAMPLE
INCLUDE JBC.h
EQU CRLF TO CHAR(10):CHAR(13)
EQU CHAR_ESC TO CHAR(27)
EQU CHAR_CR TO CHAR(10)
EQU CHAR_LF TO CHAR(13)
Comport = "COM2"
*
* Comstate here 9600 Baud, 8 bit no parity, no flow control.
*
ComState = "9600,0,8,0"
*
* Open the port
*
OPENSEQ ComPort TO Fd ELSE STOP 201,ComPort
*
* Set up the line state
*
IF IOCTL(Fd, JIOCTL_COMMAND_SERIAL_SET_STATE, ComState) ELSE
CRT "Set State Failed"
END
*
* Now output some text.
*
WRITESEQ @(-1):"jBASE NT Serial line Test":CRLF ON Fd ELSE GOTO
999
*
* Test a timed read (500ms)
*
IF IOCTL(Fd, JIOCTL_COMMAND_SERIAL_SET_TIMEOUT, "500") ELSE
CRT "Set Timeout Failed"
END
WRITESEQ "Timed Read :" ON Fd ELSE GOTO 999
READSEQ X FROM Fd ELSE CRT "Read Timed Out"
*
* Now just go into a loop reading text from the port, exit when we receive an
"X"
*
X = "
LOOP
WHILE X NE "X" DO
WRITESEQ CRLF:"Input :" ON Fd ELSE GOTO 999
READSEQ X FROM Fd THEN
CRT "GOT IT :":X
END ELSE
CRT "Timeout"
END
REPEAT
* 999:
Files
|