Question : C++ Serial Communication - LSB & MSB

Hi,
    I am writing some code for communicating to an digital imager via serial port, using C++ and I have some questions regarding data structure.  

According to the ICD, the communication structure, I need to transmit 4 bytes of data to the device (I have attached a file outlining the parts of the ICD).  I am a little confused on how to prepare the data structure, especially dealing with the MSB & LSB (see attached document).  

I have some pseudo-code below, please tell me if I am going in the right direction;

Again, please see the attached document in-reference with the pseudo-code

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:

//Sample for FOV command (see attached document)

char m_TxBuf[4];
TxBuf[0] = 0x03; (Call Word - see icd, contains address and command MSB)
TxBuf[1] = 0x10; //Byte 0 (Command LSB)
TxBuf[2] = 0x02; //Byte 1 (Data LSB)
TxBuf[3] = 0x00; //Byte 2 (Data MSB)
TxBuf[4] = TxBuf[0] + TxBuf[1] + TxBuf[2] + TxBuf[3];  //Byte 4 (Checksum)


If you could please let me know if I am preparing my data structure properly according to the ICD, and help me out that would be appreciated.  

Thanks
Attachments:
 
Communication Structure
 

Answer : C++ Serial Communication - LSB & MSB

Well, yes, I only put a light on the Byte 0 since I didn't see anything problematic in the other bytes. The other bytes IMO are trivial to handle and I guess the code you gave is ok (I say 'guess' since I have no idea what values you have to put in there since I have no knowledge about the device and its communication protocol).

I don't know what's the association between FOV and MSB/LSB - if FOV commands are sent via the LSB bytes then byte 1 and 2 IMO should look somehow like this:

> m_TxBuf[1] = 0x10; // command 'FOV'
> m_TxBuf[2] = 0x02; // data 'wide'
or
> m_TxBuf[1] = 0x1c; // command 'CCD electronic zoom'
> m_TxBuf[2] = 0x01; // data 'narrow ccd  - zoom *2 active'

'About the 4th byte (m_TxBuf[3]) I have absoluteley no idea what you have to put in there.
Random Solutions  
 
programming4us programming4us