AdvancedHMI Software

General Category => Support Questions => Topic started by: Aviraj on September 07, 2015, 11:12:25 PM

Title: Controlling Raspberry Pi using AHMI
Post by: Aviraj on September 07, 2015, 11:12:25 PM
Hi

I am extremely new to Advanced HMI and I am running it on a Windows 7 PC. I wanted to know if it is possible to control a Raspberry Pi using the Advanced HMI on my PC, such as turning on/off LEDs connected to the RPi or other things like that. I am aware that AHMI can be run on a RPi to control a PLC, however, can it control a RPi while running on a Windows computer/laptop ?

Thanks in advance for the responses.
Title: Re: Controlling Raspberry Pi using AHMI
Post by: Archie on September 08, 2015, 12:07:05 AM
Not necessarily AdvancedHMI, but this may be something that may lead you to the right direction:

https://github.com/andycb/PiSharp
Title: Re: Controlling Raspberry Pi using AHMI
Post by: Aviraj on September 08, 2015, 09:41:10 AM
Thanks for the response Archie. So what you mean is adding the PiSharp.LibGpio.dll file to the Visual Studio project and then using it from within Advanced HMI (I don't even know if that is possible) or just using Pi# as a standalone program ?

Thanks
Title: Re: Controlling Raspberry Pi using AHMI
Post by: Archie on September 08, 2015, 09:53:37 AM
Do you want to run the HMI on a separate PC or directly on the Raspberry Pi?
Title: Re: Controlling Raspberry Pi using AHMI
Post by: Aviraj on September 08, 2015, 10:15:29 AM
The HMI will be running on a separate Windows 7 PC and I want to control a Raspberry Pi which is connected to the Ethernet. The RPi has some inputs and outputs connected to it, and I want that I can control that from my Windows PC using Advanced HMI
Title: Re: Controlling Raspberry Pi using AHMI
Post by: Archie on September 08, 2015, 10:22:20 AM
PiSharp wouldn't be the solution. You would need some kind of program running on the PI that can listen for communications from AdvancedHMI and translate those messages into control of the IO pins.

The most likely easiest to find would be a library that implements Modbus.You would need a Modbus server (slave) application. Maybe something like this:

http://jacekhryniewicz.wix.com/website#!raspberry-pi-with-modbus-tcp/c1d2y
Title: Re: Controlling Raspberry Pi using AHMI
Post by: Aviraj on September 08, 2015, 10:31:16 AM
Thanks for the help Archie. I will try looking into it. Will keep you posted.
Title: Re: Controlling Raspberry Pi using AHMI
Post by: Aviraj on September 11, 2015, 10:26:18 AM
Hi Archie

I tried out the Kepware Modbus TCP/IP server on my PC and the pymodbus library on the RPi and I do have some sort of communication established. It is reading the 5 holding registers and I see the values on the Kepware window on my PC. Would you be able to point me in the right direction regarding now connecting Advanced HMI to the RPi and communicating with the RPi through AHMI ?

Thanks a lot
Title: Re: Controlling Raspberry Pi using AHMI
Post by: Godra on September 11, 2015, 12:39:06 PM
Aviraj,

Since you have a Pi, would you ever mind testing a solution posted here: http://advancedhmi.com/forum/index.php?topic=938.0

You would have to load and run it directly on the Pi (if your setup allows that).

I am just curious of whether it works and I don't have a Pi to test it.
Title: Re: Controlling Raspberry Pi using AHMI
Post by: Aviraj on September 11, 2015, 03:30:55 PM
Sure I can do that. I have downloaded the .zip folder , not really sure how to proceed after that in Raspberry Pi. Will be glad if you could tell me the steps to run it on the RPi.
Title: Re: Controlling Raspberry Pi using AHMI
Post by: Aviraj on September 11, 2015, 03:31:58 PM
Also, I got Advanced HMI to connect to my Raspberry Pi and I can actually control GPIOs on the RPi and even outputs on the PiFace module through AHMI running on my PC.
Title: Re: Controlling Raspberry Pi using AHMI
Post by: Godra on September 11, 2015, 05:03:47 PM
The steps to run AHMI directly on the Pi can be seen here:

http://advancedhmi.com/forum/index.php?PHPSESSID=5b260fdc0b31f8680e52361ebd719710&topic=666.0

By doing this test you would actually learn how to run any AHMI project directly on the Pi. If you decide not to go ahead with this, I will understand and bug somebody else to try it.

If you already have mono-complete and mono-vbnc installed on the Pi then you can just follow steps 8, 9 and 10.

The solution that you downloaded is set to have pins 18 and 22 as inputs, pins 11, 13, 15 and 16 as outputs. If your Pi is setup differently then I can modify the solution or just let you know of how to do it.

This program, when run, should have output pins "high" if both inputs are "low" (check the AHMI screen since it shows how the pins are organized).

Let me know if you DON'T feel like doing this or if you decide to go ahead then what other info I would need to provide.
Title: Re: Controlling Raspberry Pi using AHMI
Post by: Aviraj on September 14, 2015, 10:13:08 AM
Hi Godra

I was trying to run the solution on my RPi and I get an error saying "The entry point method could not be loaded"
Title: Re: Controlling Raspberry Pi using AHMI
Post by: Aviraj on September 14, 2015, 01:44:06 PM
It was a vbnc issue for some reason. Re-installing it fixed the issue. However, I am seeing the following messages now:
Title: Re: Controlling Raspberry Pi using AHMI
Post by: Godra on September 14, 2015, 05:36:28 PM
Aviraj,

Thank you for testing this solution.

If you want to give it another try, I have attached 2 files (export and unexport) that you should copy to /tmp/RasPiGpioTest/ folder on the Pi. I thought these files would be created automatically but I was wrong.

If you run the program after you copy files then those warnings might still remain but if errors continue just post them but I will not bug you to do any more testing.

If you don't feel like doing this either that is fine with me.
Title: Re: Controlling Raspberry Pi using AHMI
Post by: Aviraj on September 15, 2015, 09:04:21 AM
Hi Godra

I created the folder /tmp/RasPiGpioTest/ and copied the files there. On trying to run, it is still complaining about a missing directory (a different one though). This time over the the error is:

System.IO.DirectoryNotFoundException: Could not find a part of the path "/tmp/RasPiGpioTest/gpio24/direction".

This is followed by other messages just like the previous time.

I can test it again if you could provide me with the required files and locations.


Avi
Title: Re: Controlling Raspberry Pi using AHMI
Post by: Godra on September 15, 2015, 02:58:51 PM
Aviraj,

According to info found here https://github.com/andycb/PiSharp/wiki/Using-LibGpio , the program should be writing to /tmp/RasPiGpioTest folder only if the library is placed in test mode (otherwise it should be trying to access /sys/class/gpio folder). And in this case we don't want the library in test mode.

Can you open the solution and check the code of MainForm_Load subroutine to confirm that it looks like this:

Code: [Select]
    Private Sub MainForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
        ' Use test mode
        LibGpio.Gpio.TestMode = False ' <-- This needs to be set to False
        ' Set paired pin outputs for each pin input (using RaspberryPinNumbers)
        LibGpio.Gpio.SetupChannel(RaspberryPinNumber.Five, Direction.Input)
        LibGpio.Gpio.SetupChannel(RaspberryPinNumber.Six, Direction.Input)
        LibGpio.Gpio.SetupChannel(RaspberryPinNumber.Zero, Direction.Output)
        LibGpio.Gpio.SetupChannel(RaspberryPinNumber.Two, Direction.Output)
        LibGpio.Gpio.SetupChannel(RaspberryPinNumber.Three, Direction.Output)
        LibGpio.Gpio.SetupChannel(RaspberryPinNumber.Four, Direction.Output)
    End Sub

I have attached the whole folder as it was created on my computer (but as suggested it should only be used if the library is placed in Test mode).

You have already done a lot but if you feel like trying again then go for it.
Title: Re: Controlling Raspberry Pi using AHMI
Post by: Aviraj on October 14, 2015, 05:09:23 PM
Hi Godra

Sorry for the extremely late response. I was working on some other projects and just got back to working on the Advanced HMI once again. I tested out your solution again by downloading the RasPiGpioTest folder that you provided. The good thing is that the application now opens up and shows the buttons as shown in the picture you posted. However, the actual inputs and outputs do not work. That is, if I connect LEDs to the outputs mentioned (11,13,15 and 16) and click RPi Test button, nothing happens, the LEDs do not turn on.

I am starting to work on something requiring the exact same functionality. Your help will be greatly appreciated.

Thanks

Aviraj