nuk@wpi.WPI.EDU (Jacob W Anderson) (04/09/91)
I have been trying to program my serial port on a MacSE with 128k ROMs using a Hayes compatible modem, but have found that the protocol used in the following program does not work properly. In fact, it does not work at all it does not generate any run-time errors, but rather does nothing that it should (like dialing). Please, if you have any idea what I am doing wrong, please tell me. I possible please tell me in 'C' for I am using both Think Pascal and Think C, but the final project is to be in 'C'. Thanks in adavance. please E-mail. nuk@wpi.wpi.edu ================================================ program serial trial; const baud2400 = 46; noParity = 0; data8 = 3072; stop10 = 16384; var Error: OSErr; PortIn: Integer; PortOut: Integer; SerConfig: Integer; csParamPtr: Ptr; Buffer: Ptr; procedure DoError; begin if Error <> 0 then begin writeln('Error:', Error, ' has occured in accessing serial d river.'); ExitToShell; end; end; {this procedure sends data to the modem} procedure Send (Data: Str255); var Count: LongInt; begin Count := LongInt(Length(Data)); writeln('Sending ', Data, ' &', count, 'bytes'); Buffer := @Data; Error := FSWrite(PortOut, count, Buffer); DoError; end; procedure TalkToModem; var count: LongInt; DataIn: Str255; begin Send('ATE1 V1'); Send(chr(13)); writeln('..........Talking to Modem'); Readln(DataIn); Send(DataIn); writeln('getting feedback'); DataIn := ' '; count := 2; Error := FSRead(PortIn, count, @DataIn); DoError; writeln(DataIn, ' ....waiting'); for count := 1 to 150 do write('.'); writeln; send('ATH1'); Send(chr(13)); writeln('sending dial command'); Readln(DataIn); Send(DataIn); Send(chr(13)); end; begin SerConfig := baud2400 + noParity + data8 + stop10; writeln('Opening driver for Input'); Error := OpenDriver('.AIn', PortIn); DoError; writeln('Opening driver for output'); Error := OpenDriver('.AOut', PortOut); DoError; writeln('Resetting input channels'); Error := Control(PortIn, 8, pointer(SerConfig)); DoError; writeln('Resetting output channels'); Error := Control(PortOut, 8, pointer(SerConfig)); DoError; TalkToModem; writeln('Closing serial port channels'); end.
jmatthews@desire.wright.edu (04/10/91)
In article <1991Apr9.002744.28880@wpi.WPI.EDU>, nuk@wpi.WPI.ED (Jacob W Anderson) writes: > I have been trying to program my serial port on a MacSE with 128k ROMs using > a Hayes compatible modem, but have found that the protocol used in the > following program does not work properly. In fact, it does not work at all > it does not generate any run-time errors, but rather does nothing that it > should (like dialing). > Please, if you have any idea what I am doing wrong, please tell me. I possible > please tell me in 'C' for I am using both Think Pascal and Think C, but the > final project is to be in 'C'. Thanks in adavance. > > please E-mail. > nuk@wpi.wpi.edu > > ================================================ > > [...] > > {this procedure sends data to the modem} > procedure Send (Data: Str255); > var > Count: LongInt; > begin > Count := LongInt(Length(Data)); > writeln('Sending ', Data, ' &', count, 'bytes'); > Buffer := @Data; > Error := FSWrite(PortOut, count, Buffer); > DoError; > end; > > [...] One problem lies in passing FSWrite a pointer to the first byte in a Pascal string. This byte is the string's length. Try Buffer:= pointer(ord(@data)+1) Hope this helps, John o----------------------------------------------------------------------------o | John B. Matthews, jmatthews@desire.wright.edu, am103@cleveland.freenet.edu | | "Say...what's a mountain goat doing way up here in a cloud bank?" - Larson | o----------------------------------------------------------------------------o
jmatthews@desire.wright.edu (04/10/91)
In article <1991Apr9.230956.3159@desire.wright.edu>, jmatthews@desire.wright.ed I write: > In article <1991Apr9.002744.28880@wpi.WPI.EDU>, nuk@wpi.WPI.ED > (Jacob W Anderson) writes: >> I have been trying to program my serial port on a MacSE with 128k ROMs using >> a Hayes compatible modem, but have found that the protocol used in the >> following program does not work properly. In fact, it does not work at all >> it does not generate any run-time errors, but rather does nothing that it >> should (like dialing). >> Please, if you have any idea what I am doing wrong, please tell me. I possible >> please tell me in 'C' for I am using both Think Pascal and Think C, but the ^^^^^^^^^^^^^^^^^^^^^ >> final project is to be in 'C'. Thanks in adavance. >> >> please E-mail. >> nuk@wpi.wpi.edu >> >> ================================================ >> >> [...] >> >> {this procedure sends data to the modem} >> procedure Send (Data: Str255); >> var >> Count: LongInt; >> begin >> Count := LongInt(Length(Data)); >> writeln('Sending ', Data, ' &', count, 'bytes'); >> Buffer := @Data; >> Error := FSWrite(PortOut, count, Buffer); >> DoError; >> end; >> >> [...] > > One problem lies in passing FSWrite a pointer to the first byte in a Pascal > string. This byte is the string's length. Try > > Buffer:= pointer(ord(@data)+1) > > Hope this helps, John Whoops! I didn't see your request for help in "C". I know much too little about "C", but I think the problem doesn't exist in "C"; it's strings don't start with a length byte. John. o----------------------------------------------------------------------------o | John B. Matthews, jmatthews@desire.wright.edu, am103@cleveland.freenet.edu | | "Say...what's a mountain goat doing way up here in a cloud bank?" - Larson | o----------------------------------------------------------------------------o