Advertisement
Guest User

Untitled

a guest
Apr 25th, 2014
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. 4918 22279 29342 3161 0 24953 29814 5319 1 0
  2. 4919 22279 29348 2997 1 24953 29838 5037 0 0
  3. 4920 22279 29357 2682 0 24953 29853 4544 0 0
  4.  
  5. function stack_stream(time)
  6. column_count = 10;
  7.  
  8. serial_object = create_serial_object;
  9. fopen(serial_object);
  10.  
  11. date_vector = clock;
  12. file_name = datestr(date_vector,30);
  13. file_name = [file_name '.txt'];
  14.  
  15. file_identifier = fopen(file_name,'w');
  16. tic;
  17.  
  18. while (toc < time)
  19. if (serial_object.UserData.is_new_data == true)
  20. raw_chunk = serial_object.UserData.data;
  21. serial_object.UserData.is_new_data = false;
  22.  
  23. data_chunk = sscanf(raw_chunk,'%d');
  24. data_chunk_length = length(data_chunk);
  25.  
  26. if (mod(data_chunk_length,column_count) == 0)
  27. data_column_count = data_chunk_length/column_count;
  28.  
  29. data = reshape(data_chunk,column_count,data_column_count);
  30.  
  31. fprintf(file_identifier,...
  32. '%6d %6d %6d %6d %6d %6d %6d %6d %6d %6drn',data);
  33. end
  34. end
  35. end
  36.  
  37. fclose(file_identifier);
  38. fclose(serial_object);
  39. delete(serial_object);
  40. end
  41.  
  42. function serial_object_callback(object,event)
  43. new_data = fscanf(object,'%c',object.BytesAvailable);
  44.  
  45. if (object.UserData.is_new_data == false)
  46. object.UserData.data = new_data;
  47. object.UserData.is_new_data = true;
  48. else
  49. object.UserData.data = [object.UserData.data new_data];
  50. end
  51. end
  52.  
  53. function serial_object = create_serial_object()
  54. serial_object = serial('COM2');
  55.  
  56. serial_object.BaudRate = 57600;
  57. serial_object.DataBits = 8;
  58. serial_object.FlowControl = 'none';
  59. serial_object.StopBits = 1;
  60.  
  61. serial_object.Terminator = 'CR/LF';
  62. serial_object.InputBufferSize = 2^18;
  63. serial_object.BytesAvailableFcnMode = 'terminator';
  64. serial_object.BytesAvailableFcn = {@serial_object_callback};
  65.  
  66. serial_object.UserData.data = [];
  67. serial_object.UserData.is_new_data = false;
  68. serial_object.UserData.response = [];
  69. serial_object.UserData.is_new_response = false;
  70. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement