C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[37077] Re:시리얼 통신예제 관련 질문이여..^^
유영인 Cuperido [cuperido] 1344 읽음    2004-09-01 15:27
이전에 아주아주아주아주 간단한 CPort 컴포넌트용 프로그램을 만들어본적이 있었는데,
도움이 되실런지는 모르겠습니다. 간단히 그냥 읽고 쓰는 루틴입니다.


cuperido


//---------------------------------------------------------------------------

#include <vcl.h>
#include <stdio.h>
#pragma hdrstop

#include "Unit_Communication.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "CPort"
#pragma resource "*.dfm"


#define INPUT_BUFFER_SIZE              4096

TComm *Comm;

//---------------------------------------------------------------------------
__fastcall TComm::TComm(TComponent* Owner) : TForm(Owner)
{
}

//---------------------------------------------------------------------------

void __fastcall TComm::CommunicationAfterOpen(TObject *Sender)
{

Memo1->Lines->Add (">> OPEN");
Memo1->Lines->Add ("");

}

//---------------------------------------------------------------------------

void __fastcall TComm::CommunicationRxChar(TObject *Sender, int Count)
{

String            stBuffer, stString = "";
int               itCount, itFileSize, itTemp;
char              chByte;
unsigned char     chReceiveBuffer[INPUT_BUFFER_SIZE], chSendBuffer[10];


Communication->ReadStr(stBuffer, Count);

for(itCount = 0; itCount < stBuffer.Length(); itCount ++) {
   chReceiveBuffer[itCount] = stBuffer.c_str()[itCount];

   chByte   = stBuffer.c_str()[itCount];
   stString = stString + chByte;
}


Memo1->Lines->Add(stString);


// Initialize Code
if(!strncmp(CharString("010231").c_str(), chReceiveBuffer, Count)) {
   SendString("ABSTART");
   SendChar(0x00);
}


// OK Sign
if(!strncmp(CharString("4F").c_str(), chReceiveBuffer, Count)) {
   SendString("K");

   // Download
   SendString("D");
}


// Download Start
if(!strncmp(CharString("444E").c_str(), chReceiveBuffer, Count)) {
   stString = IntToHex(255, 6);

   for(itTemp = 5; itTemp >= 1; itTemp -= 2)
     SendChar(CharString(stString.SubString(itTemp, 2)).c_str()[0]);
}

}

//---------------------------------------------------------------------------

void __fastcall TComm::FormActivate(TObject *Sender)
{

Communication->Buffer->InputSize = INPUT_BUFFER_SIZE;
Communication->Open();

}

//---------------------------------------------------------------------------

void __fastcall TComm::FormClose(TObject *Sender, TCloseAction &Action)
{

Communication->Close();

}

//---------------------------------------------------------------------------

String __fastcall TComm::CharString(String stString)
{

int               itCount;
char              chChar;
String            stPiece, stResult = "";


for(itCount = 1; itCount < stString.Length(); itCount += 2) {
   stPiece = stString.SubString(itCount, 2).Trim();
   if(stPiece == "") break;

   chChar   = StrToInt("0x" + stPiece);
   stResult = stResult + chChar;
}


return(stResult);

}

//---------------------------------------------------------------------------

void __fastcall TComm::SendString(String stString)
{

Communication->WriteStr(stString);

}

//---------------------------------------------------------------------------

void __fastcall TComm::SendChar(char chChar)
{

Communication->Write(&chChar, 1);

}

//---------------------------------------------------------------------------


앙마 님이 쓰신 글 :
: Searching을 해보니 시리얼 통신에 관한 여러가지 질문이 있는데..관련예제가 컴포넌트 안에 있다고 했는데..없는것 같아서염.  자료실에 있는 컴포넌트 CPort264안에 있다는 말씀이신가요???  시리얼 통신은 그냥 CPort를 사용할려고 하구있구염..........빌더로 된 CPort예제 있는곳 아시는분 좀 부탁드립니다.. 시리얼 통신을 첨시작하는 초보가..^^* 좋은 하루 되십시요..^^*

+ -

관련 글 리스트
37057 시리얼 통신예제 관련 질문이여..^^ 앙마 1357 2004/08/31
37077     Re:시리얼 통신예제 관련 질문이여..^^ 유영인 Cuperido 1344 2004/09/01
37090         Re:Re:감사합니다(냉무)..^^* 앙마 854 2004/09/01
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.