@@ -33,8 +33,9 @@ export const parseSerialMessages = (
33
33
// so we need to discard it and start aggregating from the first encountered separator
34
34
let joinMessages = messages . join ( "" ) ;
35
35
if ( discardFirstLine ) {
36
+ separatorRegex . lastIndex = 0 ; // Reset lastIndex to ensure match happens from beginning of string
36
37
const separatorMatch = separatorRegex . exec ( joinMessages ) ;
37
- if ( separatorMatch && separatorMatch . index > - 1 ) {
38
+ if ( separatorMatch && separatorMatch . index > - 1 ) {
38
39
joinMessages = joinMessages . substring (
39
40
separatorMatch . index + separatorMatch [ 0 ] . length
40
41
) ;
@@ -54,6 +55,7 @@ export const parseSerialMessages = (
54
55
55
56
// remove the previous buffer
56
57
buffer = "" ;
58
+ separatorRegex . lastIndex = 0 ;
57
59
// check if the last message contains the delimiter, if not, it's an incomplete string that needs to be added to the buffer
58
60
if ( ! separatorRegex . test ( messagesAndBuffer [ messagesAndBuffer . length - 1 ] ) ) {
59
61
buffer = messagesAndBuffer [ messagesAndBuffer . length - 1 ] ;
@@ -64,11 +66,12 @@ export const parseSerialMessages = (
64
66
const parsedLines : { [ key : string ] : number } [ ] = [ ] ;
65
67
66
68
// for each line, explode variables
69
+ separatorRegex . lastIndex = 0 ;
67
70
messagesAndBuffer
68
- . filter ( ( message ) => ! separatorRegex . test ( message ) )
71
+ . filter ( ( message ) => ! separatorRegex . test ( message ) )
69
72
. forEach ( ( message ) => {
70
73
const parsedLine : { [ key : string ] : number } = { } ;
71
-
74
+
72
75
// Part Separator symbols i.e. Space, Tab & Comma are fully supported
73
76
// SerialPlotter protocol specifies 3 message formats. The following 2 formats are supported
74
77
// Value only format: <value1> <value2> <value3>
0 commit comments