Aliazzzz / Monarco-HAT-library-for-CODESYS-V3

CODESYS 3 Library for Monarco HAT
https://github.com/Aliazzzz/Monarco-HAT-library-for-CODESYS-V3
5 stars 2 forks source link

RS485 for Modbus RTU #5

Closed Hubieg closed 6 years ago

Hubieg commented 6 years ago

Greetings,

I now have my Monarco hat and everything up and running. One Wire works perfectly from inside codesys. I do however seem to be having some issues with the compilation of some libraries. I will wait a bit for that though. My "issue" is I am wondering if I can use the native Codesys RS-485 Modbus RTU support with your system and without external libraries and calls? I see in the example you have separate calls for RS-485.

I ran a "dmesg" and it is showing /dev/ttyAMA0 (which I assume from your documentation may be the "terminal". I also see /dev/ttyS0. What I am wondering is if either of these may be a direct line to the RS485 that can be used directly from the Codesys Modbus RTU drivers? Looking at the Codesys forum I found that when a USB - RS485 adapter is used, it is added as follows:

""so you need to add in /etc/CODESYSControl.cfg (Attention you need to remove the 0 from USB0)

[SysCom] Linux.Devicefile=/dev/ttyUSB portnum := COM.SysCom.SYS_COMPORT1;""

Assuming that ttyS0 is a direct line to the RS485 port, would you agree that adding "Linux.Devicefile=/dev/ttyS" would bring me directly to the RS485? I am a bit worried by this as we already have the Linux.Devicefile=/dev/ttyAMA and the portnum command doesnt seem to attach to a particular tty (unless it attaches only to the preceeding devicefile call).

What is your take on all of this?

Aliazzzz commented 6 years ago

Dear Hubieg,

Sorry for the late anwser.

For RS485 You cannot go without external libraries! The only direct interaction with the HAT is needed to set some RS485 settings, like baudrate, bits per byte, parity and stopbits, also to check some faulkt counters. The rest is done via the external library. Fortunatly, you can pick your own flavour of library, which in my opinion is a big plus. So, I deliberatly chose a CAA type library ( Uniformity (standard behaviour model, more platform independendant)

Also, My advice would be to carefully read the Monarco documentation on the RS485 interface, found here: https://github.com/monarco/monarco-hat-documentation.

A personal note: I included RS485 for completeness, but I personally do not have any use for it. Maybe you can hook up a Heater via the thermostat wiring, as this an RS485 connection (Opentherm talks via 2 wire RS485) so that can be a nice home automation project. Personally, I'd choose a CAN interface on that place, but that's life.

Hubieg commented 6 years ago

Thanks for the reply!!

I have read the documentation and it seems to indicate RS485 is brought directly in (and out) via UART0. This means (to me anyway) that Codesys should be able to directly control the serial port via its native interface. It also seems to me that the library is called from the CAA library in the Codesys config file in /etc/Codesys....

I did read elsewhere that another Pi native application may be "walking over" the UART for use with Bluetooth on the V3 Pi. I will follow this up with Monarco and report it back here. Modbus RTU is something that hopefully I can then add to the project. If the hardware is there and capable, it would be a very handy addition to the project.

Cheers, Todd

On Mon, Nov 27, 2017 at 6:55 AM, Aliazzzz notifications@github.com wrote:

Dear Hubieg,

Sorry for the late anwser.

For RS485 You cannot go without external libraries! The only direct interaction with the HAT is needed to set some RS485 settings, like baudrate, bits per byte, parity and stopbits, also to check some faulkt counters. The rest is done via the external library. Fortunatly, you can pick your own flavour of library, which in my opinion is a big plus. So, I deliberatly chose a CAA type library ( Uniformity (standard behaviour model, more platform independendant)

Also, My advice would be to carefully read the Monarco documentation on the RS485 interface, found here: https://github.com/monarco/ monarco-hat-documentation.

A personal note: I included RS485 for completeness, but I personally do not have any use for it. Maybe you can hook up a Heater via the thermostat wiring, as this an RS485 connection (Opentherm talks via 2 wire RS485) so that can be a nice home automation project. Personally, I'd choose a CAN interface on that place, but that's life.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Aliazzzz/Monarco-HAT-library-for-CODESYS-V3/issues/5#issuecomment-347160567, or mute the thread https://github.com/notifications/unsubscribe-auth/AgDU9mAkIZwBZWt1AJafvZkLMdy4CfsGks5s6qMWgaJpZM4QqdRI .

Aliazzzz commented 6 years ago

Dear Hubieg,

I would like to let you know that I am planning to release a new version within a month from now (I hope).

This version will not be entirely backward compatible with v0.9.0.3 but it will bring you more comfort with using the HAT's IO. So, using RS485, 1w, and RTC should not be affected by this update, but all other IO will.

So, stay tuned for it.

Hubieg commented 6 years ago

Ill look foreward to it. In the mean time i am persuing the issue of RS485 from within Codesys and Modbus RTU. Hopefully i can contribute.

Cheers, Todd

On Nov 27, 2017 10:24 AM, "Aliazzzz" notifications@github.com wrote:

Dear Hubieg,

I would like to let you know that I am planning to release a new version within a month from now (I hope).

This version will not be entirely backward compatible with v0.9.0.3 but it will bring you more comfort with using the HAT's IO. So, using RS485, 1w, and RTC should not be affected by this update, but all other IO will.

So, stay tuned for it.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Aliazzzz/Monarco-HAT-library-for-CODESYS-V3/issues/5#issuecomment-347215787, or mute the thread https://github.com/notifications/unsubscribe-auth/AgDU9r5oBIdEin13nobDTQ3aLBQWuQjmks5s6tRHgaJpZM4QqdRI .

Aliazzzz commented 6 years ago

PS let me know how you test RS485!

I am curious on how you are testing this, because I suspect the problem is Linux/ hardwaredriver related.

Hubieg commented 6 years ago

I just woke to an email from Monarco. Seems the main problem is tha bluetooth does indeed need to be disabled and is trying to uses ttyAMA0. As soon as i can edit the email i will forward the "high points" of it.

On Nov 28, 2017 3:09 AM, "Aliazzzz" notifications@github.com wrote:

*PS let me know how you test RS485!**

I am curious on how you are testing this, because I suspect the problem is Linux/ hardwaredriver related.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Aliazzzz/Monarco-HAT-library-for-CODESYS-V3/issues/5#issuecomment-347444845, or mute the thread https://github.com/notifications/unsubscribe-auth/AgDU9lJ3aTyQr-LM2o2DxTEmL_66F-MZks5s67-ngaJpZM4QqdRI .

Hubieg commented 6 years ago

This from Monarco. I remember what i think was the line about "sed". Not sure tbough if that needs to run in the rc scripts everytime. I cant do much tezting at the moment as im back at my "day job" the next few weeks.

As for testing, i was using an rs485 adaptor on my pc. I tried both terminal to terminal, and Modbus to a modbus slave program on my computer.

You are right about the Bluetooth. It is fixed by the overlay in steps 3-5 of the installation instructions, so you should be good (if you followed them): https://github.com/Aliazzzz/Monarco-HAT-library-for-CODESYS-V3#hardware- installation

You also have to disable Linux console (step 2 of the instructions) otherwise it will appear on the RS485 bus.

And last but not least you have to setup Codesys as per steps 9-11.

Further information about RS485 on the Monarco HAT can be found here: https://github.com/monarco/monarco-hat-documentation/ blob/master/Monarco_HAT_Integration_Raspberry-Pi_Linux.md#uart--rs-485- communication

On Nov 28, 2017 7:25 AM, "Todd Simpson" htsimp@gmail.com wrote:

I just woke to an email from Monarco. Seems the main problem is tha bluetooth does indeed need to be disabled and is trying to uses ttyAMA0. As soon as i can edit the email i will forward the "high points" of it.

On Nov 28, 2017 3:09 AM, "Aliazzzz" notifications@github.com wrote:

*PS let me know how you test RS485!**

I am curious on how you are testing this, because I suspect the problem is Linux/ hardwaredriver related.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Aliazzzz/Monarco-HAT-library-for-CODESYS-V3/issues/5#issuecomment-347444845, or mute the thread https://github.com/notifications/unsubscribe-auth/AgDU9lJ3aTyQr-LM2o2DxTEmL_66F-MZks5s67-ngaJpZM4QqdRI .

Aliazzzz commented 6 years ago

As I too have a dayjob, I will wait until you have tested this point on your own system. Until then I will concentrate on implementation of v0.9.1.1