LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

data packets

Solved!
Go to solution

Hi,

In my application, I am polling data from a stack on a module (COTS). And I am tring to create data pakets which contaain 100ms worth of data. Each packet should have a data header which contain data length (how much data in a packet). I am having difficulty creating packets.

right now I am reading the stack (which puts data in a structure) at the same time i am writing to the disk. In this method i can't calculate data lenght because i write the header first and then the data. Is there way i can accomplish this task? Is there way to buffer data for 100ms in some kind of buffer then calculate data length and then write the whole packet (header and data) to the disk? what i am trying to do is yo follow a standard called IRIG 106 Chapter 10. Any help will be greatly appreciated.

 

Thanks

0 Kudos
Message 1 of 6
(2,583 Views)

You could append incoming data to a string instead of writing it to a file; every 100 ms you can calculate string lenght and create your packet to write to disk. Beware that if your data are recorded in bynary format normal string operator like strlen or strcat / strcpy cannot be used as they would stop at the first nul byte found. You will need to use memcpy or similar operators and keep a separate lenght indicator calculated on your own based on the real amount of data transferred.

 



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 6
(2,579 Views)

Thanks for the reply Mr Bozzolo.

 

I have few questions. I am recording data in binary format therefore i have to use memcpy functions. Does this need strings.h header file? The data i am recording are integers ( members of a structure). In order for me use memcpy i have frist convert integers to strings and them use memcpy. and also i have couple of structures data types i am wiriting to the file as whole structure not as individual members. is there a way i can write these structure to a string as a whole not as a individual members?  

 

 

Thanks very much for all the help.

0 Kudos
Message 3 of 6
(2,557 Views)

You can append structure to the strings using memcpy provided you cast the structure to char * type: this is an example of how it works

typedef struct {
	int		a;
	int		b;
	int		c;
} myStruct;
static myStruct s;
static char	msg[512];
static int		z;

memset (msg, 0, 512);
strcpy (msg, "Test: ");
z = strlen (msg);
s.a = 3;
s.b = 123456;
s.c = -37599;

memcpy (msg + z, (char *)&s, sizeof (myStruct));
z += sizeof (myStruct);

 

 

Run the code in the interactive window and examine 'msg' variable after run: selecting Options >> Display entire buffer and Format >> Decimal in String display window you'll see the content of the string including the structure. Note that I'm keeping a separated variable 'z' with string lenght to avoid overwriting string content.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 6
(2,521 Views)

Hi Roberto,

Thanks for your reply. What you have posted helped me very much appending stuctures to a string.

In my application, i have few other variables to append  (integers and doubles) to string. I am having little trouble doing this. I get a compiler error message saying "too small of argument for one of the array pointers".

Could you please point me in the right direction?

This is what i have

 

chat packet[300];

int bytes=0;

double timestamp;

 

memcpy (packet+bytes, (char *) &timestamp, 😎

 

0 Kudos
Message 5 of 6
(2,494 Views)
Solution
Accepted by topic author suni

I cannot recognize the error message you posted and the snippet of code is conceptually ok: the problem may be related to the rest of the code you have not shown us. Can you also report the exact error message text?



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 6 of 6
(2,489 Views)