LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Convert serial number to a 4 byte number to be written into FRAM

Good morning,

I have this code, but every 256 numbers the buffer is empty, so when it's written to memory, it's zero.

The remaining numbers do contain information.

What could be happening and how can I resolve the buffer not being emptied?

****************************************************

int main(int argc, char *argv[])
{
unsigned int ui;
unsigned char buf[256];


ui = (unsigned int) atoi ("80640");


buf[0] = ( (ui ) & 0xFF);
buf[1] = ( (ui >> 😎 & 0xFF);
buf[2] = ( (ui >> 16) & 0xFF);
buf[3] = ( (ui >> 24) & 0xFF);

****************************************************

Results in Number is 80640

buf[0] = ""
buf[1] = ""
buf[2] = ""
buf[3] = ""

 

Results in Number is 80641

buf[0] = "\1\5"
buf[1] = "\1;"
buf[2] = "\1;\1u\330Yp"
buf[3] = "\1;\1"

 

Message 1 of 3
(143 Views)

Hello VicTowers,

If I understand correctly, there's some more code missing here (such as print functions). At a first glance, I think there might be string and integer mismatching happening. I'm not yet proficient in C#, can you please verify if the mismatching is the issue? I think someone else may be more helpful if more context is added.

Messenger2

If someone's answer helped you find a solution or provided insight into an issue, the best way to show your appreciation and acknowledgement is by giving them a kudo or marking their reply as a solution.
0 Kudos
Message 2 of 3
(99 Views)

Hello Vic

 

In the debugger set break point after the assignment to buff[0..3] and view the buf variable in HEX bytes mode

CVI assumes that buf[256] is a string so the firs "char" buf[0] is 0x00 -> NULL in the case of "80640" than you can not see the rest 3 bytes

Message 3 of 3
(70 Views)