Jump to content
The simFlight Network Forums

ariz

new Members
  • Posts

    4
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling
  • Location
    Australia

ariz's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. Yes Pete, you are absolutely right! I added a line to let the arduino to wait before reading, and everything works now! Cheers Pete PS. If anyone ever wonders how I fixed it, simply add: while (!Serial.available()); above the Serial.read() line. It will tell the arduino to wait for incoming character before reading it
  2. Hi everyone I am sorry if similar questions has been asked before, but I can't seem to find a solution yet. I'm quite new to lua and FSUIPC so pardon me for my lack of understanding. I have a question regarding com.write. I'm trying to send data to arduino via the serial communication using com.write function. I have successfully sent data, but I'm having trouble reading the actual data. Here is a snippet of my current code ... Code above here -- Writer testString=0 function comWriter(time) ... Some code here, bypassed if testString == 200 then testString= "000" else testString=200 end com.write(arduino, "*" .. testString) end -- Set the timer for the write event.timer(200, "comWriter") -- Receiver function comReceiver(arduino, datastring, length) -- Last 2 characters are 0d and 0a (line break and return carriage) -- Eliminate these 2 characters datastring= datastring(1, length-2) -- Check if debugging if datastring(1, 5) == "DEBUG" then ipc.log(datastring) else -- Check how long is the identifier -- This is the first character identifierLength= tonumber(datastring[1]) -- Seperate identifier and values -- identifier is the event ID found in PMDG sdk identifier= datastring(2, identifierLength+1) value= datastring(identifierLength+2); -- After the ID, up to end -- Call the control for the identifier ipc.control(baseID + identifier, value) end end As you can see, I'm sending either '*200' or '*000' every 200 ms to the arduino. In return the arduino send back 'DEBUG ' plus what it read in bytes. Here's a snippet of the arduino code if (Serial.available() && Serial.read() == '*') { readSerial(); } void readSerial() { digitalWrite(6,HIGH); byte il[3]; for (byte i=0; i<3; i++) { il[i] = Serial.read(); } Serial.print("DEBUG "); Serial.print(il[0]); Serial.print(il[1]); Serial.println(il[2]); } As you can see above, the arduino wait for a '*', then it reads the next 3 characters, then it sends back what it read along with the 'DEBUG ' string. However, when I looked at my lua log file, the arduino returns weird results ... 61203 LUA: Global: testString = 200 61203 LUA: ...les\Lockheed Martin\Prepar3D v4\Modules\arduino1.lua:133 61219 LUA: Waiting for an event in "G:\Program Files\Lockheed Martin\Prepar3D v4\Modules\arduino1.lua" 61219 LUA: COM Input event: calling "comReceiver" in "G:\Program Files\Lockheed Martin\Prepar3D v4\Modules\arduino1.lua" 61219 LUA: ...les\Lockheed Martin\Prepar3D v4\Modules\arduino1.lua:142 61219 LUA: Local: datastring = DEBUG 255255255 .... 61485 LUA: Global: testString = 000 61485 LUA: ...les\Lockheed Martin\Prepar3D v4\Modules\arduino1.lua:133 61500 LUA: Waiting for an event in "G:\Program Files\Lockheed Martin\Prepar3D v4\Modules\arduino1.lua" 61516 LUA: COM Input event: calling "comReceiver" in "G:\Program Files\Lockheed Martin\Prepar3D v4\Modules\arduino1.lua" 61516 LUA: ...les\Lockheed Martin\Prepar3D v4\Modules\arduino1.lua:142 61516 LUA: Local: datastring = DEBUG 48255255 ... So it returns 255255255 for '200', and 48255255 for '000' (instead of 200 for '200' and 000 for '000'). So I'm not entire sure what's going on here. Is there a mismatch between the datatype com.write sent and what arduino received (if that even make sense)? If someone could point out to me what's wrong with my code, that would be great Note, I have successfully send data from the arduino to the lua and its reading it just find (I used a rotary encoder to change heading, and it worked wonderfully). Cheers!
  3. Hi Pete, thanks for the reply. It seems that my P3D install is somehow messed up. I have reinstalled it and I can read any offset now just fine. Thanks for the help!
  4. Hi everyone I'm sorry if this questions has been asked before. I have looked around for similar problems, but I can't seems to find any fix for mine My problem is simple, I'm trying to read the CMD A annunciator of PMDG 737 NGX on P3D v4. From my understanding, I would need to read offset 0x6545 to do this, so here's my simple lua script that i made to do so arduino = com.open("COM3", 9600, 0) while 1 do cmd_a = ipc.readUB(0x6545) ipc.display(cmd_a) end The problem is, I can't seem to get any value (the value in ipc display is always 0, regardless if the button (CMD A) is lit up or not). Would be great if someone could point out the mistakes/ misunderstandings I've made here What I've done: I have added the line to enable data broadcast for PMDG in '737NGX_Options.ini' file I know that the LUA file is running as the ipc display is displaying number on top of the screen Background Information: I'm running on P3D v4, using latest version of FSUIPC (5.121b). I'm trying to build the MCP eventually. In doing so, I'm using and arduino card, and uses serial communication. Any help would be greatly appreciated. If further clarification is needed, please ask me. Cheers!
×
×
  • 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.