Dealing with Strings

Help creating logic scripts for Air Manager Instruments

Moderators: Ralph, russ

Post Reply
Message
Author
fatcharlieuk
Posts: 26
Joined: Tue Dec 22, 2020 7:42 am

Dealing with Strings

#1 Post by fatcharlieuk » Sat Feb 20, 2021 6:52 pm

Hi all,

I'm trying to extract Vspeed data from the IXEG 737-300/400

My code is:

Code: Select all

function two_R_callback(value)
print(value)
end

xpl_dataref_subscribe("ixeg/733/FMC/cdu1D_line2R_d", "STRING", two_R_callback)

Console gives:  �117> �117

This is trying to get the Vr data line.

it's the second value, the 117 after the ">", that i want to extract, convert to an integer and then use it to position a reference bug round the circumference of the ASi.

I have searched 'string', 'FMC' and 'CDU' here but nothing really relevant that i could find.

So what I need to do is get the last three characters from the string and convert it to a number.

Any help gratefully received :-)

Cheers,

Roger.

User avatar
Keith Baxter
Posts: 2801
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Dealing with Strings

#2 Post by Keith Baxter » Sat Feb 20, 2021 7:57 pm

Hi Roger

try
print(value[2])

The dataref should have the number of fields within the string/table.

What does the dataref look like in DatarefTool

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

fatcharlieuk
Posts: 26
Joined: Tue Dec 22, 2020 7:42 am

Re: Dealing with Strings

#3 Post by fatcharlieuk » Sat Feb 20, 2021 8:25 pm

Hi Keith,

Thanks for the quick reply - I'll have a look at that.

The Dataref Tool simply shows " " as the value, hence my assumption it's a string.

Out of curiosity i tried all the other data types and "BYTE" produced what looked suspicously like an ASCII code.

My code now loos lke this - gone off on a bit of a tangent, but it seems to work! There will doubless be a better and more efficient way of doing it...

Code: Select all

V1_image = img_add("V1_bug.png",0, 0, 600, 600) 
VR_image = img_add("VR_bug.png",0, 0, 600, 600)
V2_image = img_add("V2_bug.png",0, 0, 600, 600)  


function one_R_callback(value)
hundreds = (value[8] - 48) * 100
tens = (value[9] - 48) * 10
units = value[10] - 48
V1 = hundreds + tens + units
V1_angle = ((V1 - 58)/280) * 360
rotate(V1_image, V1_angle )
print("V1 is " .. V1)
end



function two_R_callback(value)
hundreds = (value[8] - 48) * 100
tens = (value[9] - 48) * 10
units = value[10] - 48
VR = hundreds + tens + units
VR_angle = ((VR - 58)/280) * 360
rotate(VR_image, VR_angle )
print("VR is " .. VR)
end

function three_R_callback(value)
hundreds = (value[8] - 48) * 100
tens = (value[9] - 48) * 10
units = value[10] - 48
V2 = hundreds + tens + units
V2_angle = ((V2 - 58)/280) * 360
rotate(V2_image, V2_angle )
print("V2 is " .. V2)
end


xpl_dataref_subscribe("ixeg/733/FMC/cdu1D_line1R_d", "BYTE[10]", one_R_callback)
xpl_dataref_subscribe("ixeg/733/FMC/cdu1D_line2R_d", "BYTE[10]", two_R_callback)
xpl_dataref_subscribe("ixeg/733/FMC/cdu1D_line3R_d", "BYTE[10]", three_R_callback)

User avatar
Keith Baxter
Posts: 2801
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Dealing with Strings

#4 Post by Keith Baxter » Sat Feb 20, 2021 8:55 pm

Roger

If it is bits and bytes you are dealing with I am very thin in that department.
Tony is the best help there.

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

JackZ
Posts: 1849
Joined: Mon Feb 22, 2016 1:02 pm

Re: Dealing with Strings

#5 Post by JackZ » Mon Feb 22, 2021 12:11 am

If you are trying to extract some characters from a string, then convert those to number, the Lua string library has everything you’ll need.
Namely string.sub(string,start,end) that will extract a substring from the original one starting and ending at a specific character.
http://lua-users.org/wiki/StringLibraryTutorial

Then tonumber(string) will convert the resulting substring to an integer (provided it’s a already a number representation of course). Can be a float or an integer.
Or you can use math.tointeger(string), provided that the string is already an integer representation.

So something like

Code: Select all

V1=tonumber(string.sub(value,7))
Should do the trick. 7 is for getting the last three characters
The ? Character is probably a color code of some sort for the line.

Jacques
My YouTube Chanel on the A320 (Real SOPs by an Airline Pilot IRL):
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ

fatcharlieuk
Posts: 26
Joined: Tue Dec 22, 2020 7:42 am

Re: Dealing with Strings

#6 Post by fatcharlieuk » Thu Feb 25, 2021 1:26 pm

Thanks for the help guys :-)

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests