有懂vc的朋友吗 ,, 进来帮我看看(60分)

  • 主题发起人 主题发起人 980
  • 开始时间 开始时间
9

980

Unregistered / Unconfirmed
GUEST, unregistred user!
void CSendOutDlg::SendMsgToCom(BOOL bReSend)
{
KillTimeOutTimer();

if(!bReSend && m_nSendingMsgEnd > m_ctrlSubmitList.GetCount())
{
DispMessage("发送完毕");
m_ctrlSendButton.SetWindowText("返回");
m_bSending = FALSE;
SetTimer(TIMERID_FINISH,3000,NULL);
return;
}
if(!bReSend)
{
m_nSendingMsgBegin = m_nSendingMsgEnd;
m_nErrorSentCounter = 0;
}

char* p;
m_strUserNumber.Format("%04d",strtol(m_strUserNumber,&p,10));
m_strUserPassword.Format("%04d",strtol(m_strUserPassword,&p,10));

int buffer_idx;
int msg_fram_begin_idx;
BYTE msg_type;
m_SendOutBuffer[0] = OUTCMD_MAINPACK;
m_SendOutBuffer[2] = (BYTE)m_strServerNumber.GetLength();
memcpy(&m_SendOutBuffer[3],(LPCTSTR)m_strServerNumber,m_SendOutBuffer[2]);
buffer_idx = 3+m_SendOutBuffer[2];

msg_fram_begin_idx = buffer_idx;

m_SendOutBuffer[buffer_idx++] = OUTCMD_MSGPACK;
buffer_idx++;
memcpy(&m_SendOutBuffer[buffer_idx],(LPCTSTR)m_strUserNumber,4);
buffer_idx+=4;
memcpy(&m_SendOutBuffer[buffer_idx],(LPCTSTR)m_strUserPassword,4);
buffer_idx+=4;

m_nSendingMsgEnd = m_nSendingMsgBegin;

CString strMsg;
m_ctrlSubmitList.GetText(m_nSendingMsgEnd-1,strMsg);
msg_type = (BYTE)m_ctrlSubmitList.GetItemData(m_nSendingMsgEnd-1);

while(buffer_idx+strMsg.GetLength()<=254)
{
m_SendOutBuffer[buffer_idx++] = msg_type;
memcpy(&m_SendOutBuffer[buffer_idx],(LPCTSTR)strMsg,strMsg.GetLength());
buffer_idx+=strMsg.GetLength();
m_SendOutBuffer[buffer_idx++] = 0xFF;
m_nSendingMsgEnd++;
if(m_nSendingMsgEnd>m_ctrlSubmitList.GetCount())
break;
m_ctrlSubmitList.GetText(m_nSendingMsgEnd-1,strMsg);
msg_type = (BYTE)m_ctrlSubmitList.GetItemData(m_nSendingMsgEnd-1);
}

m_SendOutBuffer[1] = buffer_idx-1;
m_SendOutBuffer[msg_fram_begin_idx+1] = buffer_idx-msg_fram_begin_idx-2;

m_SendOutBuffer[buffer_idx] = CalChecksum(&m_SendOutBuffer[msg_fram_begin_idx],buffer_idx-msg_fram_begin_idx);
m_SendOutBuffer[buffer_idx+1] = CalChecksum(m_SendOutBuffer,buffer_idx+1);

if(m_nSendingMsgEnd==m_nSendingMsgBegin)
{
MyMessageBox(&quot;信息发送异常&quot;);
}
if(m_nSendingMsgEnd-m_nSendingMsgBegin>1)
strMsg.Format(&quot;正在发送第 %d 至 %d 条信息...&quot;,m_nSendingMsgBegin,m_nSendingMsgEnd-1);
else
strMsg.Format(&quot;正在发送第 %d 条信息...&quot;,m_nSendingMsgBegin);
DispMessage(strMsg);

BYTE tmpbuff[400];
tmpbuff[0] = 0x95;
tmpbuff[1] = 0x9a;
memcpy(tmpbuff+2,m_SendOutBuffer,buffer_idx+2);
gProcessor.WriteComData(tmpbuff,buffer_idx+4);
SetTimer(TIMERID_TIMEOUT,1000*TIMEOU_SECONDS,NULL);
}


其实减最主要的部分 这个功能是把数据 通过串口 发送出去的 写名他的格式就可以了 是怎么组成的就可以了 ,


下面是我的delphi 的代码 始终不真确,
procedure TForm1.Button4Click(Sender: TObject);
var
datclass:string;
datalength:integer;
phonelength:integer;
phone:string;
indataclass:string;
indatalength:integer;
usernumber,userpass:string;
indata:string;
addstr:string;
begin
datclass:='959A35';
datalength:=length(edit2.text)+length(edit1.text)+10+4;//12+4;
phonelength:=length(trim(Edit2.Text));
phone:=strtohex(trim(Edit2.Text));
indataclass:='87';
indatalength:=length(edit1.text)+10;//12;
usernumber:=strtohex(Edit3.text);
userpass:=strtohex(Edit4.text);
addstr:=datclass+inttohex(datalength,2)+inttohex(phonelength,2)+phone+indataclass+inttohex(indatalength,2)+usernumber+userpass+'01'+formatstrtohex(Edit1.text)+'FF';
showmessage(addstr);
memo2.text:= addstr;
SendHex(addstr); //十六进制发送 向串口发送数据

end;
 
建议你用SPCOMM控件来向串口发送数据。
至于发送什么格式,那就由你自己来定义了!
 
to fxh7622 哥们 你看明白我的话了吗 我不是用什么发送 是看不懂他的vc代码 不知道他最后发送的字符串是怎么组成的
 
vc发的是10禁止数字
 
to zj_mpy 你可以具体点吗 什么意思
 
多人接受答案了。
 
后退
顶部