Print# Statement
Outputs data to the specified file, communications port, database, or device.
Syntax
Print #portNumber, expression [ ,expression... ] [ , ]
Parameters
- portNumber
- ID number representing a file, communications port, database, or device. File number can be specified in ROpen, WOpen, and AOpen statements. Communications port number can be specified in OpenCom (RS232) and OpenNet (TCP/IP) statements. Database number can be specified in OpenDB statement.
Device ID integers are as follows.- 21 RC+
- 20 TP4
- expression...
- Specify a numeric value or string.
- , (comma)
- Optional. If a comma is provided at the end of the statement, then a CRLF will not be added.
Description
Print # outputs variable data, numerical values, or character strings to the communication port or the device specified by portNumber.
Notes
About the Controllers to use
For T/VT series, an error will occur at operation when RS-232C port of the Controller is specified.
Maximum data length
- Maximum data length
This command can handle up to 256 bytes. However, the target is the database, it can handle up to 4096 bytes. If the target is the communication port (TCP/IP), it can handle up to 1024 bytes.
Exchange variable data with other controller
When more than one string variable or both of numeric variable and string variable is specified, a comma (“,”) character has to be added expressly to the string data.
The following programs are examples to exchange the string variable and numeric variable between the Controllers using a communication port.
Sending end (Either pattern is OK.)
Print #PortNum, "$Status,", InData, OutData Print #PortNum, "$Status", ",",InData, OutData
Receiving end
Input #PortNum, Response$, InData, OutData
File write buffering File writing is buffered.
The buffered data can be written with Flush statement. Also, when closing a file with Close statement, the buffered data can be written.
Be sure to use Print # with Wait command or a motion command within a loop
Do not use only Print # in a loopThe Controller may freeze up if only Print # is used in loop (loops with no Wait or no motion).
Depending on the Controller status, information may not be displayed properly even if the Wait command or a motion command is used. Wait time should be at least 0.1 second.
Bad example
Do Print #24,"1234" Loop
Good example
Do Print #24,"1234" Wait 1 Loop
See Also
Input#, Print, Write, WriteBin
Print # Statement Example
The following are some simple Print # examples:
Function printex
String temp$
Print #1, "5" 'send the character "5" to serial port 1 temp$ = "hello"
Print #1, temp$
Print #2, temp$
Print #1 " Next message for " + Chr$(34) + "port 1" + Chr$(34)
Print #2 " Next message for " + Chr$(34) + "port 2" + Chr$(34)
Fend