Function JudgeHex(str_Data:string):Integer;
    /////////////////////////////////////////
    //功能   : 判断一个字符串是否为HEX字符串
    //参数   : str_Data 要判断的字符串
    //返回值 : 1 是HEX字符串
    //        -1 不是HEX字符串
    /////////////////////////////////////////
    Var
      i:integer;
    Begin
      Result:=-1;
      If Length(str_Data)=0 Then
        Exit;
      str_Data:=UpperCase(str_Data);
      For i:=1 To Length(str_Data) Do
        If (Not(Ord(str_Data[i]) In [48..57]))And(Not(Ord(str_Data[i]) In [65..70])) Then
          Exit;
      Result:=1
    End;

解决方案 »

  1.   

    再补充一段,比较急,谢谢
    var
          i_StrLen,i:Integer;
          Counter:Cardinal;
          BytToSend:Byte;
    begin     
     i_StrLen:=Length(str_Data) Div 2;
          //发送数据
          For i:=1 To i_StrLen Do
            Begin
              BytToSend:=Byte(StrToInt('$'+Copy(str_Data,(i-1)*2+1,2)));
              Counter:=0;
              If WriteFile(GetCommHandle(),BytToSend,1,Counter,Nil)=False Then
                Begin
                  MessageBox(Application.Handle,'向串口发送数据失败!','错误信息',MB_OK+MB_ICONSTOP);
                  Exit
                End;
            End;
      

  2.   

    int i;
    int Result = -1;  //?
    CString str_Data ; //?
    if (str_Data.GetLength() == 0)
       return; //or break;  //?
    str_Data.MakeUpper();
    for (i = 0; i < str_Data.GetLength(); i++)
    {
      if (!((str_Data.GetAt(i) >= 48 && str_Data.GetAt(i) <= 57) 
      && ((str_Data.GetAt(i) >= 65 && str_Data.GetAt(i) <= 70))))
    return;
      Result = 1;
    }
    ------------------------
    判断一个字符串是否是16进制形式?
      

  3.   

    #include "string.h"
    #include "stdlib.h"int JudgeHex(char *str_Data)
    {
    int len = strlen(str_Data);
    char c; for(int i=0; i<len; i++)
    {
    c = toupper(str_Data[i]); if(c>= '0' && c<='9') 
    {
    continue;
    } if(c>='A' && c<='F')
    {
    continue;
    } return -1;
    } return 1;
    }
      

  4.   

    GetCommHandle(),在VC中要用CreateFile()得到。
      

  5.   

    在delphi中,Function 是返回值的
    procedure 没有返回值
    begin
    .....
    end
    为代码段标记delphi和c++相似性很大的
      

  6.   

    不能简单翻译你那个串口程序的.
    打开串口,配置串口参数的部分也要实现.
    If WriteFile(GetCommHandle(),BytToSend,1,Counter,Nil)=False Then
    中的GetCommHandle()是用CreateFile打开串口返回的句柄.
    翻译你那段通讯程序,涉及到打开串口,配置参数等问题,用到以下API函数,自己查查吧.
    CreateFile 打开串口
    SetupComm
    SetCommState
    PurgeComm
    SetCommTimeouts
      

  7.   

    那些API函数我已经在这段程序之前写好了,就是这句话不知道用C语言怎么写,帮我翻译下这句就可以了,谢谢!
    BytToSend:=Byte(StrToInt('$'+Copy(str_Data,(i-1)*2+1,2)));
      

  8.   

    int i_StrLen;
    int i;
    BYTE ByteToSend;
    DWORD Counter = 0;
    BOOL bWriteStat = FALSE;
    char temp[3] = {0};i_StrLen = strlen(str_Data) / 2;
    for(i=0; i<i_StrLen; i++)
    {
    temp[0] = str_Data[i*2];
    temp[1] = str_Data[i*2+1];
    ByteToSend = atoi(temp); //如果转BCD码就自己转
    bWriteStat = WriteFile(m_hComm,  //串口句柄
    ByteToSend, 
    1,
    &Counter,
    NULL); 
    if(!bWriteStat)
    {
          AfxMessageBox("向串口发送数据失败!");
    }}