아직 모뎀을 이용해서 파일을 송수신해야하는 곳이 있다니 놀랍군요.
원격지 컴퓨터와 전화선 모뎀을 이용해서 파일을 송수신해야 한다면
http://sourceforge.net/projects/tpapro/
의 소스를 이용해서 ZModem을 사용하시는 편이 좋을 듯 합니다.
본사의 서버에 전화접속네트워킹 서버를 설치하고 사용하는 방법도 있습니다.
97년 이후론 전화선 모뎀을 안써봐서 기억이 좀 가물거리긴 합니다^^
thinkstone 님이 쓰신 글 :
: 아는게 없다보니 첩첩산중이네요.
:
: 죄송하지만 한번 더 봐 주세요.
:
: 프로그램 흐름은
:
: 현장pc의 데이터들은 파일명이 날짜로 되어 있고
:
: 사무실 pc에서 일정 시간 간격마다 디비에 들록된 현장들에 차레로 모뎀 접속해서
:
: 데이터파일을 읽어 와서 지정된 폴더에 저장 하고 처리하는 프로그램입니다.
:
: 현재 사무실pc엔 데이터가 없어서 'ALL.TXT'라고 파일명을 보내주고 현장pc에선 해당폴더의 모든 파일을 보내줍니다.
:
: 전체읽기모드로 시작해서 처음 현장은 예상대로 잘 되었고 포트연결도 잘 끊어져서
:
: 현장 pc 대기 상태이고
:
: 사무실px 에서 다음 현장 정보를 넘겨주기위해 접속하는데
:
: 현장pc창에 connect라고 뜨고 연결된 상태인데
:
: 프로그램이 뻑이 납니다. 그다음 진행이 안되요.
:
: 현장pc는 ClearToSend, DataSetReady, ReceiveLineSignalDetact에 불 들어와 있고 화면엔 connect 찍혀 있습니다.
:
: 사무실pc는 Tx(송신중)에만 불들어와 있습니다.
:
: 주요부분 소스 입니다.
:
: 파란색 부분이 문제입니다. 연결되었다는걸 못 알아채는건 아닌지 싶어서 두가지나 넣었네요
:
: 거기서 걸려야 되는데 안걸리는거 같아요.
:
: 통신 어려워요 ㅠㅠ
:
:
:
:
: [현장pc 소스]
:
: procedure TForm1.ComPortRxChar(Sender: TObject; Count: Integer);
: var
: Str: String;
: w : string;
: i : integer;
: begin
: Str := '';
: ComPort.ReadStr(Str, Count);
: Memo.Text := Memo.Text + Str;
:
: for i:=1 to Count do begin
: if Str[i] = #2 then begin
: Rcv_State := 1; //데이터 수집시작
: kind := 'D';
: Str[i] := #32;
: end;
: if Str[i] = #3 then begin
: if Rcv_State = 1 then Rcv_State := 2
: else Rcv_State := 0; //처음상태
: Str[i] := #32;
: end;
: if Str[i] = #4 then begin
: Rcv_State := 1; //file path 수집시작
: kind := 'F';
: Str[i] := #32;
: end;
: case Rcv_State of
: 1 : RxBuf := RxBuf + Str[i]; // 데이터 수집시작
: 2 : // 데이터 수집완료
: begin
: w := RxBuf + Str[i];
: if (kind='F') then
: begin
: Edit1.Text := w;
: SeekAndSendData(trim(w));
: end;
: if (kind='D') then Memo1.Text := Memo1.Text + w;
: //DatafilterPC(w); // w에 ghgghg*^UU 가 들어 있겠죠 ^^
: Rcv_State := 0; //초기 상태로를 만듭니다.
: ComPort.ClearBuffer(True,True); //버퍼 지워 줍니다.
: RxBuf := ''; // 임시 저장소 초기화 합니다.
: end;
: end;
: end;
: end;
:
: procedure TForm1.SeekAndSendData(fname: String);
: var
: TxtFile : TextFile;
: buffer : string;
: slFileList : TStringList;
: begin
: if(Pos('ALL', fname)>0) then
: begin
: slFileList := TStringList.Create;
: GetSearchedFileList('C:\ad_data', slFileList, '*.TXT', false);
: fname := slFileList[0];
: ComPort.WriteStr(#4 + fname + #3);
: end;
: if FileExists(fname) then
: begin
: ComPort.WriteStr(#2);
: AssignFile(TxtFile, fname) ;
: Reset(TxtFile) ;
: while not EOF(TxtFile) do begin
: ReadLn(TxtFile, buffer) ;
: ComPort.WriteStr(buffer+#13#10) ;
: end;
: ComPort.WriteStr(#3);
: CloseFile(TxtFile) ;
: end
: else begin
: Comport.WriteStr(#1#3);
: if ComPort.Connected then ComPort.Close;
: memo.lines.Clear;
: Comport.Open;
: end;
: end;
:
:
:
:
: [사무실 pc 소스]
:
:
:
:
: procedure TFMain.mReadAllClick(Sender: TObject);
: var
: Str : String;
: begin
: Timer3.Interval := 1000 * 60 * StrToInt(Edit_Interval.Text);
: Timer3.Enabled := false; //일정시간 간격 일기 타이머 중지
: connectOK := false;
: first := true;
: StatusBar1.Panels[2].Text := '모드 : 전체읽기';
: PageControl1.ActivePage := TabSheet1;
: ClientDataSet1.First;
: if not ClientDataSet1.Eof then Timer1.Enabled := true;
: end;
:
:
:
:
: procedure TFMain.ComPortRxChar(Sender: TObject; Count: Integer);
: var
: Str,tmp: String;
: w : string;
: i : integer;
: TxtFile : TextFile;
:
: begin
: Str := '';
: ComPort.ReadStr(Str, Count);
: if (Rcv_State<>1) then
: Memo.Text := Memo.Text + Str;
:
: if (Pos('CONNECT', Str)>0) then //파일 정보 전송
: begin
: connectOK := true;
: StatusBar1.Panels[2].Text := '모드 : 접속중...';
: noData := false;
: cdate := now;
: if (ldate<>'') then
: begin
: rdate := StrToDate(ldate);
: Str := #4 + 'c:\AD_DATA\' + DateToStr(rdate) + '.txt' + #3;
: StatusBar1.Panels[1].Text := DateToStr(rdate);
: end else begin
: Str := #4 + 'c:\AD_DATA\ALL.txt' + #3;
: StatusBar1.Panels[1].Text := '처음부터';
: end;
: ComPort.WriteStr(Str);
: end;
:
: if (Pos('No Data', Str)>0) then
: begin
: Comport.Close;
: noData := true;
: StatusBar1.Panels[2].Text := '모드 : No Data';
: end;
:
: for i:=1 to Count do begin
: if Str[i] = #7 then begin
: Rcv_State := 0;
: connectOK := true;
: StatusBar1.Panels[2].Text := '모드 : 접속중...';
: noData := false;
: cdate := now;
: if (ldate<>'') then
: begin
: rdate := StrToDate(ldate);
: Str := #4 + 'c:\AD_DATA\' + DateToStr(rdate) + '.txt' + #3;
: StatusBar1.Panels[1].Text := DateToStr(rdate);
: end else begin
: Str := #4 + 'c:\AD_DATA\ALL.txt' + #3;
: StatusBar1.Panels[1].Text := '처음부터';
: end;
: ComPort.WriteStr(Str);
: end;
: if Str[i] = #2 then begin
: StatusBar1.Panels[2].Text := '모드 : 데이터 수집중...';
: Rcv_State := 1; //데이터 수집시작
: kind := 'D';
: Str[i] := #32;
: end;
: if Str[i] = #3 then begin //데이터 수집 끝
: if Rcv_State = 1 then Rcv_State := 2
: else Rcv_State := 0; //처음상태
: Str[i] := #32;
: end;
: if Str[i] = #4 then begin
: ComPort.ClearBuffer(True,True); //버퍼 지워 줍니다.
: RxBuf := ''; // 임시 저장소 초기화 합니다.
: Rcv_State := 1; //file path 수집시작
: kind := 'F';
: Str[i] := #32;
: end;
: if Str[i] = #5 then begin
: ComPort.ClearBuffer(True,True); //버퍼 지워 줍니다.
: RxBuf := ''; // 임시 저장소 초기화 합니다.
: Rcv_State := 1; //수신된 처음 데이타파일명 수집시작
: kind := 'F1';
: Str[i] := #32;
: end;
: if Str[i] = #1 then begin
: Rcv_State := 2; //서버에서 해당 파일이 없으면 #1 를 보내줍니다.
: kind := 'E';
: end;
: case Rcv_State of
: 1 : RxBuf := RxBuf + Str[i]; // 데이터 수집시작
: 2 : // 데이터 수집완료
: begin
: w := RxBuf + Str[i];
: if (kind='F1') then //시작날자가 없을때 서버에서 처음 파일명을 받아옴
: begin
: Edit1.Text := trim(w);
: tmp := StringReplace(ExtractFileName(w),'.txt','',[rfReplaceAll]);
: rdate := StrToDate(tmp);
: cdate := now;
: ldate := tmp;
: end;
: if (kind='D') then begin
: AssignFile(TxtFile, path + '\' + DateToStr(rdate) + '.txt') ;
: Rewrite(TxtFile) ;
: WriteLn(TxtFile, w) ;
: CloseFile(TxtFile) ; //오늘 날짜 이전의 모든 데이터 파일 받아옴
: if ((Comparedate(rdate,cdate)<>0) and not noData) then
: begin
: rdate := IncDay(rdate,1);
: StatusBar1.Panels[1].Text := DateToStr(rdate);
: Str := #4 + 'c:\AD_DATA\' + DateToStr(rdate) + '.txt' + #3;
: ComPort.WriteStr(Str);
: end else begin
: //
: end;
: Rcv_State := 0; //초기 상태로를 만듭니다.
: ComPort.ClearBuffer(True,True); //버퍼 지워 줍니다.
: RxBuf := ''; // 임시 저장소 초기화 합니다.
: end;
: if (kind='E') then begin
: noData := true;
: StatusBar1.Panels[2].Text := '모드 : 송신 끝';
: Rcv_State := 0; //초기 상태로를 만듭니다.
: RxBuf := ''; // 임시 저장소 초기화 합니다.
: ComPort.WriteStr(#6);
: connectOk := false;
: Timer1.Enabled := true; //다음 현장 정보를 읽으러 갑니다.
: end;
:
: end;
:
: end;
: end;
: end;
:
: procedure TFMain.Timer1Timer(Sender: TObject); // dataset loop용
: var
: Str : String;
: begin
: Timer1.Enabled := false;
: if not first then
: begin
: Timer2.Enabled := true; ////다음 현장 접속을 위해 포트를 닫아줍니다.
: sleep(7000);
: end;
: if not ClientDataSet1.Eof then
: begin
: first := false;
: Comport.Port := 'COM' + ClientDataSet1.FieldByName('ComPort No').AsString;
: PhoneNo := ClientDataSet1.FieldByName('전화번호').AsString;
: SiteName := ClientDataSet1.FieldByName('현장').AsString;
: ldate := ClientDataSet1.FieldByName('최종Data일시').AsString;
: path := ClientDataSet1.FieldByName('Data Path').AsString;
: StatusBar1.Panels[0].Text := '현장명 :' + SiteName;
: ClientDataSet1.Next;
: try
: if not Comport.Connected then Comport.Open;
: if Comport.Connected then
: begin
: while not connectOK do
: begin
: StatusBar1.Panels[2].Text := '모드 : 접속중...';
: Str := 'atdt ' + PhoneNo + #13#10;
: ComPort.WriteStr(Str);
: if not connectOK then sleep(2000);
: end;
: end;
: except
: on E: Exception do
: begin
: Log(E.Message);
: end;
: end;
: end
: else begin //eof
: Timer3.Enabled := true; //일정시간 간격 일기 타이머 시작 .
: end;
:
: end;
:
:
: procedure TFMain.Timer2Timer(Sender: TObject); //port close용
: begin
: Timer2.Enabled := false;
: StatusBar1.Panels[1].Text := '모드 : No Data';
: Comport.Close;
: while Comport.Connected do sleep(100);
: if not Comport.connected then ShowMessage('close');
: //Timer1.Enabled := true;
: end;
:
: procedure TFMain.Timer3Timer(Sender: TObject);
: begin
: mReadAllClick(Self); //정해진 시간이 지나면 처음현장부터 다시 반복
: end;
:
:
: