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("信息发送异常"
}
if(m_nSendingMsgEnd-m_nSendingMsgBegin>1)
strMsg.Format("正在发送第 %d 至 %d 条信息...",m_nSendingMsgBegin,m_nSendingMsgEnd-1);
else
strMsg.Format("正在发送第 %d 条信息...",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;
{
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("信息发送异常"
}
if(m_nSendingMsgEnd-m_nSendingMsgBegin>1)
strMsg.Format("正在发送第 %d 至 %d 条信息...",m_nSendingMsgBegin,m_nSendingMsgEnd-1);
else
strMsg.Format("正在发送第 %d 条信息...",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;