Can,
Simple answer: InCOMM(1)
Long answer:
If you type characters on your PC using hyperterminal, the function INPUT$(1) will assign "" to A$ if you call this function before the PLC receives a CR from the PC. Once a CR has been received, then a call to INPUT$(1) will return the characters entered, but not the CR.
If the text string is longer than string variable can hold (A$..Z$ can hold 70 chars), INPUT$(1) will return the first 70 characters of the message. Then next call will return either then remaining characters or the next 70 characters in the PLC's receive buffer. Please be careful with this.
If the text string is longer than 256 characters, then data can be lost. The PLC's firmware allocates exactly 256 bytes to buffer data for each serial port. If data comes into the PLC faster than your PLC code can read it, you will lose it and scramble the PLC receive buffer.
If your string is terminated with 2 characters (carriage return and then linefeed) as is typical with DOS text files, then INPUT$(1) will return the string correctly, but will leave the linefeed in the receive buffer. The next call to INPUT$(1) will return a string that starts with the linefeed character left over from the previous string and then next string (if any) that has been received by the PLC's firmware.
INPUT$() works great if the serial device connected to the PLC sends printable ASCII characters and terminates these characters with an ASCII carriage return. Oh and the messages are shorter than 70 characters!!!
There are many serial devices that send data that does not fit this pattern:
1. GSM MODEMs for doing SMS text messaging. These things send ASCII text but send both an ASCII carriage return and an ASCII line feed. They use 2 characters to terminate the line. And the messages can be longer than 256 characters. And the GSM MODEMs will send data to the PLC at any time so the PLC code has to be very busy to not lose data.
2. MODBUS RTU sends binary data and does not use any line terminator.
If you need the PLC to handle messages that are not terminated with an ASCII Carriage return or binary data, then you can use the InCOMM() function. InCOMM() returns a -1 value if there is no data in the receive buffer or a single character (8-bit value).
This is a snippet of what I'm doing to handle MODBUS RTU on an Fx series PLC :
Timeout = 100 ' max to wait for response
ch = InCOMM(MODBUSPort)
while (ch = -1)
delay 1 ' kill and little time
ch = InCOMM(MODBUSPort) ' see if a character has been received
Timeout = Timeout - 1 ' and keep track of time remaining
if (Timeout <= 0)
return = MBTimeout ' no response from the slave...
endif
endwhile
' we have received the first character of the response, but probably
' not the entire response.
'
delay 10 ' delay to allow the entire response from the MODBUS Slave
' to be transmitted and received by the PLC
'
Index = 0 ' start at beginning of MBResponse buffer
while (ch <> -1) ' response characters in buffer
DM[MBResponse + Index] = ch ' save this one
Index = Index + 1
ch = InCOMM(MODBUSPort) ' get next character
endwhile
[/font][/color]
I know that this is a little overkill, but InCOMM() allows me to work around the limitations of INPUT$().
Gary D