Read UART - Strings : Basic usage

As a non-programmer, I’m struggling to find documentation for some basic concepts in Squirrel.

I’m trying to configure imp to receive a multi-digit integer over UART. I can receive single bytes very easily, but do not know the syntax to assemble them into a string. If someone could provide an example I would be very grateful!

For example, The following code reads sequential bytes out of the uart buffer and sends them to the output.

function pollUart()
{
imp.wakeup(0.000001, pollUart.bindenv(this));
local byte = hardware.uart57.read();
while (byte != -1)
{
server.log(format("%c", byte));
impeeOutput.set(byte);
byte = hardware.uart57.read();

}

}

Using C++, you could use something like the below to write sequential bytes from the buffer into “string”, for example, assembling ‘2’,‘1’,‘4’ into ‘214’ by incrementing the index of a variable, and writing a byte to each position, one at a time.

int numChar = Uart.available();
while (numChar–){
string[index++] = Uart.read(); //increment index of ‘string’, writing one byte at a time from the uart buffer
}

How could I accomplish a similar thing in squirrel? For the life of me I can’t seem to find an example that does something like this.

Thanks in advance!

Reading Bytes into a string:

For anyone reading bytes from the serial port and chaining them into validated strings, the following works brilliantly. It’s based on the sparkfun example and this.

`function pollUart()
{
imp.wakeup(1, pollUart.bindenv(this));
local s = “”;
local byte = hardware.uart57.read();
while (byte != -1)
{
s+=byte.tochar();
byte = hardware.uart57.read();

    }
if (s.len() > 3) // replace with whatever validation you are using
    {  
    impeeOutput.set(s);  
    }   

}`