Author Topic: Is there a plain old serial port option?  (Read 3135 times)

jgmdesigns

  • Newbie
  • *
  • Posts: 15
    • View Profile
Is there a plain old serial port option?
« on: March 22, 2016, 11:19:00 PM »
Hello,
First post so my apologies if this is not the proper place to pose this question.

I am rather new to Adv. HMI and I am wondering if there is a way I can interface to a simple RS232 port I have on my PC, or usb/232 converter?

From what I see in the drivers everything is PLC specific.

Cheers,
Jim

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Is there a plain old serial port option?
« Reply #1 on: March 23, 2016, 02:22:18 AM »
If you look in the Alll Windows Forms group in the Toolbox, you will find a SerialPort component. It has no connection to AdvancedHMI, so it will be up to you to write code to implement what ever protocol you want and link to the AdvancedHMI visual controls.

jgmdesigns

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Is there a plain old serial port option?
« Reply #2 on: March 23, 2016, 08:48:19 PM »
Thanks!!

How difficult is it to simply send/receive raw bytes?  Is there a tutorial, or example project?  This HMI dev kit is new to me so apologies for the basic questions

JIm

EDIT:
I just put the serial port into the project, and added a Digital panel meter.  In the panel meters properties the comms section only seems to want to see a PLC connection  I would like to connect the panel meter to the serial port.

Another question:  Is there a user manual for all the components in the Toolbox?  If there is I would love to load it local here to reference to.
« Last Edit: March 23, 2016, 08:56:48 PM by jgmdesigns »

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Is there a plain old serial port option?
« Reply #3 on: March 23, 2016, 09:03:23 PM »
The SerialPort is a raw serial port and not a communication driver for AdvancedHMI controls. The drivers need to work off some sort of protocol that is address based. If it just received raw byte data, it would have no idea of how to display it and which controls to send it to.

To send and receive raw bytes, you would be more into .NET programming and not AdvancedHMI development. This may give you some idea about it:

https://tiktakx.wordpress.com/2010/11/21/serial-port-interfacing-with-vb-net-2010/

aquilmustafa

  • Full Member
  • ***
  • Posts: 121
    • View Profile
Re: Is there a plain old serial port option?
« Reply #4 on: March 24, 2016, 12:31:11 PM »
Hi,
Here is a small code to read Serial port raw data like Hyper-terminal to read Barcode data from Serial Port. See if it helps you.

Imports System
Imports System.IO
Imports System.IO.Ports

Public Class BARCODEReader

    Delegate Sub SetTextCallback(ByVal [text] As String) 'Added to prevent threading errors during receiveing of data

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Try
            BarcodePass.Text = ""
            SerialPortSupervisor.Open()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub SerialPortSupervisor_DataReceived(sender As Object, e As SerialDataReceivedEventArgs) Handles SerialPortSupervisor.DataReceived
        ReceivedText(SerialPortSupervisor.ReadExisting()) 'Automatically called every time a data is received at the serialPort
    End Sub

    Private Sub ReceivedText(ByVal [text] As String)
        'compares the ID of the creating Thread to the ID of the calling Thread
        If Me.BarcodePass.InvokeRequired Then
            Dim x As New SetTextCallback(AddressOf ReceivedText)
            Me.Invoke(x, New Object() {(text)})
        Else
            Me.BarcodePass.Text &= [text]
        End If
    End Sub

End class