
FSEPIC
Members-
Posts
15 -
Joined
-
Last visited
-
Days Won
1
FSEPIC last won the day on September 21 2020
FSEPIC had the most liked content!
FSEPIC's Achievements
Newbie (1/14)
1
Reputation
-
Hi , on 1 : went on bike trip , because it was driving me nuts . On the way home i came to the same conclusion, because the console .log did not show up on 2. i now start from: node "anyjsfile".js , and start the index.html from chrome or the live server in VS Code, and the url is : http://127.0.0.1:5500/index.html . I get connection now , but now my code is a bit messy imho ; -) A: I can NOT find a way to start the code in the connection function . From : https://dmitripavlutin.com/6-ways-to-declare-javascript-functions/#6-one-more-thing-new-function , i understand this is 1 of 6 ways to declare a function in JS. So i defined a "standard" function in test.js and just added a few lines: // test.js function myfunction() { var ws = null; ws = new WebSocket('ws://localhost:2048/fsuipc/', "fsuipc"); openConnection(); ----------------------- this.start = function () { }; this.stop = function () { if (ws) { ws.close(); } }; var clearMessages = function () { document.getElementById("connectionStatus").innerText = ""; document.getElementById("connectionError").innerText = ""; }; this.openConnection = function () { if (!ws) { clearMessages(); // Create a new WebSocket. // The server url is from the text box on the form //var serverURL = document.getElementById("serverURL").value; ws = new WebSocket('ws://localhost:2048/fsuipc/', "fsuipc"); // Handle the onopen event ws.onopen = function () { console.log("open"); document.getElementById("connectionStatus").innerText = "Connection Open"; }; // Handle the onclose event ws.onclose = function () { document.getElementById("connectionStatus").innerText = "Connection Closed"; // clear the WebSocket so we can try again ws = null; }; // Handle the onerror event ws.onerror = function () { console.log("error"); document.getElementById("connectionError").innerText = "WebSocket Error"; }; } } this.closeConnection = function () { if (ws) { clearMessages(); ws.close(); } } ); }; B . I call this from a button indeed: <input type = "button" onclick = "myfunction()" value = "openwebsocket"> and the link in the header <script type = "text/javascript" src="test.js"></script> C. i do have connection now , but it sure is ugly , not your fault , but i would like to be able to refactor the code , , ( so i can e.g. bring the dictionaries back into JS , as they are well supported in JS. ) . D: i tried : <input type = "button" onclick = "connection()" value = "openwebsocket"> <input type = "button" onclick = "connection.openconnetion()" value = "openwebsocket"> and 10 more ways , but no no avail ;-) (my guess is your code uses some framework with routing ???)
-
Γ©dited last line
-
Hi Paul, ( btw , thanks Roman , for your input , 2b has always worked very well for me , but is not the solution, 3 needs sync of hw and fsuipc ..... so... ;-) ... ) Solved , i did not call the function: connection() ;-) , deleted too much of your code... as easy as it was to get your websockets example to work in c# , the harder it seems in javascript , so no copy paste ? The setup using javascript only as simple as possible , because JS is rather new to me index.html and connection.js live in 1 folder , i started from the JS example in Visual Studio and Visual Studio Code. here is the index.html =============== <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>FSUIPC WebSocket Server</title> <script type="text/javascript" src="connection.js"></script> </head> <body> <h2>FSUIPC WebSocket</h2> </body> </html> ----------------- and here the connection.js var connection = new function () { var ws = null; // WebSocke this.start = function () { }; this.stop = function () { if (ws) { ws.close(); } }; var clearMessages = function () { document.getElementById("connectionStatus").innerText = ""; document.getElementById("connectionError").innerText = ""; }; this.openConnection = function () { if (!ws) { clearMessages(); // Create a new WebSocket. // The server url is from the text box on the form //var serverURL = document.getElementById("serverURL").value; ws = new WebSocket("ws://localhost:2048/fsuipc/", "fsuipc"); // Handle the onopen event ws.onopen = function () { console.log("open"); document.getElementById("connectionStatus").innerText = "Connection Open"; }; // Handle the onclose event ws.onclose = function () { document.getElementById("connectionStatus").innerText = "Connection Closed"; // clear the WebSocket so we can try again ws = null; }; // Handle the onerror event ws.onerror = function () { console.log("error"); document.getElementById("connectionError").innerText = "WebSocket Error"; }; } } this.closeConnection = function () { if (ws) { clearMessages(); ws.close(); } } }; ------------------------ only this line changed : ws = new WebSocket("ws://localhost:2048/fsuipc/", "fsuipc"); in the chrome dev tools i get this result : messages: connected and under headers: Request URL: ws://127.0.0.1:5500/index.html/ws Request Method: GET Status Code: 101 Switching Protocols Response Headersview source Connection: Upgrade Sec-WebSocket-Accept: ulRY6vxyLAMR+6zT9PFntYFrNiY= Upgrade: websocket Request Headersview source Accept-Encoding: gzip, deflate, br Accept-Language: en-US,en;q=0.9 Cache-Control: no-cache Connection: Upgrade Host: 127.0.0.1:5500 Origin: http://127.0.0.1:5500 Pragma: no-cache Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits Sec-WebSocket-Key: 1Ns9YcRWpb+SRrzeS0jt+A== Sec-WebSocket-Version: 13 Upgrade: websocket User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.193 Safari/537.36 ================== But the fsuipc websockets server has : number of sockets connected 0 ( i start the index.html from the live server in VS code ) : http://127.0.0.1:5500/index.html What could be the problem ??? Peter
-
Hi Paul , that is good news, and in my setup FSX , SE , and pmdg 737 I am getting around 9 ms. avg , so will investigate further ;-) Peter
-
Hi Paul , you wrote: "-Using the DLL you can check the .ValueChanged property on the Offset" - , yes , great , thanks! , works nicely. ( the alternative implementation using the websockets is indeed lot of work ;-) , but nice challenge . It is a bit more hairy in c# , because the websockets data arrive in separate thread, so invoke must be used . In your JS examples that problem does not seem to arise . ) - Using your .net client dll, all is working stable , but the encoders are a bit sluggish , to my taste . I am experimenting with settings of 10ms for timerMain , but i can't see a noticeable improvement. ( they are in their own group of 6 ) . I did do separate testing of the encoders , with a serial port viewer and there is no problem there with speed. That seems to suggest that the bottleneck is the part where the fsuipc offset is written . Is there a limit / update rate as far as fsuipc is concerned ? best regards , Peter
-
- great , works like a charm now . - Well , is a nice challenge ... , e.g. name: 'altitude', address: 0x0570, type: 'int', size: 8 }, , apparently in JS you can format JSON like that. but the JSON docs state hex numbers are not supported π , so i guess will have to use string here . ah , going through the doc examples , i did get exception , maybe quitting FS before the server ??? and small data error in HDG , consistently 2 degrees off, but no big deals . best regards , Peter - right now , ( after implementing the "pininfodictionary " , as per your example above ) i decided to to the same thing on the receiving end , and created a "leddictionary ". - so with 2 lines of code , i could get rid of all offset definitions in c# : var list = LedDictionary.Keys.ToList(); foreach (var key in list) checkbox[LedDictionary[key].LedNumber].Checked = LedDictionary[key].getOffsetValue() > 0; ( i am using checkboxes , ( i found a way to dynamically generate them ) , as a way to "fake" Events . ) So the whole program is now reduced from hundreds of lines of code to < 100 lines of code . - you are right , is more work , but on the other hand , since i use 2 .csv files, they can be read in in 1 codeline using a lib ( by now you understand i am a fan of using libs π - and i am starting to like c# VS ( forget LUA .... ) . - so i would like to give it a try . - now on testing i did run into a snag : - websocket is open , and i am testing on pmdg SE , 737 , FSX Win10 - i am sending the command as per your example in your doc: ws open {"Command":"about.read","Name":"about"} fsuipc says: { "command": "Unknown", "name": "Unknown", "success": false, "errorMessage": "Request message is invalid. No command specified.", "errorCode": "BadMessage" }
-
Hi Paul, - right now , ( after implementing the "pininfodictionary " , as per your example above ) i decided to to the same thing on the receiving end , and created a "leddictionary ". - so with 2 lines of code , i could get rid of all offset definitions in c# : var list = LedDictionary.Keys.ToList(); foreach (var key in list) checkbox[LedDictionary[key].LedNumber].Checked = LedDictionary[key].getOffsetValue() > 0; ( i am using checkboxes , ( i found a way to dynamically generate them ) , as a way to "fake" Events . ) So the whole program is now reduced from hundreds of lines of code to < 100 lines of code . - you are right , is more work , but on the other hand , since i use 2 .csv files, they can be read in in 1 codeline using a lib ( by now you understand i am a fan of using libs π - and i am starting to like c# VS ( forget LUA .... ) . - so i would like to give it a try . - now on testing i did run into a snag : - websocket is open , and i am testing on pmdg SE , 737 , FSX Win10 - i am sending the command as per your example in your doc: test cmdtest = new test { Command = "about.read", Name = "about", }; string json = JsonConvert.SerializeObject(cmdtest); =========================================== this is the response: ws open {"Command":"about.read","Name":"about"} fsuipc says: { "command": "Unknown", "name": "Unknown", "success": false, "errorMessage": "Request message is invalid. No command specified.", "errorCode": "BadMessage" } any ideas ? it would be very nice if there was also 1 example in c# in the doc , for us who don't want to delve to deep into jscript π , best regards , Peter
-
Hi Paul , was going to ask you about the possibility of events ( for data coming from fsuipc ) , to avoid "flooding" the serial port π Then I came across your FSUIPC WebSocket Server project . That would nicely solve the problem: Studying the protocol , because it is used on a LAN only , the latency is about 0 . edit : could not connect , because did not notice the protocol parameter in the websocketsharp lib . , All is fine now , great thanks Paul ! Best regards , Peter
-
Hi Paul , was just reading up on your offset.GetValue example in your advanced tutorial section , but it did not compute , until now... ! I got the swithces to work with datatables , but this is more elegant ! Great ! best regard , Peter
-
Hi Paul , that was the idea , indeed. For the implementation ( not for the dict. stuff ) , do you have some pointers , what this is called in c# ?? So i can study this in the net . I found something called " dynamic programming " , but that was about recursive programming , and not applicable here , i think ... , best regards , Peter
-
Hi Paul , - basically all is working now for pmdg , and receiving data over serial port from hw, starting to like Visual Studio ( just kidding π - i am using the FSUIPCConnection.SendControlToFS(PMDG_737_NGX_Control. properties , which is fantastic , thanks ! - but it looks like about 20 times about the same code , for the pushbutton switches . for example : --------------------------------------- // event or loop , i can choose in my code , so i am basically receiving the pin numbers over a serial port . case pin.EVT_MCP_LVL_CHG_SWITCH: FSUIPCConnection.SendControlToFS(PMDG_737_NGX_Control.EVT_MCP_LVL_CHG_SWITCH, Convert.ToInt32(!(MCP_annunLVL_CHG.Value > 0)) ); break; --------------------------------------------------- pin.EVT_MCP_LVL_CHG_SWITCH: defined as 23 ( in separate class , similar to enumeration ) using your naming conventions PMDG_737_NGX_Control.EVT_MCP_LVL_CHG_SWITCH defined as 70023 Convert.ToInt32(!(MCP_annunLVL_CHG.Value > 0)) , using petes naming convention , and your > 0 trick π Q . I would like to keep this idea , but use a dictionary , would that be more elegant / short ??? - So use the 23 as key , lookup your value . Then use the same key in a second dictionary , lookup the last MCP_annunLVL_CHG.Value name , and its value ( maybe in tuple) . - in this way , it would be 1 function call , with the key as parameter . - the key value pairs or tuples could be neatly stored in a text file , and read into the dictionary at formload time . best regards , Peter Edit: I thought about it again , and don't know if it is possible in c# , If the text file has rows like this: ( for the above example ) , ( to be read into the dictionary ) Pinnumber( enum) (dict-key) controlname offsetname pin.EVT_MCP_LVL_CHG_SWITCH PMDG_737_NGX_Control.EVT_MCP_LVL_CHG_SWITCH MCP_annunLVL_CHG then call function , and use the 2 strings in this row from the dict. to BUILD the code line : FSUIPCConnection.SendControlToFS("controlname" , " offsetname" .Value > 0)) ); if this magic is possible , then that would be the most simple solution , unless you have other tricks up your sleeve ... best regards , Peter
-
Hi Paul , - am still comparing , so last but not least .... your dll , so diving into C# and Visual Studio . It is a lot... π - this morning i got this error when trying to add the fsuipc dll as you described in your video . Error Could not install package 'FSUIPCClientDLL 3.1.20'. You are trying to install this package into a project that targets '.NETFramework,Version=v3.5', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author. what gives ??? best regards , Peter Hi Paul , - thanks , that was indeed part of the problem , i took a gamble and added the fsuipcclient folder to the solution , and added then the reference to the dll . - great , thanks , making progress now best regards , Peter
-
Hi Paul , - am still comparing , so last but not least .... your dll , so diving into C# and Visual Studio . It is a lot... ;-) - this morning i got this error when trying to add the fsuipc dll as you described in your video . Error Could not install package 'FSUIPCClientDLL 3.1.20'. You are trying to install this package into a project that targets '.NETFramework,Version=v3.5', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author. what gives ??? best regards , Peter
-
Hi Paul, - thanks for your very clear explanation , ( looks like your code π ) - the task at hand is to let my arduino board talk to fsx , the buttons and switches , and also receive data , to set leds , and 7-segm. display , therefore no user interaction is necessary . - so the lua program would be only an intermediary , and it can speak "serial " very easily according to the lua docs . - could you expand a bit on the ΓΆther considerations ? Why is lua mor effiecint ? - i thought from your docs that the .net client also needs a copy of fsuipc installed ? Peter
-
Hi Paul , i am looking to use either fsuipc client dll , or lua and i noticed in one of your replies , that you suggested to a user to try lua instead of the client dll Is there any functional difference , as both talk to fsuipc ? I would like to hear your take on this , ? ( to me, on the surface lua looks very simple to program , and no GBs VS download etc needed π ) best regards , Peter