|
실험의 내용은 다음과 같습니다.
1. Virtual Serial Ports Emulator 프로그램을 이용하여,
2. 가상포트 2번과 5번을 연결시켜서.
3. C++ Builder로 작성된 프로그램(이하 CBP)을 COM2에 연결하고,
3. ComMaster라는 시리얼 프로그램을 COM5에 연결했음.
6. 그래서 서로 주고 받기를 하니. 데이터의 누락없이 정확하게 보내고 받는 것을 확인 했음.
그런데.....
실제 보드(DSP보드)에 연결하고 통신을 시도하면
1. ComMaster 시리얼 프로그램은 모든 데이터를 받고 잘 보냄.
2. 하지만, CBP에서는 데이터를 받지 못하고 있음
( --> 아직 보내는 것은 실험하지 않았음.)
3. CBP에서는 데이터의 누락이 있음.
이를 어떻게 해야 하나요?
아~자~~! 님이 쓰신 글 :
: Cport를 사용하여 시리얼 통신(RS232)을 하는데요.
: 일단 TComPort4Beta의 예제파일들로 실행시키고 있습니다.
: 예제파일명은 ComExample입니다.
: 문제점은 다음과 같습니다.
:
: 받는 데이터는 "02 01 C4 C7 03" 입니다.
:
: 1. EventChar가 #0 일때에,
: Cport->ReadStr()에서 데이터를 1개만 받습니다.
: 받는 데이터의 중간에 NULL은 없습니다.
:
: 2. EventChar가 #3 일때에, (데이터 패킷을 마지막은 0x03)으로 끝납니다.)
: Cport->ReadStr()에서 데이터를 2개만 받습니다.
: 받는 데이터의 중간에 NULL은 없습니다.
:
: 3. Cport->ReadStr()은 동기식이고,
: Cport->ReadStrAsync()은 비동기식이니까.
: 따라서 RS232는 비동기식이므로 "Cport->ReadStrAsync()"을 사용해야 되지 않나요?
:
: 4. 다음은 ComMainForm.Cpp파일과 Form의 텍스트 파일입니다.
: //**************************//
: //*** ComMainForm.cpp ***//
: //**************************//
: //---------------------------------------------------------------------------
: #include <vcl.h>
: #pragma hdrstop
:
: #include "ComMainForm.h"
: //---------------------------------------------------------------------------
: #pragma package(smart_init)
: #pragma resource "*.dfm"
: TForm1 *Form1;
: //---------------------------------------------------------------------------
: __fastcall TForm1::TForm1(TComponent* Owner)
: : TForm(Owner)
: {
: }
: //---------------------------------------------------------------------------
: void __fastcall TForm1::Button_OpenClick(TObject *Sender)
: {
: if (ComPort->Connected)
: ComPort->Close();
: else
: ComPort->Open();
: }
: //---------------------------------------------------------------------------
:
: void __fastcall TForm1::Button_SettingsClick(TObject *Sender)
: {
: ComPort->ShowSetupDialog();
: }
: //---------------------------------------------------------------------------
:
: void __fastcall TForm1::Button_SendClick(TObject *Sender)
: {
: AnsiString Str;
:
: Str = Edit_Data->Text;
: if (NewLine_CB->Checked)
: Str = Str + "\r\n";
: ComPort->WriteStr(Str);
: }
: //---------------------------------------------------------------------------
:
: void __fastcall TForm1::ComPortOpen(TObject *Sender)
: {
: Button_Open->Caption = "Close";
: }
: //---------------------------------------------------------------------------
:
: void __fastcall TForm1::ComPortClose(TObject *Sender)
: {
: Button_Open->Caption = "Open";
: }
: //---------------------------------------------------------------------------
:
: void __fastcall TForm1::ComPortRxChar(TObject *Sender, int Count)
: {
: AnsiString Str;
:
: ComPort->ReadStr(Str, Count);
: Memo->Text = Memo->Text + Str;
: }
: //---------------------------------------------------------------------------
:
:
:
:
:
:
:
: //*************************************//
: //*** 다음은 Form의 텍스트 파일입니다 ***//
: //*************************************//
: object Form1: TForm1
: Left = 191
: Top = 107
: Caption = 'ComPort Library example'
: ClientHeight = 363
: ClientWidth = 558
: Color = clBtnFace
: Font.Charset = DEFAULT_CHARSET
: Font.Color = clWindowText
: Font.Height = -11
: Font.Name = 'MS Sans Serif'
: Font.Style = []
: OldCreateOrder = True
: PixelsPerInch = 96
: TextHeight = 13
: object Memo: TMemo
: Left = 1
: Top = 1
: Width = 433
: Height = 297
: ImeName = 'Microsoft Office IME 2007'
: ReadOnly = True
: ScrollBars = ssBoth
: TabOrder = 0
: end
: object Button_Open: TButton
: Left = 456
: Top = 8
: Width = 75
: Height = 25
: Caption = 'Open'
: TabOrder = 1
: OnClick = Button_OpenClick
: end
: object Button_Settings: TButton
: Left = 456
: Top = 40
: Width = 75
: Height = 25
: Caption = 'Settings'
: TabOrder = 2
: OnClick = Button_SettingsClick
: end
: object Edit_Data: TEdit
: Left = 440
: Top = 80
: Width = 113
: Height = 21
: ImeName = 'Microsoft Office IME 2007'
: TabOrder = 3
: end
: object Button_Send: TButton
: Left = 456
: Top = 104
: Width = 75
: Height = 25
: Caption = 'Send'
: Default = True
: TabOrder = 4
: OnClick = Button_SendClick
: end
: object NewLine_CB: TCheckBox
: Left = 448
: Top = 136
: Width = 89
: Height = 17
: Caption = 'Send new line'
: Checked = True
: State = cbChecked
: TabOrder = 5
: end
: object Panel1: TPanel
: Left = 0
: Top = 304
: Width = 433
: Height = 57
: BevelInner = bvRaised
: BevelOuter = bvLowered
: TabOrder = 6
: object ComLed1: TComLed
: Left = 112
: Top = 8
: Width = 25
: Height = 25
: ComPort = ComPort
: LedSignal = lsCTS
: Kind = lkPurpleLight
: RingDuration = 0
: end
: object ComLed2: TComLed
: Left = 144
: Top = 8
: Width = 25
: Height = 25
: ComPort = ComPort
: LedSignal = lsDSR
: Kind = lkPurpleLight
: RingDuration = 0
: end
: object ComLed3: TComLed
: Left = 176
: Top = 8
: Width = 25
: Height = 25
: ComPort = ComPort
: LedSignal = lsRLSD
: Kind = lkPurpleLight
: RingDuration = 0
: end
: object ComLed4: TComLed
: Left = 256
: Top = 8
: Width = 25
: Height = 25
: ComPort = ComPort
: LedSignal = lsRing
: Kind = lkYellowLight
: RingDuration = 0
: end
: object Label2: TLabel
: Left = 112
: Top = 32
: Width = 21
: Height = 13
: Caption = 'CTS'
: end
: object Label3: TLabel
: Left = 144
: Top = 32
: Width = 23
: Height = 13
: Caption = 'DSR'
: end
: object Label4: TLabel
: Left = 176
: Top = 32
: Width = 29
: Height = 13
: Caption = 'RLSD'
: end
: object Label5: TLabel
: Left = 256
: Top = 32
: Width = 22
: Height = 13
: Caption = 'Ring'
: end
: object ComLed5: TComLed
: Left = 344
: Top = 8
: Width = 25
: Height = 25
: ComPort = ComPort
: LedSignal = lsTx
: Kind = lkRedLight
: RingDuration = 0
: end
: object ComLed6: TComLed
: Left = 376
: Top = 8
: Width = 25
: Height = 25
: ComPort = ComPort
: LedSignal = lsRx
: Kind = lkRedLight
: RingDuration = 0
: end
: object Label1: TLabel
: Left = 350
: Top = 32
: Width = 12
: Height = 13
: Caption = 'Tx'
: end
: object Label6: TLabel
: Left = 382
: Top = 32
: Width = 13
: Height = 13
: Caption = 'Rx'
: end
: end
: object ComPort: TComPort
: BaudRate = br9600
: Port = 'COM1'
: Parity.Bits = prNone
: StopBits = sbOneStopBit
: DataBits = dbEight
: DiscardNull = True
: Events = [evRxChar, evTxEmpty, evRxFlag, evRing, evBreak, evCTS, evDSR, evError, evRLSD, evRx80Full]
: FlowControl.OutCTSFlow = False
: FlowControl.OutDSRFlow = False
: FlowControl.ControlDTR = dtrEnable
: FlowControl.ControlRTS = rtsDisable
: FlowControl.XonXoffOut = False
: FlowControl.XonXoffIn = False
: OnAfterOpen = ComPortOpen
: OnAfterClose = ComPortClose
: OnRxChar = ComPortRxChar
: Left = 384
: Top = 8
: end
: end
|