S
S
Slavka2016-02-01 22:46:37
C++ / C#
Slavka, 2016-02-01 22:46:37

What is the difference between C and C++ memory handling?

In general, communication takes place between the PC and the Microcontroller, on both devices the structure is defined

struct typeDateTimeSend{
  
  int hh;
  int mm;
  int ss;
  int dm;
  int mh;
  int yy;
  
};

I do this trick on PC
unsigned char *pdata = (unsigned char *)&dateTime //struct typeDateTimeSend{ ;

I send data to the microcontroller, on it I do the trick back
DateTime = *((struct typeDateTimeSend*)&OutReport[1]);  // [0] занят под номер команды

In fact, if I send the number 23 (for example, as a clock), then it sends 0x17 0x00 0x00 0x00 right there on the PC, I collected the request back and everything is fine, but for some reason the opposite happens on the controller, it starts not from left to right, but from right to left c9cb6cbc1a184987a812decde91cb4a4.PNG3a2d8e99323144219be37a9ad5c14394.PNG
How correct this state of affairs?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
abcd0x00, 2016-02-02
@abcd0x00

Read about serialization. Here, according to the same principle, you need to convert the structure into an unambiguous byte stream, transfer it, and then convert the byte stream back into a structure. So your structures can be arranged differently, but at the same time they will be filled in the same way.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question