Jump to content
The simFlight Network Forums

MCP (CPFLIGHT) and LUA


Recommended Posts

Hello,

I am a registered user of FSUIPC and WIDEFS for 11 years, and I thank Pete very much for this extremely complete software.
The operation of WideFS is still operational with P3D-V4. Bravo.
I bought an FSUIPC5 key as soon as it was available, and everything works perfectly with P3D-V4.

Now, here is my problem :
 
I own an MCF + EFIS from CPFlight. It worked perfectly with the supplied driver, as well as the (Expensive) software from FS-Labs.
Unfortunately , the FS-Labs software is a 32 bits version, and there is no planned version for compatibility with P3D-V4.
So I looked for another solution, and by reading the important documentation provided with FSUIPC, I discovered that there was everything necessary to direct control for my  hardware.
So I started using LUA plug-ins, helped by the many examples provided.  Great job, Pete ... Very well explained and very complete.

Unfortunately, I am not able to make a simple com.write () ...
I run P3D-V4 with the following LUA script, associated with a keyboard key ("A") :

MCP-747.lua :

-----------------------------------------------
-- Commande du MCP-747 de CP-Flight avec LUA
-----------------------------------------------

speed = 38400  -- Vitesse du port USB 
handshake = 0  -- No handshake

MCP = com.open("com6", speed, handshake)

if MCP == 0 then
   ipc.log("Pas trouvé de MCP-747 de CP-Flight")
   ipc.exit()
end

ipc.log("Port USB ouvert")

n = com.write (MCP, "Q001")

ipc.log(n)

When I execute the script ("A" key from the keyboard), the LLUA log (MCP747.log)  gives this:

********* LUA: "MCP-747" Log [from FSUIPC version 5.101] *********
   256825 System time = 21/06/2017 11:42:37, Simulator time = 14:44:36 (12:44Z)
   256825 LUA: beginning "M:\P3D-V4-0\Modules\MCP-747.lua"
   256825 LUA: M:\P3D-V4-0\Modules\MCP-747.lua:5
   256825 LUA: Global: ipcPARAM = 0
   256825 LUA: M:\P3D-V4-0\Modules\MCP-747.lua:6
   256825 LUA: Global: speed = 38400
   256825 LUA: M:\P3D-V4-0\Modules\MCP-747.lua:8
   256825 LUA: Global: handshake = 0
   256903 LUA: M:\P3D-V4-0\Modules\MCP-747.lua:10
   256903 LUA: Global: MCP = 5029216692
   256903 LUA: M:\P3D-V4-0\Modules\MCP-747.lua:15
   256903 LUA: Port USB ouvert
   256903 LUA: M:\P3D-V4-0\Modules\MCP-747.lua:17
   256903 LUA: M:\P3D-V4-0\Modules\MCP-747.lua:19
   256919 LUA: Global: n = 0
   256919 LUA: 0
   256919 >>> Thread forced exit (ipc.exit or os.exit) <<<
   256919 System time = 21/06/2017 11:42:37, Simulator time = 14:44:36 (12:44Z)
********* LUA execution terminated: Log Closed *********

The trace of the serial port (COM6) by the "Advanced Serial Port Monitor" software gives this :

<20170621114237.550 SYS>
COM est ouvert
<20170621114237.550 SYS>
Taille de queue entrée/sortie 1024/1024
<20170621114237.550 SYS>
Unable to add string #8
<20170621114237.553 SYS>
Débit en bauds 38400
<20170621114237.556 SYS>
RTS activé
<20170621114237.559 SYS>
DTR activé
<20170621114237.562 SYS>
Bits de données=8, Bits d'arrêt=1, Parité=None
<20170621114237.562 SYS>
Configurer charactères : Eof=0x00, Error=0x00, Break=0x00, Event=0x00, Xon=0x11, Xoff=0x13
<20170621114237.565 SYS>
Handflow : ControlHandShake=(DTR_CONTROL), FlowReplace=(TRANSMIT_TOGGLE, RTS_CONTROL), XonLimit=896, 

XoffLimit=512
<20170621114237.565 SYS>
Purger le port série : RXABORT, RXCLEAR
<20170621114237.983 SYS>
Purger le port série : RXABORT, RXCLEAR
<20170621114238.101 SYS>
COM est fermé

There is nothing writen on the Com6 !

Using the MCP test software, with the same "Advanced Serial Port Monitor" :

<20170621114831.512 SYS>
COM est ouvert
<20170621114831.515 SYS>
Taille de queue entrée/sortie 1024/512
<20170621114831.515 SYS>
Purger le port série : RXABORT, RXCLEAR, TXABORT, TXCLEAR
<20170621114831.515 SYS>
Unable to add string #8
<20170621114831.518 SYS>
Débit en bauds 38400
<20170621114831.524 SYS>
RTS désactivé
<20170621114831.530 SYS>
DTR activé
<20170621114831.533 SYS>
Bits de données=8, Bits d'arrêt=1, Parité=None
<20170621114831.533 SYS>
Configurer charactères : Eof=0x1A, Error=0x00, Break=0x00, Event=0x00, Xon=0x11, Xoff=0x13
<20170621114831.539 SYS>
Handflow : ControlHandShake=(DTR_CONTROL), FlowReplace=(), XonLimit=256, XoffLimit=256
<20170621114831.540 TX>
Q001<NUL>Q001<NUL>
<20170621114831.612 RX>
KCPF<NUL>CPMCP747_100<NUL>CHIAVE0310013<NUL>MOD485EFI1<NUL>K037<NUL>K041<NUL>K017<NUL>K019<NUL>V06 

359<NUL>S003<NUL>M001<NUL>K072<NUL>K075<NUL>V0900<NUL>
<20170621114844.218 RX>
K025<NUL>
<20170621114844.218 TX>
L0125
<20170621114845.089 RX>
K024<NUL>
<20170621114845.089 TX>
L0124
<20170621114846.026 RX>
K026<NUL>
<20170621114846.027 TX>
L0126

I do not understand where I was wrong !
Can anyone help me ?

PS : I am from Paris (France) so, please, excuse my bad English ...

 

Link to comment
Share on other sites

FSUIPC version 5.102 fixed some problems in COM, VRI and HID functions, related to handles in 64-bit more being 64-bit and Lua numbers all being floating point, with less than 64-bit numerical capacity.

Please always look for updates first when you have a problem. Solutions often arrive beforehand.

5.102 replaced 5.101 on the 12th, 9 days ago! And further improvements and fixes (including one for event.com) were included in the interim update 5.102a, released today in the Download Links subforum.

Pete

 

Link to comment
Share on other sites

Thank you for this quick response.
I apologize, I would of course have to start by verifying that a new version was not released.

I just installed the new version.
Actually com.write works. All is OK !
I can now write a Lua script to drive my MCP.


Your product is just great. Thank you very much.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.