开云体育

ctrl + shift + ? for shortcuts
© 2025 Groups.io

How to add leading zeros to a number


 

I have made some great progress today with the Flex3000 flow. I solved the problem of the built-in TCP server in PowerSDR not accepting multiple connections, with a program I found called Com by TCP. I run it on the host PC that runs PSDR, and add that COM port as a CAT port in PSDR. It's working well, and I can "connect" payloads from different command buttons and switches, and it responds perfectly.

I hit a roadblock with sliders. The slider node outputs a number, but the command requires a 3-digit number, including leading zeros. I tried making a function node with? "msg.payload = parseInt(msg.payload (0,3))"? but that didn't work.?

I know it's just my ignorance in syntax. So......how to you add leading zeros to a payload that doesn't have them?

thanks,

Charlie KB8CR


 

开云体育

Function node

?

If (msg.payload <== 9) {

????????????? msg.payload = “00” + msg.payload;

} else if (msg.payload <== 99) {

????????????? Msg.payload = “0” + msg.payload;

}

Return msg;

?

If the number is between 0 and 9 it will add two zeroes to the front

If between 10 – 99 it adds one zero

If 100 + it passes msg.payload not changed.

?

Dave wo2x

?

?

From: [email protected] <[email protected]> On Behalf Of Charlie Rubenstein
Sent: Sunday, February 28, 2021 4:09 PM
To: [email protected]
Subject: [nodered-hamradio] How to add leading zeros to a number

?

I have made some great progress today with the Flex3000 flow. I solved the problem of the built-in TCP server in PowerSDR not accepting multiple connections, with a program I found called Com by TCP. I run it on the host PC that runs PSDR, and add that COM port as a CAT port in PSDR. It's working well, and I can "connect" payloads from different command buttons and switches, and it responds perfectly.

I hit a roadblock with sliders. The slider node outputs a number, but the command requires a 3-digit number, including leading zeros. I tried making a function node with? "msg.payload = parseInt(msg.payload (0,3))"? but that didn't work.?

I know it's just my ignorance in syntax. So......how to you add leading zeros to a payload that doesn't have them?

thanks,

Charlie KB8CR


 

It didn't like that......


 

开云体育

Try this

?

Only need <= and not <==

?

Heading out to dinner for my birthday.

?

73

Dave wo2x

?

?

From: [email protected] <[email protected]> On Behalf Of Charlie Rubenstein
Sent: Sunday, February 28, 2021 4:44 PM
To: [email protected]
Subject: Re: [nodered-hamradio] How to add leading zeros to a number

?

It didn't like that......


 

Charlie

Look at the "String" Node, "PadLeft" Method. ?You can specify the number of characters and what to use to "fill" the empty space. ?Here is an example with six digits, fill left with "0".

Alan


 

开云体育

Alan

The issue is he may need 0, 1, or two leading zeroes thus the if else statement is probably best solution.?

73
Dave


Sent from my waxed string and tin cans.?

On Feb 28, 2021, at 5:07 PM, Alan Blind, WA9WUD <a.alan.blind@...> wrote:

?Charlie

Look at the "String" Node, "PadLeft" Method. ?You can specify the number of characters and what to use to "fill" the empty space. ?Here is an example with six digits, fill left with "0".

Alan

<Screen Shot 2021-02-28 at 5.04.43 PM.png>


 

Understand, I think....

The string node, pad method will keep the number of characters the same and adjust with the "fill character" to adjust the empty space.? Here are two examples, 50, and 14074.? In each case, the total number of characters out remains as specified, six in this example.

Screen Shot 2021-02-28 at 5.15.39 PM.png

Alan

On Sun, Feb 28, 2021 at 5:09 PM David De Coons wo2x <RocketNJ@...> wrote:
Alan

The issue is he may need 0, 1, or two leading zeroes thus the if else statement is probably best solution.?

73
Dave


Sent from my waxed string and tin cans.?

On Feb 28, 2021, at 5:07 PM, Alan Blind, WA9WUD <a.alan.blind@...> wrote:

?Charlie

Look at the "String" Node, "PadLeft" Method.? You can specify the number of characters and what to use to "fill" the empty space.? Here is an example with six digits, fill left with "0".

Alan

<Screen Shot 2021-02-28 at 5.04.43 PM.png>


 

开云体育

Ok two ways to get it done :-)

Dave wo2x

Sent from my waxed string and tin cans.?

On Feb 28, 2021, at 5:18 PM, Alan Blind, WA9WUD <a.alan.blind@...> wrote:

?
Understand, I think....

The string node, pad method will keep the number of characters the same and adjust with the "fill character" to adjust the empty space.? Here are two examples, 50, and 14074.? In each case, the total number of characters out remains as specified, six in this example.

<Screen Shot 2021-02-28 at 5.15.39 PM.png>


Alan

On Sun, Feb 28, 2021 at 5:09 PM David De Coons wo2x <RocketNJ@...> wrote:
Alan

