Author Topic: SEND PLC DATA TO OTHER COM PORT  (Read 3674 times)

joko markono

  • Full Member
  • ***
  • Posts: 132
    • View Profile
SEND PLC DATA TO OTHER COM PORT
« on: September 04, 2019, 03:59:57 AM »
Hi Guys,

My PLC is connected to serial COM1, and i want to send out the displayed/collected data (as a single line data string) to serial COM2.
How can i do that in AHMI?
« Last Edit: September 04, 2019, 04:21:13 AM by joko markono »

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: SEND PLC DATA TO OTHER COM PORT
« Reply #1 on: September 04, 2019, 03:18:21 PM »

joko markono

  • Full Member
  • ***
  • Posts: 132
    • View Profile
Re: SEND PLC DATA TO OTHER COM PORT
« Reply #2 on: September 05, 2019, 01:57:28 AM »
ok, actually i imported some code from
https://github.com/bartashevich/serial-communication
I'm not very sure if my way of combining the PLC data (as you can see from 'SendTextBox' is correct. I actually just plus both data like this:

SendTextBox.Text = BasicLabel1.Text + BasicLabel2.Text

But so far the program is running fine. Here is the code for my DataPanelForm:
Code: [Select]
Public Class DataPanel

    Dim Data_received As String

    '*******************************************************************************
    '* Stop polling when the form is not visible in order to reduce communications
    '* Copy this section of code to every new form created
    '*******************************************************************************
    Private NotFirstShow As Boolean

    Private Sub Form_VisibleChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.VisibleChanged
        '* Do not start comms on first show in case it was set to disable in design mode
        If NotFirstShow Then
            AdvancedHMIDrivers.Utilities.StopComsOnHidden(components, Me)
        Else
            NotFirstShow = True
        End If
    End Sub

    Private Sub ReturnToMainButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        MainForm.Show()
        ' Me.Hide()
        Me.Visible = False
    End Sub

    Private Sub MessageListByItem1_SelectedIndexChanged(sender As Object, e As EventArgs)

    End Sub

    Private Sub MessageListByValue1_SelectedIndexChanged(sender As Object, e As EventArgs)

    End Sub

    Private Sub SendTextBox_TextChanged(sender As Object, e As EventArgs) Handles SendTextBox.TextChanged
        'combined data = data1 + data2 + data3 + .....
        SendTextBox.Text = BasicLabel1.Text + BasicLabel2.Text

    End Sub

    Private Sub DataPanel_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Timer1.Interval = 300
        Timer1.Enabled = False

        ModuleComPortParameters.configuration_is_valid = False
        SendBtn.Enabled = False
    End Sub

    Private Sub ConfigurePortBtn_Click(sender As Object, e As EventArgs) Handles ConfigurePortBtn.Click
        ConfigurationPort.StartPosition = FormStartPosition.CenterParent
        ConfigurationPort.ShowDialog()

        If ModuleComPortParameters.configuration_is_valid = True Then
            With SerialPort1
                .PortName = ModuleComPortParameters.Port
                .BaudRate = ModuleComPortParameters.Baudrate
                .Parity = ModuleComPortParameters.Parity
            End With
        End If
    End Sub

    Private Sub ExitBtn_Click(sender As Object, e As EventArgs) Handles ExitBtn.Click
        End
    End Sub

    Private Sub OpenPortBtn_Click(sender As Object, e As EventArgs) Handles OpenPortBtn.Click
        If ModuleComPortParameters.configuration_is_valid = True Then
            If SerialPort1.IsOpen Then
                SerialPort1.Close()
                SendBtn.Enabled = False
                OpenPortBtn.Text = "Open Port"
                OpenPortBtn.BackColor = Color.LightGray
                Timer1.Enabled = False
            Else
                SerialPort1.Open()
                SendBtn.Enabled = True
                OpenPortBtn.Text = "Close Port"
                OpenPortBtn.BackColor = Color.Red
                Timer1.Enabled = True
            End If
        Else
            MsgBox("Cannot open port with an invalid configuration")
        End If
    End Sub

    Private Sub SendBtn_Click(sender As Object, e As EventArgs) Handles SendBtn.Click
        SerialPort1.Write(SendTextBox.Text)
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Data_received &= SerialPort1.ReadExisting
        If Len(Data_received) > 0 Then
            ReceiveTextBox.Text = Data_received
            HistoryTextBox.Text = TimeOfDay.ToLongTimeString + " : " + Data_received + vbNewLine + HistoryTextBox.Text
            Data_received = ""
        End If
    End Sub
End Class


and this the code for the ConfigurationPort:
Code: [Select]
Public Class ConfigurationPort
    Private Sub Port_Conf_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim available_Ports As Array = IO.Ports.SerialPort.GetPortNames
        Dim i As Integer

        For i = 0 To UBound(available_Ports)
            PortComboBox.Items.Add(available_Ports(i))
        Next

        BaudrateComboBox.Items.Clear()
        BaudrateComboBox.Items.Add("4800")
        BaudrateComboBox.Items.Add("9600")
        BaudrateComboBox.Items.Add("19200")
        BaudrateComboBox.SelectedIndex = 2

        ParityComboBox.Items.Clear()
        ParityComboBox.Items.Add(IO.Ports.Parity.None)
        ParityComboBox.Items.Add(IO.Ports.Parity.Odd)
        ParityComboBox.Items.Add(IO.Ports.Parity.Even)
        ParityComboBox.SelectedIndex = 2

    End Sub

    Private Sub Cancel_Btn_Click(sender As Object, e As EventArgs) Handles CancelBtn.Click
        ModuleComPortParameters.configuration_is_valid = False
        Me.Close()
    End Sub

    Private Sub Ok_Btn_Click(sender As Object, e As EventArgs) Handles OkBtn.Click
        ModuleComPortParameters.Port = PortComboBox.Text
        ModuleComPortParameters.baudrate = BaudrateComboBox.Text

        Select Case ParityComboBox.Text
            Case "None"
                ModuleComPortParameters.parity = IO.Ports.Parity.None
            Case "Even"
                ModuleComPortParameters.parity = IO.Ports.Parity.Even
            Case "Odd"
                ModuleComPortParameters.parity = IO.Ports.Parity.Odd

        End Select
        ModuleComPortParameters.configuration_is_valid = True

        Me.Close()
    End Sub

    Private Sub Port_combo_SelectedIndexChanged(sender As Object, e As EventArgs) Handles PortComboBox.SelectedIndexChanged

    End Sub
