Firstly I pushed the development version of pyinsim 3.0.0 to codePlex, overwriting the old repository. I wasn't sure if I was going to do this at first, but I figured that all the old code and old versions will still be there, so people can still find them if they need them.
The second change was to add support for both Python 2.7 and Python 3.0 in a single package. The latest version of pyinsim has support for both versions of Python without any changes. It does this by conditionally declaring and importing several functions depending on which Python version is installed. This wasn't as much effort as I thought it was going to be actually, Python 2.7 and 3.0 are more compatible than you think. That being said, support for two Python versions means twice as many bugs and twice as much testing needed!
Lastly I'm still making some changes to the API. I realised after some thought that what I really needed to do was to eliminate any situation where there was more than one way of doing something. This means that I've finally deprecated the old way of sending packets in favour of the simpler newer version. That means that to send a packet you now always do it like this:
insim.send_packet(IS_MST(Msg='Hello, InSim!'))
In addition to this change I also renamed the pyinsim 'run' function to the new name of 'main_loop', which I think better describes what it actually is. There was always a lot of confusion as to what the run function did and why it was needed. Now it should be more explicit.
from pyinsim import insim_init, main_loop, IS_MST
insim = insim_init('127.0.0.1', 29999, Admin='')
insim.send_packet(IS_MST(Msg='Hello, InSim!'))
main_loop()
Um, I think that's it for the moment. As mentioned the library still needs a bunch more testing, and I also still need to rewrite the documentation to reflect all the API changes. That being said, it is coming along.
You can find the latest version of pyinsim 3.0.0 in the CodePlex repository.
My problem was caused by neglecting to set the ReqI. Thanks
Python doesn't care about the order of keyword arguments. I could put UCID after Msg if I wanted to.
I don't know how to use ReqIs. Request ID? To be honest, I use totally arbitrary numbers.
Edit: I wrote this at the end of a long, shitty shift. I apologise if it comes across as short and argumentative. That wasn't the intention.
In your example code you weren't using a named argument to refer to UCID (note the difference between 255 and the "Hello?" in the below quote, now checkout insim.py and look at the __init__ definition)
Therefore you are refering to ReqI since it's the first argument in the definition of IS_MTC. I assumed it was actual code you were using, I apologise. I should've read your mind.
Worked well for my program (here is it). Appreciate your work.
But when I try to send IS_MSO packet, I get some strange error (something like "pyinsim: Unknown packet type (136 bytes)" from LFS. I call it this way:
I have no idea, try it out and let us know! I would think it's in an alpha state, I seem to recall a conversation with DarkTimes about it from _quite_ a while ago.
I have the same problem as racerss, IS_ISI has no attribute SP0, tried to reinstall many times in many ways, i know its been like 2 years since update but is it just broken now or something?
I feel like it's fairly up to date, as last year I merged in a bunch of updates from Degats and also fixed some bugs. Exactly what is included vs missing I couldn't say for sure. If there is anything important needed it should not be hard to add.
Hi DarkTimes, I used a slightly updated version of your pyinsim in my g27 linux leds project (see forum). I have modded the outgauge reception to work with python3, as 2.7 support ends this year and I didnt want to create something thats obsolete soon
Are you planning to port the whole project to python3 anytime or even add support to this new custom outsim packet Scawen introduced in the last test patches?
I've managed to port most of this project to python 3.8, seems to be running fine (hasn't crashed and messages seem to look mostly ok)
One issue that I ran into with both python 2.7 & 3 was that the original insim.py file throws at line 2024, when attempting to send messages that start with a slash ("/"). The solution is kinda ugly atm, and there are probably some other hidden issues still, but I'll make a pull request when I'm more confident that I haven't left anything too horrific in there code.
So I started porting it to Python 3, at least a bit. I made a new branch and got it basically running with packets being both received and sent. There are some issues to work out, specifically how it should handle string encoding. As always with LFS it's the major blockage. Converting everything to 'latin1' doesn't work as LFS supports more types of encoding than that. Right now in my branch you need to make everything a byte string, by putting a 'b' in front of it e.g. b'Hello'.
Anyway, I spent a worryingly long amount of time on the issue with the IS_ACR packet throwing an error on line 2024. Seems like it was a Python 3 error.
Hey everyone. Stupid question from someone who has not a particularly high amount of skill in programming:
I am trying to figure out how to send autocross objects to LFS with python 3. I got everything else to work with byte stuff (car data, message handling, and so on), but I cannot figure out how to send autocross objects.
I've done basically everything but working with layouts so far, so I looked at the old examples, but I have no idea how that would work with the python 3 branch.
Firstly, ObjectInfo takes only two arguments, data and index, which is not a big deal I think i can figure that one out, but if I try to make that work I get this error:
self.X, self.Y, self.Zbyte, self.Flags, self.Index, self.Heading = self.pack_s.unpack(data[index:index+8])
TypeError: a bytes-like object is required, not 'tuple'
And I have no idea how to make a tuple a byte thingy .
Obviously only if anyone is bored enough haha, but it would be awesome if somebody could provide me with a newer little example with python 3.
Thank you
PS: Thank you for creating pyinsim in the first place, it was a huge help getting into programming with LFS and I was able to realize really cool projects.