The issue is he may need 0, 1, or two leading zeroes thus the if else statement is probably best solution.?

73
Dave


Sent from my waxed string and tin cans.?

On Feb 28, 2021, at 5:07 PM, Alan Blind, WA9WUD <a.alan.blind@...> wrote:

?Charlie

Look at the "String" Node, "PadLeft" Method.? You can specify the number of characters and what to use to "fill" the empty space.? Here is an example with six digits, fill left with "0".

Alan

<Screen Shot 2021-02-28 at 5.04.43 PM.png>


 

Well, the Format node way, kept giving errors. But the edit string node worked. Now we have SLIDERS !!. I'll repost once I'm done adding sliders.

tnx,

73 de Charlie KB8CR?


 

First off.....HAPPY BIRTHDAY, DAVE !!

I made a lot of progress on the 3000's flow (gave me something to do on a rainy day in Cincy). I now have buttons for TUNE, MUTE, and VAC, and sliders for AF Gain, AGC-T, and Drive Level.? I added dropdown boxes for Mode and ACG selections. I learned the hard way to make sure to have feedback from the current settings, as the AF Gain slider otherwise starts at 100 !! ....All working well, except that the dropdown boxes, even with feedback from PSDR of the current settings, does not load those in the dropdown window. All it does is SEND whatever selection you pick. Might delete those.
Also wish the sliders allowed you to set the color of the sliders, they are dark blue, and don't show well on a dark theme.

Here's what it looks like now.......


73 de Charlie KB8CR


 
Edited

Oh no.....somebody stop me....hi hi....I found a way to import the panadapter to the dashboard !!




Wonder how much bandwidth that takes. But it's working pretty well. It's only display, not for input.

Charlie KB8CR


 

开云体育

Now THAT is cool!

:-)

Dave wo2x

Sent from my waxed string and tin cans.?

On Feb 28, 2021, at 8:32 PM, Charlie Rubenstein <charlier@...> wrote:

?

[Edited Message Follows]

Oh no.....somebody stop me....hi hi....I found a way to import the panadapter to the dashboard !!

<dummyfile.0.part>


Wonder how much bandwidth that takes. But it's working pretty well. It's only display, not for input.

Charlie KB8CR


 

开云体育

Can’t wait to see that flow. Would be cool to be able to do same for 6000 series. Would be a good step towards a full Linux client.?

Dave wo2x

Sent from my waxed string and tin cans.?

On Feb 28, 2021, at 8:38 PM, Charlie Rubenstein <charlier@...> wrote:

?

[Edited Message Follows]

Oh no.....somebody stop me....hi hi....I found a way to import the panadapter to the dashboard !!
<dummyfile.0.part>


<dummyfile.0.part>


Wonder how much bandwidth that takes. But it's working pretty well. It's only display, not for input.

Charlie KB8CR


 

I just uploaded v.0.31 to the files section (in my folder). Bear in mind that alot of the settings are custom to my setup. I have the lower group of commands going through a separate TCP to serial connection than the 'built-in' one that is in PSDR. I'm using a program called COMByTCP.....and it's working well.

73 de Charlie KB8CR


 

Very nice! I wish I had the skills to do that for the 6000 series...

--
Gary
K6HN


 

Gary,?

That's certainly not MY skill.....I just found that iframe node, and remembered that KE9NS had a web server in PowerSDR. I gave it a try. I just had to adjust a few things and it worked.

Charlie KB8CR


 

开云体育

// From StackExchange - Function to pad with leading zeros
function pad(n, width, z) {
? ? z = z || '0';
? ? n = n + '';
? ? return n.length >= width ? n : new Array(width - n.length + 1 ).join(z) + n;
}

Examples:
pad(10, 4);      // 0010
pad(9, 4);       // 0009
pad(123, 4);     // 0123

pad(10, 4, '-'); // --10

Regards Dwayne


 

I wonder if the web server was built in before the code was forked. I use a version for my anan-10e. Guess I’ll find out when I end my snow birding in May.

If anyone gets this going for the 6000 series please make a single flow snd post.

73, Marty wd9gym?



On Monday, March 1, 2021, 1:35 AM, Dwayne Sinclair AB6A via groups.io <Dwayne_sinclair@...> wrote:

// From StackExchange - Function to pad with leading zeros
function pad(n, width, z) {
? ? z = z || '0';
? ? n = n + '';
? ? return n.length >= width ? n : new Array(width - n.length + 1 ).join(z) + n;
}

Examples:
pad(10, 4);      // 0010
pad(9, 4);       // 0009
pad(123, 4);     // 0123

pad(10, 4, '-'); // --10

Regards Dwayne


 

It's nice to have that web server feature available. I keep hoping a skilled programmer will share code on how to create a panadapter client that can be served up in a webpage. I know it's been done, but the code is not opensource.

--
Gary
K6HN