Jump to content
The simFlight Network Forums

Recommended Posts

Posted

A quick question about com.write.

 

From examples here and elsewhere I have a simple lua script which is able to switch an output high or low on Arduino with the value of an Lvar changing. (good start!)

 

I am realising though I do not really understand com.write. Though I have researched several examples and figured a lot of the code I could do with explanation of what com.write is actually doing.

 

So it sends a string such as "a" to the device with the given handle.

 

But what does this actually mean? Is it restricted to a single character and hence 0 to 255 possible combinations or could it be "abc" also and thus unlimited?

 

I do have the the FSUIPC: Lua Library Reference open in front of me, I am just looking for deeper understanding of how sending a string such as "a" to the com port achieves things. What if I had a constantly changing value, say for a gauge, how do I get that to Arduino using com.write? Sorry if I am being a bit thick, probably overthinking the whole thing so a simple explanation of how com.write works would be appreciated. 

Posted

A quick question about com.write.

 

From examples here and elsewhere I have a simple lua script which is able to switch an output high or low on Arduino with the value of an Lvar changing. (good start!)

 

I am realising though I do not really understand com.write. Though I have researched several examples and figured a lot of the code I could do with explanation of what com.write is actually doing.

 

So it sends a string such as "a" to the device with the given handle.

 

But what does this actually mean? Is it restricted to a single character and hence 0 to 255 possible combinations or could it be "abc" also and thus unlimited?

 

I do have the the FSUIPC: Lua Library Reference open in front of me, I am just looking for deeper understanding of how sending a string such as "a" to the com port achieves things. What if I had a constantly changing value, say for a gauge, how do I get that to Arduino using com.write? Sorry if I am being a bit thick, probably overthinking the whole thing so a simple explanation of how com.write works would be appreciated. 

 

com.write simply sends whatever you want, whether one character or many bytes, whether binary data or character strings, out of the serial port or USB port you have opened. That is all. Nothing clever. It just tries to shove whatever you want shoved out of the port, in the format you provide it.

 

For changing values, send the changing values (of course?). Just be aware that there will be a limit on the speed of the transmission, depending on the device, the settings and so on. Best just to send values at intervals. If you want to see smooth changes on a gauge or something then 10-30 changes a second would be in order. For lesser needs maybe once per second might be enough.

 

I can't tell you how to program your device. Just be aware that there's nothing clever or mystical about com.write (or com.read for that matter). It just does exactly what you ask. It does exactly what it says in the La reference you have in front of you. What else would you expect?

 

Pete

Posted

Thanks Pete, yes the penny has dropped as they say. I created my own confusion due to the simplicity of some of the examples I found which led me to think there was a limitation to just a single ASCII character. I realise now this is not the case at all. Can I confirm with you that if I refer to the LUA documentation, com.write is essentially the same as io.write?

Posted

Thanks Pete, yes the penny has dropped as they say. I created my own confusion due to the simplicity of some of the examples I found which led me to think there was a limitation to just a single ASCII character. I realise now this is not the case at all. Can I confirm with you that if I refer to the LUA documentation, com.write is essentially the same as io.write?

 

Well, yes, probably, though I'm not sure io.write has the same buffering facilities built into it as the FSUIPC offerings. FSUIPC uses separate read and write threads running in the background.

 

Pete

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.