Author Topic: AdvancedHMI on a Raspberry Pi  (Read 130088 times)

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: AdvancedHMI on a Raspberry Pi
« Reply #45 on: August 21, 2015, 04:14:40 PM »
I used older AHMI v3.84 to test this, modified your code to this and placed the call inside WaitForResponse sub of the DF1Comm driver:

Code: [Select]
    '*********************************
    '* Open Serial Port
    '*********************************
    Public Function OpenConnection() As Integer
        '*****************************************
        '* Open serial port if not already opened
        '*****************************************
        Dim SerialPort As New IO.Ports.SerialPort
        If Not SerialPort.IsOpen Then
            If CDbl(m_BaudRate) > 0 Then
                Try
                    SerialPort.PortName = m_ComPort

                    If CDbl(m_BaudRate) = 0 Then
                        DetectCommSettings()
                    Else
                        SerialPort.BaudRate = CInt(m_BaudRate)
                        SerialPort.Parity = m_Parity
                    End If

                    '* Calculate how long to wait based on baud rate
                    MaxTicks = Convert.ToInt32(19200 * 100 / CDbl(m_BaudRate))

                    SerialPort.ReceivedBytesThreshold = 1
                    SerialPort.Open()
                    MsgBox("Serial port opened")
                Catch ex As Exception
                    If SerialPort.IsOpen Then SerialPort.Close()
                    Throw New MfgControl.AdvancedHMI.Drivers.Common.PLCDriverException("Failed To Open " & SerialPort.PortName & ". " & ex.Message)
                    Return -9
                    'Throw New MfgControl.AdvancedHMI.Drivers.PLCDriverException("Failed To Open " & SerialPort.PortName & ". " & ex.Message)
                End Try
            Else
                Dim result As Integer = DetectCommSettings()
                If result <> 0 Then
                    'Throw New MfgControl.AdvancedHMI.Drivers.PLCDriverException("Could Not Auto Connect")
                    If SerialPort.IsOpen Then SerialPort.Close()
                End If
                Return result
            End If
        End If

        Return 0
    End Function


When I run it on a Windows PC then I get this error (see the attached picture):

Quote
Comm Error -1.Failed To Open /dev/ttyUSB0. The given port name does not start with COM/com or does not resolve to a valid serial port. Parameter name: portName.


The same program run on Ubuntu PC gives this error (see the attached picture):

Quote
Comm Error -1.Failed To Open /dev/ttyUSB0. The requested feature is not implemented.


Another successful attempt was to place a ListBox on the form and place this code (the ports did open and close properly):

Code: [Select]
    Private mySerial As New SerialPort
    Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        listBoxSerialPorts.Items.Clear()
        Dim portnames As String() = SerialPort.GetPortNames()

        If portnames.Length = 0 Then
            Me.listBoxSerialPorts.Items.Add("error: none available!")
            listBoxSerialPorts.ForeColor = Color.Red
        Else
            listBoxSerialPorts.ForeColor = Color.Black
            For Each sPort As String In portnames
                Me.listBoxSerialPorts.Items.Add(sPort)
            Next
            If listBoxSerialPorts.Items.Count >= 1 Then
                listBoxSerialPorts.Sorted = True
            End If
        End If
    End Sub

    Private Sub listBoxSerialPorts_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles listBoxSerialPorts.SelectedIndexChanged
        If mySerial.IsOpen Then
            mySerial.Close()
            MsgBox("Serial Port " & mySerial.PortName & " closed.")
        End If
        mySerial.PortName = Me.listBoxSerialPorts.SelectedItem
        mySerial.BaudRate = 38400
        mySerial.DataBits = 8
        mySerial.Parity = Parity.None
        mySerial.StopBits = 2
        mySerial.Open()
        If mySerial.IsOpen Then MsgBox("Serial Port " & mySerial.PortName & " opened.")
    End Sub

    Private Sub MainForm_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        If mySerial.IsOpen Then
            mySerial.Close()
            MsgBox("Serial Port " & mySerial.PortName & " closed.")
        End If
    End Sub



Since I used older AHMI version for these tests, I can only suggest that you check that parameter portName as the first error suggested (if it is applicable in the current version).
« Last Edit: August 21, 2015, 04:23:16 PM by Godra »

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: AdvancedHMI on a Raspberry Pi
« Reply #46 on: August 21, 2015, 08:01:36 PM »
Archie,

I am using MONO 3.2.8 on Ubuntu and it doesn't seem to like the line: SerialPort.ReceivedBytesThreshold.

That feature doesn't seem to be implemented.

Could you possibly comment it out and post a patched dll?

What I did find out is that if I copy debug folder to Home directory and run "mono AdvancedHMI.exe" directly from there instead of USB drive then the program seems to be trying to do something with the port (some "Win32 IO returned 25" errors disappeared but the program might be stuck on the above mentioned unsupported feature).

