JAG Posted September 14, 2009 Author Posted September 14, 2009 Hi again, I tried with the code you posted with a Console project and it works but with an exception. At the begining I was using ip address assigned to my network card, and it doesn't work, then I change the ip address to "127.0.0.1" and it works, but it only shows the message "receiving from server..." and that is all, after the message no data is added to the console window. This are the lines I added to the export.lua, without the commented lines. function LuaExportStart() package.path = package.path..";.\\LuaSocket\\?.lua" package.cpath = package.cpath..";.\\LuaSocket\\?.dll" socket = require("socket") host = "127.0.0.1" port = 8080 c = socket.try(socket.connect(host, port)) -- connect to the listener socket c:setoption("tcp-nodelay",true) -- set immediate transmission mode end function LuaExportAfterNextFrame() local t = LoGetModelTime() local MainPanel = GetDevice(0) local slip = MainPanel:get_argument_value(108) local ias = MainPanel:get_argument_value(51) local mc = MainPanel:get_argument_value(44) local vsi = MainPanel:get_argument_value(24) local turn = MainPanel:get_argument_value(437) local aa = MainPanel:get_argument_value(438) local gmt = MainPanel:get_argument_value(440) local hoa = MainPanel:get_argument_value(439) local rst = MainPanel:get_argument_value(441) socket.try(c:send(string.format("t = %.2f, slip = %.2f, ias = %.2f, mc = %.2f, vsi = %.2f, turn = %.2f, aa = %.2f, gmt = %.2f, hoa = %.2f, rst = %.2f\n", t, slip, ias, mc, vsi, turn, aa, gmt, hoa, rst))) end function LuaExportStop() socket.try(c:send("quit")) -- to close the listener socket c:close() end I set the value in the Config.lua to true, It's there anything else to configure? Quick guide to configure ABRIS and LCD mini monitor Quick Countermeasure Editor v1.3.0 Core i5 3570K 4.0Ghz | GIGABYTE MOTHERBOARD | Crucial M4 120GB | 8GB DDR3 1600 MHZ | ASUS GTX 670 | AOC LED 23" | AOC LCD 24" | HYBRID DUAL THROTTLE (SAITEK THROTTLE QUADRANT + SUNCOM DUAL THROTTLE) | CH FIGHTERSTICK | SAITEK PRO PEDALS |
ruprecht Posted September 14, 2009 Posted September 14, 2009 Your Lua looks fine, I suspect if your client is throwing an exception that you should probably check that out :) Can you post your client code? I hate VB with a passion, but I'll have a look. Also note that my code was C# .Net, not VB! DCS Wishlist: | Navy F-14 | Navy F/A-18 | AH-6 | Navy A-6 | Official Navy A-4 | Carrier Ops | Dynamic Campaign | Marine AH-1 | Streaming DCS sometimes:
JAG Posted September 14, 2009 Author Posted September 14, 2009 (edited) The console is not throwing an exception, it's just the way I explained. JAjajajaja Why you hate VB, it's cool :lol: By the way it's VB, but the .Net version 2008 Here is the code, it's the same, just with the vb sintax ------------------------------------------------------ Imports System.Net.Sockets Imports System.IO Imports System.Net Module Module1 Sub Main() Dim reader As StreamReader Dim data As String Dim listener As TcpListener = New TcpListener(IPAddress.Any, 8080) listener.Start() Dim sock As Socket = listener.AcceptSocket() Dim serverstream As NetworkStream = New NetworkStream(sock) reader = New StreamReader(serverstream) While True Console.Write("receiving from server...") data = reader.ReadLine() Console.Write(data) End While End Sub End Module Edited September 14, 2009 by JAG Quick guide to configure ABRIS and LCD mini monitor Quick Countermeasure Editor v1.3.0 Core i5 3570K 4.0Ghz | GIGABYTE MOTHERBOARD | Crucial M4 120GB | 8GB DDR3 1600 MHZ | ASUS GTX 670 | AOC LED 23" | AOC LCD 24" | HYBRID DUAL THROTTLE (SAITEK THROTTLE QUADRANT + SUNCOM DUAL THROTTLE) | CH FIGHTERSTICK | SAITEK PRO PEDALS |
ruprecht Posted September 14, 2009 Posted September 14, 2009 Aaaagh my eyes! :) Dunno mate, it looks good to me. Maybe check out the TcpListener and Socket classes to see if there are any methods you can call to check that they're properly connected? Put a whole bunch of debug console writes in there and see. I suspect it's hanging on the data = reader.ReadLine() line, blocking for input, which means that the socket somehow hasn't connected? That's a guess though. Try specifying 127.0.0.1 instead of IPAddress.Any? DCS Wishlist: | Navy F-14 | Navy F/A-18 | AH-6 | Navy A-6 | Official Navy A-4 | Carrier Ops | Dynamic Campaign | Marine AH-1 | Streaming DCS sometimes:
JAG Posted September 14, 2009 Author Posted September 14, 2009 I will add a Try Catch just in case, by the way, I will try you code in C# and see what happend. It's funny because in the university I never liked C jajajajjaaja, but I have to program in it, I always tried, to program in VB since then. Un saludo :thumbup: Quick guide to configure ABRIS and LCD mini monitor Quick Countermeasure Editor v1.3.0 Core i5 3570K 4.0Ghz | GIGABYTE MOTHERBOARD | Crucial M4 120GB | 8GB DDR3 1600 MHZ | ASUS GTX 670 | AOC LED 23" | AOC LCD 24" | HYBRID DUAL THROTTLE (SAITEK THROTTLE QUADRANT + SUNCOM DUAL THROTTLE) | CH FIGHTERSTICK | SAITEK PRO PEDALS |
JAG Posted September 14, 2009 Author Posted September 14, 2009 The vb version finally works, at some point it start to show the info, but not at the begining of the mission, maybe a minute or more after and now it don't stop showing it. I finish the mission and the console windows don't stop. Looks like the while loop, never receive the false condition, it's supose when the mission finish the lua script close the TCP connection. With your code, it show you the values, as soon as the mission starts and stop showing it, when the mission is over? Quick guide to configure ABRIS and LCD mini monitor Quick Countermeasure Editor v1.3.0 Core i5 3570K 4.0Ghz | GIGABYTE MOTHERBOARD | Crucial M4 120GB | 8GB DDR3 1600 MHZ | ASUS GTX 670 | AOC LED 23" | AOC LCD 24" | HYBRID DUAL THROTTLE (SAITEK THROTTLE QUADRANT + SUNCOM DUAL THROTTLE) | CH FIGHTERSTICK | SAITEK PRO PEDALS |
PanelBuilder Posted September 14, 2009 Posted September 14, 2009 The vb version finally works, at some point it start to show the info, but not at the begining of the mission, maybe a minute or more after and now it don't stop showing it. I finish the mission and the console windows don't stop. Looks like the while loop, never receive the false condition, it's supose when the mission finish the lua script close the TCP connection. With your code, it show you the values, as soon as the mission starts and stop showing it, when the mission is over? I can see why it would keep running at the end: there's a lot of data in the pipe. I don't get the delay at the start though. Are you still using IPAddress.Any ? What does "t=" look like? Cheers, Colin
JAG Posted September 14, 2009 Author Posted September 14, 2009 (edited) Hi, I was using IpAddress the first time, then I change to IpAddress.Parse("127.0.0.1"), about that "t" it's one include in export.lua?, If that the case, the only t I found there is in the next function and it looks like this function LuaExportActivityNextEvent(t) local tNext = t -- Put your event code here and increase tNext for the next event -- so this function will be called automatically at your custom -- model times. -- If tNext == t then the activity will be terminated. -- For example: -- 1) File -- local o = LoGetWorldObjects() -- for k,v in pairs(o) do -- io.write(string.format("t = %.2f, ID = %d, name = %s, country = %s(%s), LatLongAlt = (%f, %f, %f), heading = %f\n", t, k, v.Name, v.Country, v.Coalition, v.LatLongAlt.Lat, v.LatLongAlt.Long, v.LatLongAlt.Alt, v.Heading)) -- end -- local trg = LoGetLockedTargetInformation() -- io.write(string.format("locked targets ,time = %.2f\n",t)) -- for i,cur in pairs(trg) do -- io.write(string.format("ID = %d, position = (%f,%f,%f) , V = (%f,%f,%f),flags = 0x%x\n",cur.ID,cur.position.p.x,cur.position.p.y,cur.position.p.z,cur.velocity.x,cur.velocity.y,cur.velocity.z,cur.flags)) -- end -- local route = LoGetRoute() -- io.write(string.format("t = %f\n",t)) -- if route then -- io.write(string.format("Goto_point :\n point_num = %d ,wpt_pos = (%f, %f ,%f) ,next %d\n",route.goto_point.this_point_num,route.goto_point.world_point.x,route.goto_point.world_point.y,route.goto_point.world_point.z,route.goto_point.next_point_num)) -- io.write(string.format("Route points:\n")) -- for num,wpt in pairs(route.route) do -- io.write(string.format("point_num = %d ,wpt_pos = (%f, %f ,%f) ,next %d\n",wpt.this_point_num,wpt.world_point.x,wpt.world_point.y,wpt.world_point.z,wpt.next_point_num)) -- end -- end -- local stations = LoGetPayloadInfo() -- if stations then -- io.write(string.format("Current = %d \n",stations.CurrentStation)) -- for i_st,st in pairs (stations.Stations) do -- local name = LoGetNameByType(st.weapon.level1,st.weapon.level2,st.weapon.level3,st.weapon.level4); -- if name then -- io.write(string.format("weapon = %s ,count = %d \n",name,st.count)) -- else -- io.write(string.format("weapon = {%d,%d,%d,%d} ,count = %d \n", st.weapon.level1,st.weapon.level2,st.weapon.level3,st.weapon.level4,st.count)) -- end -- end -- end -- local Nav = LoGetNavigationInfo() -- if Nav then -- io.write(string.format("%s ,%s ,ACS: %s\n",Nav.SystemMode.master,Nav.SystemMode.submode,Nav.ACS.mode)) -- io.write(string.format("Requirements :\n\t roll %d\n\t pitch %d\n\t speed %d\n",Nav.Requirements.roll,Nav.Requirements.pitch,Nav.Requirements.speed)) -- end -- tNext = tNext + 1.0 -- 2) Socket -- local o = LoGetWorldObjects() -- for k,v in pairs(o) do -- socket.try(c:send(string.format("t = %.2f, ID = %d, name = %s, country = %s(%s), LatLongAlt = (%f, %f, %f), heading = %f\n", t, k, v.Name, v.Country, v.Coalition, v.LatLongAlt.x, v.LatLongAlt.Long, v.LatLongAlt.Alt, v.Heading))) -- end -- tNext = tNext + 1.0 return tNext end Un saludo Update: I checked again the code, and I was wrong, it's no sending values at 1 or 2 minutes after the mission starts, if start to show the values, when the mission is over. Edited September 14, 2009 by JAG Quick guide to configure ABRIS and LCD mini monitor Quick Countermeasure Editor v1.3.0 Core i5 3570K 4.0Ghz | GIGABYTE MOTHERBOARD | Crucial M4 120GB | 8GB DDR3 1600 MHZ | ASUS GTX 670 | AOC LED 23" | AOC LCD 24" | HYBRID DUAL THROTTLE (SAITEK THROTTLE QUADRANT + SUNCOM DUAL THROTTLE) | CH FIGHTERSTICK | SAITEK PRO PEDALS |
PanelBuilder Posted September 14, 2009 Posted September 14, 2009 Hi, I was using IpAddress the first time, then I change to IpAddress.Parse("127.0.0.1"), about that "t" it's one include in export.lua?, If that the case, the only t I found there is in the next function and it looks like this /QUOTE] Sorry, I meant the "t" you're exporting: local t = LoGetModelTime() Cheers, Colin
JAG Posted September 14, 2009 Author Posted September 14, 2009 That "t" :thumbup: local t = LoGetModelTime() By the way I found another thing, it's not showing values, it only show the "receiving from server..." message, and repeat it again and again. Sorry if I don't checked it properly, but I was doing all this at 2am, and thinking more in sleep, than put attention to the console windows. Thanks :smilewink: Quick guide to configure ABRIS and LCD mini monitor Quick Countermeasure Editor v1.3.0 Core i5 3570K 4.0Ghz | GIGABYTE MOTHERBOARD | Crucial M4 120GB | 8GB DDR3 1600 MHZ | ASUS GTX 670 | AOC LED 23" | AOC LCD 24" | HYBRID DUAL THROTTLE (SAITEK THROTTLE QUADRANT + SUNCOM DUAL THROTTLE) | CH FIGHTERSTICK | SAITEK PRO PEDALS |
JAG Posted September 14, 2009 Author Posted September 14, 2009 (edited) Hi again, I tried with another code for TCPListener, and things are going different. The new code was made in a console project, and when it start it works this way. 1- Start the console project, and inmediately shows the message "Waiting for a connection..." 2- When the mission starts, it shows, "Waiting for a connection... Connected!" 3- During the mission no messages of cockpit values are added 4- Finish the mission and the next messages appear: Received: quit Sent: QUIT Waiting for a connection... Could the missing part, be in export.lua? After this I look into the error.log and at the end it shows many times the next line: Lua::Config::call error LuaExportAfterNextFrame:./Config/Export/Export.lua:73: attempt to call method 'get_argument_value' (a nil value) and the line 73 in the export.lua is: "local slip = MainPanel:get_argument_value(108 ) Now I have a doubt, all lines begining from 73 to n lines are wrong, or the script don't check the rest of the lines, and stop in the first wrong sentence it found? Un saludo Edited September 14, 2009 by JAG Quick guide to configure ABRIS and LCD mini monitor Quick Countermeasure Editor v1.3.0 Core i5 3570K 4.0Ghz | GIGABYTE MOTHERBOARD | Crucial M4 120GB | 8GB DDR3 1600 MHZ | ASUS GTX 670 | AOC LED 23" | AOC LCD 24" | HYBRID DUAL THROTTLE (SAITEK THROTTLE QUADRANT + SUNCOM DUAL THROTTLE) | CH FIGHTERSTICK | SAITEK PRO PEDALS |
JAG Posted September 15, 2009 Author Posted September 15, 2009 Finally the console windows, show info. With all the arguments listed before it doesn't work, then I test with only local t = LoGetModelTime(). It shows data, many times, but at some point like 3 or more minutes it suddenly stops and no info were added. Is that a failure in the communication with Lua or is the way that method works? But when I go back and try to add more values to show, it doesn't work. This is the last one I tried. local t = LoGetModelTime() local MainPanel = GetDevice(0) local lamp = MainPanel:get_argument_value(175) socket.try(c:send(string.format("t = %.2f, lamp = %.2f", t, lamp))) Cheers Quick guide to configure ABRIS and LCD mini monitor Quick Countermeasure Editor v1.3.0 Core i5 3570K 4.0Ghz | GIGABYTE MOTHERBOARD | Crucial M4 120GB | 8GB DDR3 1600 MHZ | ASUS GTX 670 | AOC LED 23" | AOC LCD 24" | HYBRID DUAL THROTTLE (SAITEK THROTTLE QUADRANT + SUNCOM DUAL THROTTLE) | CH FIGHTERSTICK | SAITEK PRO PEDALS |
ruprecht Posted September 15, 2009 Posted September 15, 2009 Are you using the 1.0.1 patch? If so, that's very weird. DCS Wishlist: | Navy F-14 | Navy F/A-18 | AH-6 | Navy A-6 | Official Navy A-4 | Carrier Ops | Dynamic Campaign | Marine AH-1 | Streaming DCS sometimes:
JAG Posted September 16, 2009 Author Posted September 16, 2009 Nop, I'm still using 1.0, there are changes between version 1.0 and 1.01 concerning lua? Quick guide to configure ABRIS and LCD mini monitor Quick Countermeasure Editor v1.3.0 Core i5 3570K 4.0Ghz | GIGABYTE MOTHERBOARD | Crucial M4 120GB | 8GB DDR3 1600 MHZ | ASUS GTX 670 | AOC LED 23" | AOC LCD 24" | HYBRID DUAL THROTTLE (SAITEK THROTTLE QUADRANT + SUNCOM DUAL THROTTLE) | CH FIGHTERSTICK | SAITEK PRO PEDALS |
ruprecht Posted September 16, 2009 Posted September 16, 2009 1.0.1 changed a lot of the exporting stuff Your GetDevice() code won't work on 1.0. LoGetModelTime() works because it is a 1.0 function that was preserved in 1.0.1, but most weren't. DCS Wishlist: | Navy F-14 | Navy F/A-18 | AH-6 | Navy A-6 | Official Navy A-4 | Carrier Ops | Dynamic Campaign | Marine AH-1 | Streaming DCS sometimes:
JAG Posted September 16, 2009 Author Posted September 16, 2009 Understood, I'll update to 1.0.1 and see what are the results. Thanks :thumbup: Quick guide to configure ABRIS and LCD mini monitor Quick Countermeasure Editor v1.3.0 Core i5 3570K 4.0Ghz | GIGABYTE MOTHERBOARD | Crucial M4 120GB | 8GB DDR3 1600 MHZ | ASUS GTX 670 | AOC LED 23" | AOC LCD 24" | HYBRID DUAL THROTTLE (SAITEK THROTTLE QUADRANT + SUNCOM DUAL THROTTLE) | CH FIGHTERSTICK | SAITEK PRO PEDALS |
stelios2000 Posted September 16, 2009 Posted September 16, 2009 please write us the link to update it also. thanks
JAG Posted September 16, 2009 Author Posted September 16, 2009 This is the link to the latest patch released the 1.0.1 http://www.digitalcombatsimulator.com/index.php?end_pos=2364&scr=products&lang=en Saludos Quick guide to configure ABRIS and LCD mini monitor Quick Countermeasure Editor v1.3.0 Core i5 3570K 4.0Ghz | GIGABYTE MOTHERBOARD | Crucial M4 120GB | 8GB DDR3 1600 MHZ | ASUS GTX 670 | AOC LED 23" | AOC LCD 24" | HYBRID DUAL THROTTLE (SAITEK THROTTLE QUADRANT + SUNCOM DUAL THROTTLE) | CH FIGHTERSTICK | SAITEK PRO PEDALS |
JAG Posted September 17, 2009 Author Posted September 17, 2009 It's working, it's working :thumbup: I've playing with the instant action mission for a while, flying around, keep flying around and even let the AI shootdown me a few times (but just for testing purposes:megalol:) and the game don't freeze, and the info don't stop. Ruprecht you were right, the problem was I was using updated methods for 1.0.1. Before updating, I decide to try with the previous methods to see if it works, and it did. Thank you very much for all your help guys. Now I can continue working on my project. When it's ready I'll show you it. Saludos (Cheers) Quick guide to configure ABRIS and LCD mini monitor Quick Countermeasure Editor v1.3.0 Core i5 3570K 4.0Ghz | GIGABYTE MOTHERBOARD | Crucial M4 120GB | 8GB DDR3 1600 MHZ | ASUS GTX 670 | AOC LED 23" | AOC LCD 24" | HYBRID DUAL THROTTLE (SAITEK THROTTLE QUADRANT + SUNCOM DUAL THROTTLE) | CH FIGHTERSTICK | SAITEK PRO PEDALS |
sweinhart3 Posted September 18, 2009 Posted September 18, 2009 Is there somewhere I can find out how to program LUA scripts cause outside of visual C++ I dont understand the other programming languages and how to interact with the data. Intel i7 990X, 6GB DDR3, Nvidia GTX 470 x2 SLI, Win 7 x64 http://picasaweb.google.com/sweinhart
sweinhart3 Posted September 18, 2009 Posted September 18, 2009 wow excellent. thnx. another book to pile away in the old registry. maybe itll make sense aftwerward Intel i7 990X, 6GB DDR3, Nvidia GTX 470 x2 SLI, Win 7 x64 http://picasaweb.google.com/sweinhart
stelios2000 Posted October 11, 2009 Posted October 11, 2009 (edited) Ok guys... it is time for me to give a try what i have read.... I am little confused so forgive me in advance. Lets say that i want to make work these two switches 1 & 2. http://img25.imageshack.us/img25/4158/43040539.jpg http://img98.imageshack.us/img98/4007/98465960.jpg I deliberately chose them to be in different panels. I have connected the Opencockpit Usb Key card (88 keys) http://www.opencockpits.com/catalog/usbkeys-card-p-53.html?cPath=21_35 I run IOCKeys program and i saw the Devide Number (2276). I then change/update the IOCKey.ini file with the correct Device Number. I connected at the 35/1 card pins the first On/Off switch and at the 35/8 card pins the second On/Off switch. I run the Opencockpits Sioc program and i am getting these two windows http://img99.imageshack.us/img99/4578/32714847.jpg I then go to Config/Export/Config.lua file and set EnableExportScript = true From here....i am a little confused. Where do i have to place the code for these two switches.... at the Config/Export/Config.lua file ???? Where exactly? And Can someone please write me the code for these JUST two switches? and some help for every code line please? thanks in advance stelios Ps I have only one PC (for Localhost), I have ALL the opencockpit cards (in case you tell me to use the master card) and i have the latest patch released 1.0.1 Edited October 11, 2009 by stelios2000
Gadroc Posted October 11, 2009 Posted October 11, 2009 Hey Stelios, You should look at Oakes Import/Export scripts they already interface with SIOC. http://forums.eagle.ru/showthread.php?t=45377 His code is not necessarily a simple example but it's designed to handle many switches. Basic overview of the tasks it does. 1 - Startup 1a) Connect via TCP to SIOC 1b) Send command to tell SIOC which switches to keep it informed of status. In Oakes examples he creates an array (inputsTable) which contains all the switches and their config. He loops through this array and sends all of the switch id's to SIOC. 2 - Before Frame 2a) Read input from SIOC 2b) Parse input to get the state of switchs 2c) Execute the appropriate command for switch In particular the switches you asked about are two position switches. You can find the info you need about them in clickabledata.lua. Here are the two appropriate bits for the fuel meter switch. I'll let you figure out the other one. elements["FUEL-METER-PTR"] = device = devices.FUELSYS_INTERFACE, action = {device_commands.Button_5,device_commands.Button_5}, arg_value = {-direction*1.0,direction*1.0}, arg_lim = {{0, 1},{0,1}} The device is device id you need to get to execute the switches. You look in devices.lua to find the number for that. In this case it's 3. The action tells you which button on the device to trigger in the format of {left button click, right button click} there are some cases where different things happen for right and left click. You need to ad 3000 to this number. In this case that would be 3005. The arg_value and arg_lim tell you what the on off state values are. arg_value is the change in value that happens on click. arg_lim are the max and min values. For a two position switch you set min value (0 in this case) for off and max value for on (1). So when SIOC indicates the swtich is on you need to do the following in lua GetDevice(3):performClickableAction(3005, 1.0) and when SIOC indicates the switch is off GetDevice(3):performClickableAction(3005, 0.0) 3 - After Frame 3a) Gather data about indicator lamps and led displays 3b) Send commands to SIOC to toggle lamps on and off Hopefully that helps explain the examples that are already there.
stelios2000 Posted October 11, 2009 Posted October 11, 2009 Hey Stelios, You should look at Oakes Import/Export scripts they already interface with SIOC. http://forums.eagle.ru/showthread.php?t=45377 You can find the info you need about them in clickabledata.lua. Here are the two appropriate bits for the fuel meter switch. I'll let you figure out the other one. elements["FUEL-METER-PTR"] = device = devices.FUELSYS_INTERFACE, action = {device_commands.Button_5,device_commands.Button_5}, arg_value = {-direction*1.0,direction*1.0}, arg_lim = {{0, 1},{0,1}} The device is device id you need to get to execute the switches. You look in devices.lua to find the number for that. In this case it's 3. The action tells you which button on the device to trigger in the format of {left button click, right button click} there are some cases where different things happen for right and left click. You need to ad 3000 to this number. In this case that would be 3005. The arg_value and arg_lim tell you what the on off state values are. arg_value is the change in value that happens on click. arg_lim are the max and min values. For a two position switch you set min value (0 in this case) for off and max value for on (1). So when SIOC indicates the swtich is on you need to do the following in lua GetDevice(3):performClickableAction(3005, 1.0)and when SIOC indicates the switch is off GetDevice(3):performClickableAction(3005, 0.0)Hopefully that helps explain the examples that are already there. My dear Gadroc, Many things became more clearer after your reply.... I have some questions though: Firtst where do you write these code lines. I mean in which file. Second where inside the file? At the begining/middle/end ? Can i just make a file for only this (1st) switch and test it ? I have saw the Oakes files and they are pretty nice.It was hard for me to understand till now (without your help) I am looking forward for your help again Ps All the other stuff i did it(in my previous post) is it right? I mean do i have to run these 2 programms ? And if i have 2 or more USB key cards connected to my PC how different would be then the script ? thanks again stelios
Recommended Posts