How to Calculate CRC-16 (XModem)?

i don't have this externalModules directory ?!

image

You mentioned that you installed the module manually (from the console), so most likely you will find it inside "~/.node-red/node_modules". Probably the runtime is smart enough to know that the module already exists.

Okaaaaaay.... The engineering stick is at full reach and coming up a bit short....

I think I have the right section in settings.js, but am not too bright here... Which bits do I uncomment, without creating chaos?

    // Configure how the runtime will handle external npm modules.
    // This covers:
    //  - whether the editor will allow new node modules to be installed
    //  - whether nodes, such as the Function node are allowed to have their
    //    own dynamically configured dependencies.
    // The allow/denyList options can be used to limit what modules the runtime
    // will install/load. It can use '*' as a wildcard that matches anything.
    externalModules: {
        // autoInstall: false,   // Whether the runtime will attempt to automatically install missing modules
        // autoInstallRetry: 30, // Interval, in seconds, between reinstall attempts
        // palette: {              // Configuration for the Palette Manager
        //     allowInstall: true, // Enable the Palette Manager in the editor
        //     allowUpload: true,  // Allow module tgz files to be uploaded and installed
        //     allowList: [],
        //     denyList: []
        // },
        // modules: {              // Configuration for node-specified modules
        //     allowInstall: true,
        //     allowList: [],
        //     denyList: []
        // }

At an approximate guess, the last 5 lines maybe?

Regds
Ed

No.

Look for functionExternalModules & uncomment it. If not present, add it.

See here...
https://nodered.org/docs/user-guide/writing-functions#using-the-functionexternalmodules-option

1 Like

Sorted!! The external module section is now available!

Inserted the required bits under the section pertaining to the External Modules in settings.js and then in the individual node's module details, all is working like a charm!!

Big thanks to you and @Andrei and @Jean-Luc for all of the help to get this right!!

I actually don't know how to mark this as solved, as each and every comment and step has been invaluable to me, no single answer can be singled out as the solution!!

Thanks again guys, I REALLY appreciate the time and trouble you have taken to answer a newbies questions .... again!!

Regards
Ed

2 Likes

I think you are using @Andrei proposed solution, chose that one.

I will do so indeed!

@Steve-Mcl @Andrei @Jean-Luc

Thanks to all of your help, I have "Hybridised" it a bit and moved it to a subflow...

It seems to test out ok, next step will be to see if my inverter can understand my gibberish...
(But that will still take a while as I now need to incorporate it fully into a switchable enviro, so should I screw it up properly, hit the button and revert to current way of drawing data)..

@Jean-Luc : Here is my test flow with its subflow for the crc calculation and implementation that I will be going with... Hopefully you can find it handy, it should make life a little easier when working with the crc'd strings... I think I have been fairly thorough, but please forgive me if I have left anything out...

(Note: The CRC values are appended as ascii characters in their "raw" forms for visual verification - the pairs still have to be "consolidated" and converted to individual characters when sending to the inverter)

Regds
Ed
CRC16Xmodem Example and Subflow.json (14.6 KB)

Good job @eddee54455 !
However if you send the thong as is, in my opinion it will not work.
You must not forget the hex 0D at the end of each command.
On the other hand, the string must be sent as a buffer converted to hexadecimal so that the inverter can handle your request and answer you.
I have been using these functions for a long time and it works perfectly.
You also have to be careful to receive a response or an "ACK" - "NAK" before sending it a new command. So do a hand checking.
Enjoy !

Yeh, aware of that, agree 100%!

I was just "padding" the basic routine to make it more general purpose so I could use the one subflow for most of the things I have on plan... I haven't had a chance to switch it into my inverter yet, so still working "blind"... one thing I haven't looked at is the ACK/NAK response... is it a single char or a string that is returned... I seem to remember from my "working at Sperry/Burroughs" days that it was a single char... Dunno if the inverter is the same...

Regds

Ed

This is what works with my inverter. It is a string and not the character.
Here is my example:

image

[
    {
        "id": "32a7a866.ffcf98",
        "type": "serial in",
        "z": "8952ce3a.3e5f",
        "name": "Output de l'onduleur",
        "serial": "267673c4.e4afdc",
        "x": 110,
        "y": 105,
        "wires": [
            [
                "8d0e82b6.58bc8",
                "bb9b8363.c81d1",
                "ae01b0af.5ec85"
            ]
        ]
    },
    {
        "id": "ae01b0af.5ec85",
        "type": "switch",
        "z": "8952ce3a.3e5f",
        "name": "ACK9 ?",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "cont",
                "v": "ACK9",
                "vt": "str"
            },
            {
                "t": "else"
            }
        ],
        "checkall": "false",
        "repair": false,
        "outputs": 2,
        "x": 160,
        "y": 200,
        "wires": [
            [
                "3ce78a5a.a7f876",
                "bdade693.0a4828"
            ],
            [
                "aefa97c.0d30468"
            ]
        ]
    },
    {
        "id": "267673c4.e4afdc",
        "type": "serial-port",
        "serialport": "/dev/tty-onduleur",
        "serialbaud": "2400",
        "databits": "8",
        "parity": "none",
        "stopbits": "1",
        "waitfor": "",
        "dtr": "none",
        "rts": "none",
        "cts": "none",
        "dsr": "none",
        "newline": "\\r",
        "bin": "false",
        "out": "char",
        "addchar": "",
        "responsetimeout": "10000"
    }
]