Zip

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: AdvancedHMI on a Raspberry Pi
« Reply #47 on: August 21, 2015, 11:38:14 PM »
That is the same error message that i have been getting.

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: AdvancedHMI on a Raspberry Pi
« Reply #48 on: August 22, 2015, 12:52:30 AM »
Maybe a separate MONO edition of AHMI could be created that would eliminate those features not implemented.

It all depends on how much work it would create for Archie.

Zip

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: AdvancedHMI on a Raspberry Pi
« Reply #49 on: August 29, 2015, 01:48:21 AM »
Hi Godra,
               Please Excuse my lack of VB Coding Knowledge but I have been trying to find the sections of code where you modified the "Open Serial Port" commands and I cant find them anywhere in the Advanced HMI files. Am I missing something? Was hoping to replicate your successful attempt at getting the com port open. Could it be that the code is different in V3.98t to the v3.84 that you modified? Or am I looking in the wrong places? Browsed through all .vb files in the advanced HMI folder looking for "open serial port" and "WaitForResponse" but didnt come across anything. Apologies if this is a really basic Noob question.

zip

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: AdvancedHMI on a Raspberry Pi
« Reply #50 on: August 29, 2015, 04:09:27 AM »
The code to open the serial port is actually a part of the dll file (which you cannot access).

Archie took it out and posted it in this topic so I could perform some testing.

I can only suggest to be patient and wait for Archie to possibly modify the code so it would work with serial ports on Pi.

Zip

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: AdvancedHMI on a Raspberry Pi
« Reply #51 on: August 29, 2015, 06:58:43 AM »
Thanks Godra. I had a feeling that was the case. Thank you for confirming.

welsche

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: AdvancedHMI on a Raspberry Pi
« Reply #52 on: January 21, 2016, 08:25:34 AM »
Are there any news about Ahmi on the Raspberry with USB to Serial Adapter and Modbus RTU?

welsche

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: AdvancedHMI on a Raspberry Pi
« Reply #53 on: January 29, 2016, 05:29:31 AM »
Push

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: AdvancedHMI on a Raspberry Pi
« Reply #54 on: January 29, 2016, 07:51:38 AM »
Are there any news about Ahmi on the Raspberry with USB to Serial Adapter and Modbus RTU?
Internally we do very little development and testing with the Pi since it has almost no commercial applications for us, so unfortunately it is a very low priority. You may have better response on this by posing the question to a Raspberry Pi or Linux specific forum.

My guess is that it has something to do with Mono address serial ports in Linux versus the common Windows style of COMx:

Zip

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: AdvancedHMI on a Raspberry Pi
« Reply #55 on: April 04, 2016, 09:03:40 AM »
Quick update. Still no luck with modbus rtu but the brand of plc i use has just bought out an ethernet based model.
I was able to connect direct to the plc via ethernet port of raspberry pi for cheap standalone touchscreen hmi. Exactly what i needed! Thanks for all the help guys!

DanieLoche

  • Guest
Re: AdvancedHMI on a Raspberry Pi
« Reply #56 on: July 12, 2016, 12:29:38 PM »
Hello,

I juste made a little interface (2 buttons and a login page) to test it with my raspberry Pi. The goal is to implement a full HMI working in modbus TCP with a PLC.

But then when I try to run it, after 2 secondes AvcancedHMI.exe crashes.

Here is the error I get in the console :

