harrow@exodus.dec.com (Jeff Harrow, NCSE LKG1-3/F16 DTN=226-7445) (09/17/86)
I could use a pointer (sic). Using Lightspeed Pascal (which strictly enforces typing) I'm trying to use the Serial Driver to collect data from the modem port and then do string manipulation on the resultant data. I'm currently attempting the following (fragment): var CharsInModem : Longint; theChars : StringPtr; err : OSErr; {creates a new buffer the length of the Type (StringPtr) (255)} {bytes long, pointed to by theChars.} New(theChars); repeat {Returns # of characters currently in Serial Driver's input buffer} err := SerGetBuf(-6, CharsInModem); {if there are any characters that have been received...} if CharsInModem > 0 then begin {Attempt to get <CharsInModem> characters out of} {the serial driver's buffer, put them in the} {<theChars> buffer, and return the actual number} {of characters returned in <CharsInModem>} err := FSRead(-6, CharsInModem, Pointer(theChars)); {Convert the characters in <theChars> (which I} {believe are stored beginning at the ZEROth byte of} {the buffer, NOT at the 1st (as in a Pascal String)} {and write the new string out.} {I KEEP MISSING THE 1ST CHARACTER OUT OF EACH BATCH!} writeln (copy(theChars^, 0, CharsInModem)); {Here, we use DrawText to output the characters} {in <theChars>, AND IT COMES OUT CORRECTLY, because} {this routine assumes that the data is NOT a Pascal} {string, but just a generic buffer!!} DrawText(Pointer(theChars), 0, CharsInModem); end; end; until 1 <> 1; {forever} Two questions: First, am I causing problems using a StringPtr to create my buffer (as opposed to generating some kind of "generic" buffer, which I haven't figured out how to do)? and Second, how do I correctly turn data in a "generic" buffer (which I believe this buffer to be, as far as where FSRead is placing the characters (beginning from the ZEROth byte)) into a Pascal String, so that I can subsequently use other String functions to manipulate the data? I've tried things like: myString := copy(ord(@theChars^), 0, CharsInModem); but that returned garbage. Remember, Lightspeed Pascal will not allow you to access subscript ZERO of any kind of String variable to stuff in the Length byte! Is my approach all wet (all I want to do is get some data from the modem!) or have I just missed some important MacFact? Thanks for you help! Jeff Harrow Work address: ARPAnet: HARROW%EXODUS.DEC@decwrl.ARPA Usenet: decwrl!exodus.dec.com!harrow or {allegra,Shasta,decvax}!decwrl!dec-rhea!dec-exodus!harrow Easynet: EXODUS::HARROW Telephone: (617)486-7445 USPS: Digital Equipment Corp. Mail stop: LKG1-3/F16 550 King Street Littleton, MA 01460