Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 4918 22279 29342 3161 0 24953 29814 5319 1 0
- 4919 22279 29348 2997 1 24953 29838 5037 0 0
- 4920 22279 29357 2682 0 24953 29853 4544 0 0
- function stack_stream(time)
- column_count = 10;
- serial_object = create_serial_object;
- fopen(serial_object);
- date_vector = clock;
- file_name = datestr(date_vector,30);
- file_name = [file_name '.txt'];
- file_identifier = fopen(file_name,'w');
- tic;
- while (toc < time)
- if (serial_object.UserData.is_new_data == true)
- raw_chunk = serial_object.UserData.data;
- serial_object.UserData.is_new_data = false;
- data_chunk = sscanf(raw_chunk,'%d');
- data_chunk_length = length(data_chunk);
- if (mod(data_chunk_length,column_count) == 0)
- data_column_count = data_chunk_length/column_count;
- data = reshape(data_chunk,column_count,data_column_count);
- fprintf(file_identifier,...
- '%6d %6d %6d %6d %6d %6d %6d %6d %6d %6drn',data);
- end
- end
- end
- fclose(file_identifier);
- fclose(serial_object);
- delete(serial_object);
- end
- function serial_object_callback(object,event)
- new_data = fscanf(object,'%c',object.BytesAvailable);
- if (object.UserData.is_new_data == false)
- object.UserData.data = new_data;
- object.UserData.is_new_data = true;
- else
- object.UserData.data = [object.UserData.data new_data];
- end
- end
- function serial_object = create_serial_object()
- serial_object = serial('COM2');
- serial_object.BaudRate = 57600;
- serial_object.DataBits = 8;
- serial_object.FlowControl = 'none';
- serial_object.StopBits = 1;
- serial_object.Terminator = 'CR/LF';
- serial_object.InputBufferSize = 2^18;
- serial_object.BytesAvailableFcnMode = 'terminator';
- serial_object.BytesAvailableFcn = {@serial_object_callback};
- serial_object.UserData.data = [];
- serial_object.UserData.is_new_data = false;
- serial_object.UserData.response = [];
- serial_object.UserData.is_new_response = false;
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement