apigpio icon indicating copy to clipboard operation
apigpio copied to clipboard

Serial Access including RS232 (Feature request)

Open Odianosen25 opened this issue 6 years ago • 10 comments

Hello @PierreRust,

Many thanks for your work. Please is it possible to kindly add support for the Serial interface? I went via the doc on the pigpio library, and it seems to support serial.

I have a serial interface at “/dev/ttyAMA0”, and was hoping to be able to access it asynchronously using your code. Also support for RS485 will be great as mine is on “/dev/ttyRS485”.

Thanks and regards

Odianosen25 avatar Jun 09 '18 03:06 Odianosen25

@jabdoa2 and @alexander3771,

Please is there anyway someone could assist me with this request? I know Asyncio, but not so confident in it.

Even if the code is just a patch together, at least it gives me a start and I could walk via it, if its buggy; so no need to spend so much time on it.

Thanks

Odianosen25 avatar Jun 10 '18 07:06 Odianosen25

Hello, @Odianosen25!

I didn't make anything with apigpio since my last commit, but I worked on other asyncio-projects :)

As far as I understand, you want to connect to your gpio via serial port. I guess, you only need to implement connection from this snippet https://gist.github.com/potens1/914b738a2ca6fed7a7b3 Inherit methods connect, _pigpio_aio_command and close here, and make sending data via serial connection https://github.com/alexander3771/apigpio/blob/2df1aafff4a3e274c35bc6509afd06d28b08bc13/apigpio/apigpio.py#L540-L600

Hope it helped, btw I can review your code :)

alexander3771 avatar Jun 10 '18 08:06 alexander3771

@alexander3771,

Oh thanks for your response.

Thanks for the examples, and I am aware of the serial over asyncio, but that's not really want I want. Not that I want to read the GPIO from serial, but I want to use the apigpio to read the serial port on the Raspi which is part of the GPIO ('/dev/ttyAMA0' to be precise). As the pigpio supports that with some SER.. commands.

I am working on a project, and I want to use the pigpio daemon via asyncio to read my GPIO using python. So that was what brought me here. I noticed you made a PR, which I have downloaded, and I want to make some modes to it, so I can read not just the pins, but also the serial port.

I also what to use the pipe option over /dev/pigerr, instead of the socket to improve security; but I will look into this later.

Thanks for the offer to review my code, and I will go via that option so I don't use up your time. I am already presently making some modes already, so once done will send it over.

Thanks and regards

Odianosen25 avatar Jun 10 '18 09:06 Odianosen25

Hello @alexander3771,

I have made some changes to your files, in which I added the i2c changes made by @jabdoa2 and some serial by myself. You can see the files here.

Please can you kindly go via it and confirm I didn't do anything naughty?

Thanks and kind regards

Odianosen25 avatar Jun 10 '18 20:06 Odianosen25

Looks good to me. Can you create a PR against this or my repo? That would allow us to merge it later.

jabdoa2 avatar Jun 10 '18 21:06 jabdoa2

Ok thanks @jabdoa2, I will do just that now and create a PR also against your repo.

Regards

Odianosen25 avatar Jun 10 '18 21:06 Odianosen25

It's ok for me too. But let me wrap this code in if py35:

+    async def __aenter__(self):
+        await self.connect()
+        return self
+
+    async def __aexit__(self, exc_type, exc_val, exc_tb):
+        await self.stop()

because of https://github.com/PierreRust/apigpio/pull/10#issuecomment-357529075 I can make it tomorrow

alexander3771 avatar Jun 10 '18 21:06 alexander3771

Elmm @alexander3771 I honestly have no clue what you saying, but I believe you can make changes to it right?

So I will wait till tomorrow, before using the code in my project so I will be certain I have the latest.

Thanks and kind regards

Odianosen25 avatar Jun 10 '18 21:06 Odianosen25

@Odianosen25 just use the older syntax (yield from and asyncio.coroutine) like the other functions

jabdoa2 avatar Jun 10 '18 22:06 jabdoa2

@jabdoa2, thanks, but I have just started learning to use asyncio, and I am actually so much more used to async def and await, so not so used to the old yield stuff; that's why I said I didn't get what he meant.

If its about the conversion as the linked comment, I will actually prefer that, as I am kind of more comfortable with the new way of doing it, since that is my first way I learnt it.

Thanks once again

Odianosen25 avatar Jun 10 '18 22:06 Odianosen25