# Issue with node-red-node-serialport and serial control Node: "TypeError: newline.substr is not a function" when Using Fixed Length Split Configuration

**URL:** <https://discourse.nodered.org/t/issue-with-node-red-node-serialport-and-serial-control-node-typeerror-newline-substr-is-not-a-function-when-using-fixed-length-split-configuration/88601>\
**Category:** General\
**Tags:** node-red-node-serialport\
**Created:** [10 June 2024 13:10 UTC](https://discourse.nodered.org/t/issue-with-node-red-node-serialport-and-serial-control-node-typeerror-newline-substr-is-not-a-function-when-using-fixed-length-split-configuration/88601 "2024-06-10T13:10:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![khalil\_khalil](https://avatars.discourse-cdn.com/v4/letter/k/ea666f/32.png) [@khalil\_khalil](https://discourse.nodered.org/u/khalil_khalil)\
**Post date:** [10 June 2024 13:10 UTC](https://discourse.nodered.org/t/issue-with-node-red-node-serialport-and-serial-control-node-typeerror-newline-substr-is-not-a-function-when-using-fixed-length-split-configuration/88601/1 "2024-06-10T13:10:17Z")

</div>

Hello,

I encountered an error with the `node-red-node-serialport` module while using the `serial control` node to open and close communication with a product. Here is my configuration and the steps I followed:

### Initial Configuration

I configured the COM port as shown in the image above with the following settings:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/e/eed9748205ae4b92976966f3721c80f11e6d772b.png)

- **Split input after a timeout of 200ms**

## Sequence

1. **Close COM port** (`close com` - works correctly)
2. **Open COM port** (`open com` - works correctly)
3. **Send serial commands** using the `serial request` node (`send serial commands` - works correctly)
4. **Close COM port** (`close com` - works correctly)
5. **Open COM port** (`open com` - works correctly)

### Problem with New Configuration

When I used the following configuration:

- **Split input into fixed lengths of 30000 chars**  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/0/70d899e1fe9683051631c3b3836923929ed5a54a.png)

and repeated the same steps, I encountered an error at step 5:

1. **Close COM port** (`close com` - works correctly)
2. **Open COM port** (`open com` - works correctly)
3. **Send serial commands** using the `serial request` node (`send serial commands` - works correctly)
4. **Close COM port** (`close com` - works correctly)
5. **Open COM port** (`open com` - error: "TypeError: newline.substr is not a function")

### Notes

- **Return type from the product** : The messages returned by the product are of the form `\n\rxxxxx ok xxxx \r\n`.

It seems that the "TypeError: newline.substr is not a function" error occurs when opening the COM port with the configuration set to split input into fixed lengths of 5000 characters. This likely indicates a problem with the handling of the `newline` variable in this configuration.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [10 June 2024 22:08 UTC](https://discourse.nodered.org/t/issue-with-node-red-node-serialport-and-serial-control-node-typeerror-newline-substr-is-not-a-function-when-using-fixed-length-split-configuration/88601/2 "2024-06-10T22:08:47Z")

</div>

Please raise an issue against this node in the node-red-nodes project and link to here. Thanks

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [8 September 2024 22:09 UTC](https://discourse.nodered.org/t/issue-with-node-red-node-serialport-and-serial-control-node-typeerror-newline-substr-is-not-a-function-when-using-fixed-length-split-configuration/88601/3 "2024-09-08T22:09:07Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