Thanks JL!

I will look at it this evening when I get to the house!!

Much appreciated!!

Regds

Ed

Apologies Moderators - If you would like to move this from here on and start a new thread, please do...

Hi @Jean-Luc

Here is an "almost ready" to "live test" version of the CRC-16 incorporated comms subflow for my Axpert - I have added some code and tried to get it to as close to working as I can, without hooking it up to the inverter.

Would you be so kind as to look it over and see if I have missed anything?

I suspect that I will need to strip the last 3 characters from the inverter returned strings instead of the 2 that is currently handled in this version - The 3 characters being CRC1, CRC2, CR(0d) ... (This version only strips the last 2 characters, CRC1 and CRC2)

If I could be so bold as to ask you to perhaps send me a single line reply of your QPIGS query, I could verify and test further..

Regds
Ed

CRC16Xmod Axpert.json (20.2 KB)

1 Like

Hello @eddee54455
Here is below the answer from my inverter. iI is a string format.
For me your code will not work, because you have to send the QPIGS word in hexadecimal form, add the CRC and the x=0D at the end and send it to the serial port.

But why not connect your inverter now ? You don't risk much.
Do you have an RS232 or USB connection?

The answer from my inverter:

(237.1 49.9 229.6 49.9 0436 0336 008 434 52.00 000 078 0043 01.0 402.2 00.00 00000 00010110 00 00 00418 110&ļæ½

Hi @Jean-Luc

Thank you for the string, unfortunately my "validate routine" fails it.... I need to look a bit deeper..

I am hesitant to pull the inverter across to it as yet, I know there are still errors that need to be sorted, yes, I know, simple queries will not damage anything, but unfortunately the inverter is running pretty much as a hub in our nearly, very close, nearly, off-grid setup... As soon as I pull it out of the equation, all manner of appliances go into "fail safe" manual mode and they start chewing batteries or power...

No stress, Rome wasn't built in a day, I will take my time and eventually hook up my spare pi and inverter when the time gets closer to go to full live testing....

Currently the inverter is hooked to the pi via USB and the Pylon batteries are hooked to the same Pi via a USB to Serial adapter....

I will take another look at the code and start doing more "touch ups" ...

How are you transmitting/converting the commands to the inverter? Via a function node that does the hex conversion? Could you perhaps share it with me? I would love to take a look at it!

Regds
Ed

Here is another way to create CRC-16's, but without the npm package. I had to tweak the function node a little to work with our WiFi lights (LINK).

CRC Checksum
flows.json (5.0 KB)

2 Likes

thanks @awsteve ,

I will check it out... I have discovered some interesting things about my inverter.... Hmmmmm... Comms manuals aren't what they used to be!! (I have found a couple of missing "things" that should be there but are missing... Anybody have the "Latest" Voltronic Comms manual possibly?)

Regds
Ed

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