日期:2014-05-17 浏览次数:20949 次
BOOL CDGX::WriteBfm( int nUnit, int addr, int nDevCnt, LPBYTE data )
{
BYTE buf[530];//最大524
LPBYTE p = &buf[4];
int i, n, byt;
while( nDevCnt > 0 )
{
if( m_nUartStopFlag != 0 )
return FALSE;
if( nDevCnt > 127 )
n = 127;
else
n = nDevCnt;
p[0] = 0xf1;
p[1] = ((nUnit<<4)&0xf0) | ((addr>>12)&0xf);
p[2] = (addr>>4)&0xff;
p[3] = (addr<<4)&0xf0;
p = &p[3];
byt = n*2;//字节数
*p++ |= (byt>>4 ) & 0xf;
*p = (byt<<4) & 0xf0;
//数据
for( i=0; i<byt; i++ )
{
int Q = *data++;
*p++ |= (Q>>4 ) & 0xf;
*p = (Q<<4) & 0xf0;
}
for( i = 0; i < MAX_UART_TRY; i++ )
{
SendReq( buf, n*4 + 9 );
if( WriteDevice_Ack() )
break;
if( m_nUartStopFlag != 0 )
return FALSE;
ReShakeHandle(1);
}
if( i == MAX_UART_TRY )
return FALSE;
nDevCnt -= n;
addr += byt;
data += byt;
}
return TRUE;
}
public unsafe bool WriteBfm(int nUnit, int addr, int nDevCnt, byte* data)
{
byte[] buf = new byte[530];
fixed (byte* pbuf = buf)
{
fixed (byte* p = &buf[4])
{
int i, n, byt;
while (nDevCnt > 0)
{
if (m_nUar