|
안녕하세요...
제가 옛날에 win98환경에서 CBuilder 5.0으로 cport 2.64를 이용하여 시리얼 통신을 구현하였는데...
수년이 지난 지금에는 win98도 사용하고 winxp도 사용한다고 합니다.
그런데 문제가 되는것이 지금의 제 컴파일 환경은 winxp pro 환경에 CBuilder 5.0, cport 2.64이고 소스는 과거(win98)에 짠 소스를 가지고 있습니다...
지금의 환경에서 과거 win98과 winxp 둘다 시리얼 통신이 가능한지 궁금하여 이렇게 고수님들에게 여쭈어 봅니다.
가능할까요? 가능하다면 방법이 있는지...? 질의 응답을 두루 둘러 보았는데 cport 2.64를 포기하고 다른 컴포넌트로 사용하면 가능한지? 궁금합니다...
참고로...
제 cpp 소스를 추가해 보았습니다... --;;;
//---------------------------------------------------------------------------
#include <vcl.h>
#include <stdio.h>
#include <Dos.h>
#include <IniFiles.hpp>
#pragma hdrstop
#include "Main.h"
#include "select.h"
#include "MainStorage.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "CPort"
#pragma resource "*.dfm"
TMain *Main;
//---------------------------------------------------------------------------
__fastcall TMain::TMain(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TMain::SpeedButton1Click(TObject *Sender)
{
AnsiString SendBuf;
if(!ComPort1->Connected)
ComPort1->Open();
if (!ComPort1->Connected)
{
Application->MessageBox("직렬 포트를 열수 없습니다. 프린터와 통신을 할 수 없습니다.\n직렬 포트를 다른 프로그램이 사용하고 있는지 확인하세요.", "직렬 포트 열기 에러", MB_ICONSTOP | MB_OK);
return;
}
if (!CheckSP(3)) {
Application->MessageBox("시리얼에 응답이 없습니다. 프린터 전원이 연결 되었는지, 케이블이 PC와의 연결 상태가 올바른지 확인하십시요.", "시리얼 에러", MB_ICONSTOP | MB_OK);
ComPort1->Close();
return;
}
int cnt = 1;
//송신
ComPort1->WriteStr("TEST001");
ComPort1->WriteStr("SPEC정의");
ComPort1->Close();
}
//---------------------------------------------------------------------------
void __fastcall TMain::SpeedButtonExitClick(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TMain::ComPort1RxChar(TObject *Sender,
int Count)
{
AnsiString Str;
int i;
ComPort1->ReadStr(Str, Count);
for (i = 1 ; i<=Count ; i ++)
{
if (Str.SubString(i,1) == "(")
strComBuffer = "";
else if (Str.SubString(i,1) == "\n" )
{
if(strComBuffer.SubString(1,2) == "OK") {
m_bCheckSP = TRUE;
strComBuffer = "";
}
}
else
strComBuffer += Str.SubString(i,1);
}
}
//---------------------------------------------------------------------------
bool __fastcall TMain::CheckSP(int nTime)
{
AnsiString Buffer;
m_bCheckSP = false;
ComPort1->WriteStr("ACK");
Sleep(100);
struct time t;
int nOld, nMax = nTime, nCount = 0, nESTCount = 1;
gettime(&t);
nOld = t.ti_sec;
while(1)
{
gettime(&t);
if (nOld != t.ti_sec)
{
nCount++;
nOld = t.ti_sec;
if (nCount == nMax)
{
return false;
}
if (nESTCount == 1)
{
ComPort1->WriteStr("NAK");
nESTCount = 0;
}
nESTCount++;
}
MSG message;
if (PeekMessage(&message, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&message);
DispatchMessage(&message);
}
if (m_bCheckSP)
break;
}
m_bCheckSP = false;
Sleep(100);
return true;
}
//---------------------------------------------------------------------------
void __fastcall TMain::FormShow(TObject *Sender)
{
TIniFile *ini;
ini = new TIniFile(ChangeFileExt(Application->ExeName,".INI"));
ComPort1->Port = ini->ReadString("PORT_CHECK","SELECT","COM1");
if(ComPort1->Port == "COM1")
RadioGroupPort->ItemIndex = 0;
else
RadioGroupPort->ItemIndex = 1;
delete ini;
// EditArr->SetFocus();
}
//---------------------------------------------------------------------------
void __fastcall TMain::FormClose(TObject *Sender,
TCloseAction &Action)
{
TIniFile *ini;
ini = new TIniFile(ChangeFileExt(Application->ExeName,".INI"));
ini->WriteString("PORT_CHECK","SELECT" ,RadioGroupPort->Items->Strings[RadioGroupPort->ItemIndex]);
delete ini;
}
//---------------------------------------------------------------------------
void __fastcall TMain::m_edGeoKeyPress(TObject *Sender,
char &Key)
{
if(Key == 13) EditPrd->SetFocus();
}
//---------------------------------------------------------------------------
void __fastcall TMain::m_edSuKeyPress(TObject *Sender,
char &Key)
{
if (Key == 13) SpeedButton1Click(this);
}
//---------------------------------------------------------------------------
void __fastcall TMain::RadioGroupPortClick(TObject *Sender)
{
switch(RadioGroupPort->ItemIndex)
{
case 0 :
ComPort1->Port = "COM1";
break;
case 1 :
ComPort1->Port = "COM2";
break;
}
}
//---------------------------------------------------------------------------
|