Knowledge Base Nr: 00161 siemensconv.cpp - http://www.swe-kaiser.de
Downloads:
siemens datentypen nach intel konvertieren
float fData;
unsigned int nData;
...
case 'B': //BOOL
case 'C': //BYTE
nData = m_dbitem[nDBindex].m_dbdata[nDW];
if (nData&0x80) //negativ!
{
nData = - (128 - (nData&0x7f));
}
break;
case 'W': //WORD
nData = m_dbitem[nDBindex].m_dbdata[nDW];
nData = (nData<<8) & 0xff00;
nData |= m_dbitem[nDBindex].m_dbdata[nDW+1];
if (nData&0x8000) //negativ!
{
nData = - (32768 - (nData&0x7fff));
}
break;
case 'D': //DWORD
nData |= (((int)m_dbitem[nDBindex].m_dbdata[nDW+3]<<0) & 0x000000FF);
nData |= (((int)m_dbitem[nDBindex].m_dbdata[nDW+2]<<8) & 0x0000FF00);
nData |= (((int)m_dbitem[nDBindex].m_dbdata[nDW+1]<<16) & 0x00FF0000);
nData |= (((int)m_dbitem[nDBindex].m_dbdata[nDW+0]<<24) & 0xFF000000);
if (nData&0x80000000) //negativ!
{
nData = - (2147483648 - (nData&0x7fffffff));
}
break;
case 'R': //REAL
*nData |= (((int)m_dbitem[nDBindex].m_dbdata[nDW+3]<<0) & 0x000000FF);
*nData |= (((int)m_dbitem[nDBindex].m_dbdata[nDW+2]<<8) & 0x0000FF00);
*nData |= (((int)m_dbitem[nDBindex].m_dbdata[nDW+1]<<16) & 0x00FF0000);
*nData |= (((int)m_dbitem[nDBindex].m_dbdata[nDW+0]<<24) & 0xFF000000);
memcpy(fData, nData, 4);
break;
...