Page 1 of 1

aliasing word variables in reverse order?

Posted: Thu Nov 24, 2022 11:11 am
by Gunplumber
Hi Guys

I have question regarding aliasing word variables and the order of the bytes as they are stored..
I have an byte array that stores incoming serial data. The data is comprised of 16 bit words, but are sent MSB first then LSB. I am trying to alias the array to several word variables using the following code..

Code: Select all

Dim Array(10) as byte

Dim Word_var_1 as Array(0).Asword
Dim Word_var2 as Array(2).Asword
etc
However because the bytes are sent MSB-LSB, they are stored in the wrong order for the Aliasing (LSB then MSB) and any reference to my word variable is incorrect.

My first thought was just swapping the bytes as they are read and stored in the array, but i need the array in the order it was transmitted so i can preform a CRC check on the data. If i swap them, the CRC will never match and each packet will be rejected..

Other than going back through and swapping each pair using a separate routine is there any other way of doing it?

Cheers
Lee

Re: aliasing word variables in reverse order?

Posted: Thu Nov 24, 2022 1:50 pm
by Jerry Messina
There's no way to get it to directly swap the byte order of the alias. You could use a function to read/write the bytes in swapped order for you, but that's not quite the same thing.

I think you're stuck doing it in code.