USB-024評価用簡易アプリケーションのソースが見たい


USB-024評価用簡易アプリケーションのソースは公開できませんか

 このアプリケーションは、C++Builder2007とnrCommという市販通信コンポーネントを使用しています。本体の部分はわずかですので抜粋してお見せします。
実装しているのは、"1A"コマンドのみです。
nrCommについてはこちらをご覧ください)

 ソースコードは、処理の内容を説明するもので、コードが正しいとは限りません。

///////////////////////////////////////////

String convhex( unsigned char *p, int n )
{
int i;
unsigned char bcc;
String wk,ret;
    ret = "";
    for( i = 0; i < n ; i++ ){
        ret = ret + wk.sprintf("%02X ", p[i]);
    }
    //bcc = calcCRC( p , n-1 );
    bcc = 0;
    for( i = 0; i < n-1 ; i++ ){
        bcc = bcc ^ p[i];
    }
    if( bcc == p[i] ){
        ret = ret + " <bcc OK>";
    }else{
        ret = ret + " <bcc ERROR>";
    }
    return ret;
}

struct FM_1A {
	unsigned char  cmd;        // 0
	unsigned char  status;     // 1
    unsigned char  abs0;       // 2
    unsigned char  abs1;       // 3
    unsigned char  abs2;       // 4
    unsigned char  enid;       // 5
	unsigned char  abm0;       // 6
    unsigned char  abm1;       // 7
    unsigned char  abm2;       // 8
    unsigned char  almc;       // 9
    unsigned char  crc;        // 10
};

String kaiseki(  unsigned char *p, int n )
{
int abm,abs;
String ret,s1;
double wk, wk1;
struct FM_1A *tp;
	tp = (struct FM_1A *)p;
	if( tp->cmd == 0x1A ){
    	abs = tp->abs0 + (tp->abs1 << 8) + (tp->abs2 << 16);
    	abm = tp->abm0 + (tp->abm1 << 8) + (tp->abm2 << 16);
        abs &= 0xfffff;
        wk1 = abs * (360.0 / 0x100000) ;

        ret.sprintf("ABS=%10d | 角度=%9.2f | ABM=%10d", abs, wk1, abm );

    }else{
        ret = "";
    }
    return ret;

}

///////////////////////////////////////////
//---------------------------------------------------------------------------
int __fastcall TForm2::VCPExam()
{
TnrComm *pComm[1] = {nrComm1};
int i;
String tmp;
unsigned char cmd;
	cmd = (unsigned char) StrToInt("0x"+ComboBox_cmd->Text);
    tmp.sprintf( "%c", cmd );
    RecvStreamData = new char[gSendStreamBurden];

	AddMemo("SEND : "+ ComboBox_cmd->Text );

    RecvPos = 0;

    QueryPerformanceCounter(&StartTime);
    pComm[0]->SendString( tmp );

    // 受信は nrCommAfterReceiv で行われるのでしばらく待つ
    for(int i=0; i< 2 ; i++){
    	Sleep( 100 );
   	 	Application->ProcessMessages();
    }

    tmp = convhex( RecvStreamData, RecvPos );   // HEX 変換
    AddMemo( "RCV  : " + tmp );
    if( (tmp = kaiseki( RecvStreamData, RecvPos )) != "" ){
    	AddMemo_kaiseki( tmp );
    }
	delete []RecvStreamData;

    return 0;

}
//---------------------------------------------------------------------------
void __fastcall TForm2::nrCommAfterReceive(TObject *Com, Pointer Buffer,
      DWORD Received)
{

    int RecvNum;
    char *pBuffer;

    RecvNum = (int)Received;
    pBuffer = (char*)Buffer;

    	//受信した数だけバッファに取込む
    for( ; RecvNum; RecvNum--)
    {
    	RecvStreamData[RecvPos] = *pBuffer;
        pBuffer++;				//Src位置のインクリメント
        RecvPos++;  			//Dest位置のインクリメント
    }

   	RecvStreamData[RecvPos] = 0;

}
//---------------------------------------------------------------------------
void __fastcall TForm2::Button_testClick(TObject *Sender)
{
	VCPExam();       // 上にある
}
//---------------------------------------------------------------------------
void __fastcall TForm2::nrDeviceBox1Change(TObject *Sender)
{
	unsigned short com;

	com = nrComm1->ComPortNo;

}
//---------------------------------------------------------------------------
void __fastcall TForm2::WMDeviceChange(TMessage &Msg)
{
	Memo->Lines->Add("@デバイスを登録中です..." + IntToStr(gDeviceChangeTimes++));

    if((gDeviceChangeTimes%6)==0)
    {
        nrComm1->WMDeviceChange(Msg);

    }

    ResetTimer(10);
}
//---------------------------------------------------------------------------
void __fastcall TForm2::ResetTimer(int value)
{
    gTimerInterval = value;
}
//---------------------------------------------------------------------------
void __fastcall TForm2::ReportComNames()
{
    int deviceCnt;
    String str;
    TnrDevice *p;

    deviceCnt = nrComm1->DeviceCount;

	Memo->Lines->Add("/*----- 現在認識中のポート-----*/");

    for(int i=0; i<devicecnt; nrcomm1-="" str="・">Device[i]->NameFriendly;
        Memo->Lines->Add(str);
    }

    Memo->Lines->Add("/*-----------------------------------*/");
}
//---------------------------------------------------------------------------
       
//---------------------------------------------------------------------------
void __fastcall TForm2::Button_com_closeClick(TObject *Sender)
{
	if(nrComm1->Active == TRUE) nrComm1->Active = FALSE;
    Button_test->Enabled = False;

}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
void __fastcall TForm2::AddMemo(String str)
{
	Memo->Lines->Add(str);
}
void __fastcall TForm2::AddMemo_kaiseki(String str)
{
	Memo_kaiseki->Lines->Add(str);
}

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


void __fastcall TForm2::All_Reset()
{

 if(nrComm1->Active == TRUE) nrComm1->Active = FALSE;


}
//---------------------------------------------------------------------------




void __fastcall TForm2::Timer_TimeoutTimer(TObject *Sender)
{
    if(gUartTimeoutCounter>0){
    	gUartTimeoutCounter--;
    }
}
//---------------------------------------------------------------------------




void __fastcall TForm2::CheckBox1Click(TObject *Sender)
{
	Timer1->Enabled = CheckBox1->Checked;
}
//---------------------------------------------------------------------------

void __fastcall TForm2::Timer1Timer(TObject *Sender)
{
static int cnt = 0;
	if( Button_test->Enabled ){
		Button_test->Click();
        cnt++;
        if( cnt > 1000 ){
        	CheckBox1->Checked = False;
            cnt = 0;
        }
    }
}
//---------------------------------------------------------------------------


[kw] 2012-03-07 USB-024 TEC-FA


[]