End Class

The results is shown in the attachment. I just need to know if the way i combined the data is correct. Currently i don't have my PLC data connected.

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: SEND PLC DATA TO OTHER COM PORT
« Reply #3 on: September 05, 2019, 02:39:59 AM »
It's usually "&" instead of "+", but if it works then good.

com0com program is free and for virtual ports is usually the best choice, you can find the link here:

https://www.advancedhmi.com/forum/index.php?topic=1961.0

I'm not sure if your Eltima software is free.

joko markono

  • Full Member
  • ***
  • Posts: 132
    • View Profile
Re: SEND PLC DATA TO OTHER COM PORT
« Reply #4 on: September 05, 2019, 10:06:02 PM »
i have problem to read to incoming data.
there is no display on the textbox.
I notice the data has a kind of weird format like these:

$PPTIROV (NMEA 0183 format)

is there a way i can assigned the format (any type) in the beginning of my receiving text box?
Some other data start with different format like "$NORCLOG", ":" , "$", etc....

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: SEND PLC DATA TO OTHER COM PORT
« Reply #5 on: September 06, 2019, 01:45:42 AM »
This sounds like something Archie would have to decipher.

Maybe a new driver might need to be created for NMEA 0183 protocol.

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: SEND PLC DATA TO OTHER COM PORT
« Reply #6 on: September 06, 2019, 01:59:47 AM »
The last page of this document shows that "weird" format:

http://linux.geodatapub.com/shipwebpages/winfrog-all/WinFrog%203.10/Documents/WinFrog%203.10%20User%27s%20Guide/WFUG%20App%20C%20-%20Device%20Documentation/ROV/PerryTritec.pdf

The best thing you can do is provide all the details of your setup and devices.

joko markono

  • Full Member
  • ***
  • Posts: 132
    • View Profile
Re: SEND PLC DATA TO OTHER COM PORT
« Reply #7 on: September 06, 2019, 02:14:12 AM »
i have a terminal protocol software which was created in JAVA that can read any data format by assigning the format in initial place. unfortunately it's not in VB. you can see the attachment. my main target is actually to implement the same function into the AHMI.

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: SEND PLC DATA TO OTHER COM PORT
« Reply #8 on: September 06, 2019, 02:37:59 AM »
Just by looking at config.txt file, this might have a simple solution in VB (this is just a wild guess).

What you should do is examine the exact data you are receiving and post it here.
Since your program is already communicating with a device it might just be a matter of deciphering the data.

joko markono

  • Full Member
  • ***
  • Posts: 132
    • View Profile
Re: SEND PLC DATA TO OTHER COM PORT
« Reply #9 on: September 06, 2019, 03:24:54 AM »
as shown in the attachment, my device input is from COM1 and output is COM6 to my AHMI. (the output format that you see on COM6 has been modified from the JAVA software setting as what i like it to be, so not to bother much. i can set the output to be exactly the same as the input).

so far no output turn out on the AHMI software that i created.

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: SEND PLC DATA TO OTHER COM PORT
« Reply #10 on: September 06, 2019, 04:25:16 AM »
Is your Java software closed when you try to use AHMI?

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: SEND PLC DATA TO OTHER COM PORT
« Reply #11 on: September 06, 2019, 04:36:48 AM »
You need to understand that you are not providing enough details about your setup.

The first issue you need to resolve is the communication between AHMI and your device.

joko markono

  • Full Member
  • ***
  • Posts: 132
    • View Profile
Re: SEND PLC DATA TO OTHER COM PORT
« Reply #12 on: September 06, 2019, 05:03:31 AM »
Please see the attachment on my current setup.
As i mentioned, the reason i want to make the build in read/write serial port software into AHMI is to eliminate the JAVA PC.
Since now the only way i can see there is data is using the JAVA, that's why i use this setup.
the JAVA is always open in order to send/receive data.
« Last Edit: September 06, 2019, 05:10:17 AM by joko markono »

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: SEND PLC DATA TO OTHER COM PORT
« Reply #13 on: September 06, 2019, 01:02:19 PM »
Here is how I understand it:

AHMI normally uses one of its drivers to establish communication to a device and collect data from it.

In your case, there is no AHMI driver that can communicate with your device marked "device that sends the data".

The reading would have to be done through VB code and collected data would have to be manually sorted and provided to AHMI controls and also sent to Omron PLC (if that's your intention). So, in your code, when you open the serial port then you have to do the reading and not writing.


Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: SEND PLC DATA TO OTHER COM PORT
« Reply #14 on: September 06, 2019, 05:16:31 PM »
If you do manage to read the data then examine it and compare to the Java data.

If you can communicate to the person that created the Java program then ask for more information on the data format.
Everything kind of looks like a standard serial protocol communication.