Code: [Select]
* Assertion at mini-codegen.c:807, condition `i == sel' not met

Stacktrace:

  at <unknown> <0xffffffff>
  at System.Windows.Forms.TextBoxBase.Draw (System.Drawing.Graphics,System.Drawing.Rectangle) <0x000ab>
  at System.Windows.Forms.TextBoxBase.OnPaintInternal (System.Windows.Forms.PaintEventArgs) <0x00063>
  at System.Windows.Forms.Control.WmPaint (System.Windows.Forms.Message&) <0x0017f>
  at System.Windows.Forms.Control.WndProc (System.Windows.Forms.Message&) <0x00217>
  at System.Windows.Forms.TextBoxBase.WndProc (System.Windows.Forms.Message&) <0x00313>
  at System.Windows.Forms.TextBox.WndProc (System.Windows.Forms.Message&) <0x001d3>
  at System.Windows.Forms.Control/ControlWindowTarget.OnMessage (System.Windows.Forms.Message&) <0x0002b>
  at System.Windows.Forms.Control/ControlNativeWindow.WndProc (System.Windows.Forms.Message&) <0x0003b>
  at System.Windows.Forms.NativeWindow.WndProc (intptr,System.Windows.Forms.Msg,intptr,intptr) <0x002b7>
  at System.Windows.Forms.XplatUIX11.DispatchMessage (System.Windows.Forms.MSG&) <0x00023>
  at System.Windows.Forms.XplatUI.DispatchMessage (System.Windows.Forms.MSG&) <0x0002b>
  at System.Windows.Forms.Application.RunLoop (bool,System.Windows.Forms.ApplicationContext) <0x00ac7>
  at System.Windows.Forms.Application.Run (System.Windows.Forms.ApplicationContext) <0x0005f>
  at System.Windows.Forms.Application.Run (System.Windows.Forms.Form) <0x0002b>
  at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun () <0x00083>
  at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run (string[]) <0x00023>
  at MfgControl.AdvancedHMI.My.MyApplication.Main (string[]) <0x0003f>
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <0xffffffff>

Native stacktrace:


Debug info from gdb:

[New LWP 11418]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/arm-linux-gnueabihf/libthread_db.so.1".
0x76e3bee8 in __libc_waitpid (Cannot access memory at address 0x3
pid=11419, stat_loc=0x7efa8d10, options=0) at ../sysdeps/unix/sysv/linux/waitpid.c:40
40 ../sysdeps/unix/sysv/linux/waitpid.c: No such file or directory.
  Id   Target Id         Frame
  2    Thread 0x75bff430 (LWP 11418) "mono" 0x76e39a40 in do_futex_wait (isem=isem@entry=0x3181a4) at ../nptl/sysdeps/unix/sysv/linux/sem_wait.c:48
* 1    Thread 0x76f4a000 (LWP 11417) "mono" 0x76e3bee8 in __libc_waitpid (Cannot access memory at address 0x3
pid=11419, stat_loc=0x7efa8d10, options=0) at ../sysdeps/unix/sysv/linux/waitpid.c:40

Thread 2 (Thread 0x75bff430 (LWP 11418)):
#0  0x76e39a40 in do_futex_wait (isem=isem@entry=0x3181a4) at ../nptl/sysdeps/unix/sysv/linux/sem_wait.c:48
#1  0x76e39af4 in __new_sem_wait (sem=0x3181a4) at ../nptl/sysdeps/unix/sysv/linux/sem_wait.c:69
#2  0x00219f98 in mono_sem_wait ()
#3  0x0019091c in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Thread 1 (Thread 0x76f4a000 (LWP 11417)):
Cannot access memory at address 0x3
#0  0x76e3bee8 in __libc_waitpid (pid=11419, stat_loc=0x7efa8d10, options=0) at ../sysdeps/unix/sysv/linux/waitpid.c:40
#1  0x000c0ba4 in ?? ()
Cannot access memory at address 0x3
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

=================================================================
Got a SIGABRT while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================

Aborted

Any idea ?
If needed I can provide my project.
I put the 3 folders in my USBkey (AdvancedHMI, AdvancedHMIControls, AdvancedHMIDrivers) and the project file.
Then I run : sudo mono AdvancedHMI.exe from AdvancedHMI/bin/debug/.
My project includes the modbus TCP driver (but unused), a SQL database for the login page and... nothing else special.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: AdvancedHMI on a Raspberry Pi
« Reply #57 on: July 12, 2016, 01:22:08 PM »
Hello,

I juste made a little interface (2 buttons and a login page) to test it with my raspberry Pi. The goal is to implement a full HMI working in modbus TCP with a PLC.

But then when I try to run it, after 2 secondes AvcancedHMI.exe crashes.

Here is the error I get in the console :

Code: [Select]
* Assertion at mini-codegen.c:807, condition `i == sel' not met

Stacktrace:

  at <unknown> <0xffffffff>
  at System.Windows.Forms.TextBoxBase.Draw (System.Drawing.Graphics,System.Drawing.Rectangle) <0x000ab>
  at System.Windows.Forms.TextBoxBase.OnPaintInternal (System.Windows.Forms.PaintEventArgs)
 
Any idea ?
This seems like a Mono/Winforms issue. Try creating a new Windows Form project in Visual Studio, add just a TextBox to the form, then see if you get the same problem.

DanieLoche

  • Guest
Re: AdvancedHMI on a Raspberry Pi
« Reply #58 on: July 13, 2016, 04:12:50 AM »
Hello,

Yes I have the same issue. It looks like it's due to the text box... (it's the only thing that is not loaded before the application's crash)


Edit : after some researches I found some topics on the subject. There's an issue with versions under 3.10 of mono that could not handle textbox and its derivatives.

I'm having a hard time finding the tricks to update mono as apt-get gives me version 3.2...
« Last Edit: July 13, 2016, 06:44:24 AM by DanieLoche »

Mikefly95

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
Re: AdvancedHMI on a Raspberry Pi
« Reply #59 on: July 13, 2016, 10:54:44 AM »
Has anyone tried Windows 10 IoT on the Pi with AHMI?