# First Node Project

**URL:** <https://discourse.nodered.org/t/first-node-project/20512>\
**Category:** General\
**Created:** [17 January 2020 18:04 UTC](https://discourse.nodered.org/t/first-node-project/20512 "2020-01-17T18:04:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![javants](https://avatars.discourse-cdn.com/v4/letter/j/ccd318/32.png) [@javants](https://discourse.nodered.org/u/javants)\
**Post date:** [17 January 2020 18:04 UTC](https://discourse.nodered.org/t/first-node-project/20512/1 "2020-01-17T18:04:10Z")

</div>

Hello all,  
I was curious to see if anyone has had experience using node-red with a BannerDXM 100. This is my first time using node-red and would like to potentially shift some projects over to it in the future. I have been using the node-red-contrib-modbus package. After playing with the nodes I for some reason can not read my holding registers correctly.

This is a link to the banner api documentation.

[http://info.bannerengineering.com/cs/groups/public/documents/literature/186221.pdf](http://info.bannerengineering.com/cs/groups/public/documents/literature/186221.pdf)

As of right now we use a simple visual basic program HMI to read registers over a tcp client.

Public Function Read\_Remote\_Registers(server As String, port As Int32, StartReg As Int16, RegCount As Int16, Slave\_ID As Int16) As ArrayList  
SyncLock SocketConnections  
Connect(server, port)  
Dim Read\_Remote\_Register\_Array As New ArrayList  
Read\_Remote\_Register\_Array.Clear()  
//Example use  
//Dim Register\_Array As ArrayList  
//Register\_Array = Read\_Registers(201, 2, 0)  
[//TextBox1.Text](https://TextBox1.Text) = Register\_Array(2)  
//This will read 2 registers starting at register 201 from the processing board slave ID = 0 and build an array  
//Next we return register 202 the second register from the array to a textbox

```
        //Begin connection and registry read
        //Server = Form_Connection_Settings.TextBox_IP_Address.Text
        //Port = Form_Connection_Settings.TextBox_Port.Text
        Try
            // Translate the passed message into ASCII and store it as a Byte array.
            //CMD0001 StartReg, RegCount, Slave ID (=0 for Processing Board, =200 for I/O Board), Modbus CMD, Timeout
            //RSP0001 StartReg, CSV Data 
            Dim data As [Byte]() = System.Text.Encoding.ASCII.GetBytes("CMD0003 " & StartReg & "," & RegCount & "," & Slave_ID & ",0,0")
           //Dim client As New TcpClient(Server, Port)
            client.SendTimeout = 1000
            client.ReceiveTimeout = 1000
            //Get a client stream for reading and writing.
            Dim stream As NetworkStream = client.GetStream()

           //Send the message to the connected TcpServer. 
            stream.Write(data, 0, data.Length)

            Dim bytes(client.ReceiveBufferSize) As Byte
            //Read can return anything from 0 to numBytesToRead. 
            //This method blocks until at least one byte is read.
            stream.Read(bytes, 0, CInt(client.ReceiveBufferSize))

            //Returns the data received from the host to the console.
            Dim returndata As String = Encoding.ASCII.GetString(bytes)

            //Convert to array
            Dim values As String = returndata
            Read_Remote_Register_Array.AddRange(values.Split(","))
            Read_Remote_Register_Array.RemoveAt(Read_Remote_Register_Array.Count - 1)
            Read_Remote_Register_Array(0) = Mid(returndata, 1, 7)

            Read_Remote_Registers = Read_Remote_Register_Array

            //Close everything.
            stream.Close()
            //client.Close()
        Catch
            Read_Remote_Registers = Read_Remote_Register_Array
            //Error Catch
        End Try
    End SyncLock
End Function

```

Im not experienced with nodejs so I have no idea how to convert that into javascript

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [17 January 2020 22:15 UTC](https://discourse.nodered.org/t/first-node-project/20512/2 "2020-01-17T22:15:55Z")

</div>

JS isn't so hard. A few pointers:

- `Dim someVarName As <type>` - JavaScript is typeless (mainly) you don't generally have to declare a variable as a particular type. Slight exception for Array's or Objects
- `Dim someVarName As <type>` =\> `var someVarName = 'stringvalue'` [1](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/var) (or [const](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const) or [let](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let))
- `Dim bytes(client.ReceiveBufferSize) As Byte` =\> That would be referred to as a `buffer` in JS. [1](https://nodejs.org/docs/latest-v12.x/api/buffer.html)
- `Try ...` =\> `try { .... } catch (err) { ... }` [1](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch), [2](https://nodejs.org/en/knowledge/errors/what-is-try-catch/)
- [Functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)
