Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - bachphi

Pages: 1 ... 3 4 [5] 6
61
Open Discussion / Need some help with SQL
« on: April 03, 2017, 07:02:23 PM »
I have 2 tables: TABLE1 with id, SerialNumber, PassFail, Data1, Data2, etc.....
                       TABLE2 with id, SerialNumber, PassFail.

As TABLE1 get updated by "insert" from app, I would like TABLE2 to be updated with the latest info.
Can this be done  with a SQL script or stored procedure automatically? 
TIA.

62
Open Discussion / DataSet and ComboBox
« on: March 27, 2017, 02:24:45 PM »
I created a local DB file [DB_Product.mdf]  and a DataSet [DB_ProductDataSet.xsd]
Inside the db, I created a table [TB_PartSpec] that contains: Id, PartName, PartNumber, PressureLoLim, ....

On the MainForm, an Add/Change button will ShowDialog of Page2, where you can add/change Part specs.
Also on the mainform is a combobox to select PartName. The combobox is bound to the table as shown below:



In order to display part details associated with the PartName selected from the combobox, I use its IndexChanged event:
Code: [Select]
If ComboBox1.SelectedValue IsNot Nothing Then
            Label2.Text = DB_ProductDataSet.TB_PartSpec.FindById(ComboBox1.SelectedValue).PartNumber
            Label3.Text = DB_ProductDataSet.TB_PartSpec.FindById(ComboBox1.SelectedValue).PressureLoLim
            Label4.Text = DB_ProductDataSet.TB_PartSpec.FindById(ComboBox1.SelectedValue).PressureHiLim
        End If

This works for me, and the values will be written to PLC later, but I wonder if you would have a better way to handle this.
TIA.

63
Support Questions / Displaying more than one picture
« on: March 10, 2017, 11:27:29 AM »
I currently have a DataSubscriber with DataChanged event. Depending on the value , it will display the selected picture.
Code: [Select]
Private Sub DataSubscriber1_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber1.DataChanged

        Select Case e.Values(0)
            Case "0"
                PictureBox2.BackgroundImage = My.Resources.AdvancedHMILogoBR
            Case "1"
                PictureBox2.BackgroundImage = My.Resources.AdvancedHMILogoBR
            Case "2"
                PictureBox2.BackgroundImage = My.Resources.AdvancedHMILogoBR
            Case "3"

Now, let's say when it's case "1", I'd like to display more than one picture, that is pic1 for 2 seconds, pic2 for 2 seconds, then repeat the sequence as long as the value is still at "1"
so I modified case "1" like below:
Code: [Select]
Case "1"
        While e.Values(0) = 1
            PictureBox2.BackgroundImage = My.Resources.Pic1
            Application.DoEvents()
            Sleep(2000)
            PictureBox2.BackgroundImage = My.Resources.Pic2
            Application.DoEvents()
            Sleep(2000)
        End While
      
This works as intended, but as my e.values changes, different pictures are not displaying. Do you see anything wrong with the code? TIA

64
Archie,

The ConnectionEstablished event in SerialDF1forSLCMicroCom1 driver did not seem to work. I put a msgbox in the event to see if it fire, but nothing pop up. I am using 399v.
Thanks.

65
Support Questions / PilotLight3Color & Lightcolor property
« on: February 20, 2017, 09:14:38 AM »
I am not sure if this is by design or what , but I am confused.
When select PLCAdressSelectColor2 it actually turned on LightColorOff




66
Open Discussion / Tested on Mono on Linux (except OPC driver)
« on: February 14, 2017, 04:26:39 PM »
I just saw this from the web site:
https://sourceforge.net/projects/advancedhmi/

Should the  Serial DF1 driver  be excluded on the list as well?

67
Open Discussion / 10" INDUSTRIAL PANEL PC WITH WINDOWS FOR HMI
« on: February 02, 2017, 09:48:47 AM »
I just noticed you now have the 10"" AIO PC on your web site.  Do you have something bigger like 15/17"?
Also 2GB  RAM maynot be enough , is there an option to add more?
256GB SSD is more than what we need for PC resides on the floor, 64 or 128 GB?
Windows 10, is it avail with 32 bit version?  and windows 7?

68
Open Discussion / Solution for Pi + mono AAHMI + ML1000 ??
« on: January 17, 2017, 04:37:47 PM »
is there a solution to the Pi USB-Serial?. My app is very simple , just the serial driver with a basic label. I verified it works with PC, but not with Pi

1. I verified that USB-serial adapter is attached to /dev/ttyUSB0 with dmesg
Code: [Select]
pi@raspberrypi:~ $ dmesg | grep FTDI
[    2.115733] usb 1-1.4: Manufacturer: FTDI
[    5.043141] usbserial: USB Serial support registered for FTDI USB Serial Device
[    5.043434] ftdi_sio 1-1.4:1.0: FTDI USB Serial Device converter detected
[    5.044668] usb 1-1.4: FTDI USB Serial Device converter now attached to ttyUSB0

2.  use Godra's mono GetSerial showed that it is /dev/ttyUSB0:
Code: [Select]
pi@raspberrypi:~ $ mono getserial.exe
/dev/ttyUSB0

3. Tried set access permission:
Code: [Select]
sudo chmod 777 /dev/ttyUSB0
4.  Tried set logical link with:
Code: [Select]
sudo ln -s /dev/ttyUSB0 COM1
5. Also tried adding this:
Code: [Select]
sudo nano /etc/modules   // use lsusb to see product id & vendor
sudo modprobe usbserial vendor=0x0403 product=0x6001

69
Open Discussion / Nuget Package like EPplus
« on: October 14, 2016, 06:26:55 PM »
Does anyone know of such a nuget package that can do chart, like Farpoint Spread by GrapeCity? TIA

70
Open Discussion / BackGround Worker from hell
« on: August 22, 2016, 10:44:56 AM »
Up until yesterday, I did not know who the heck the BackGround worker is, nor what exactly he's supposed to be doing... so say HELLo to my new BackGround worker. ;).

In my project, after scanning the barcode, I need to check if the SerialNumber exist in the SQL DB, if it is then display the data in the DataGridView , next call up the keypad and enter some number.  Since checking the DB does takes a few seconds, my display would freeze up before the keypad can appear. So I thought,  it would be nice if I can enter my number while its doing the check.
To avoid the problem of cross-threading call, I added a  BackGroundWorker to my form, start calling it with
Code: [Select]
        dgvData.DataSource = Nothing
        dgvData.Rows.Clear()
        BGW1.RunWorkerAsync()                           'Using BGW to check if Serial exist

This worker has 3 events associated with it: DoWork, ProgressChanged and RunWorkerCompleted. The DoWork will do the heavy lifting and the Progress or Completed will allow you to set the DataGridView from the original UI thread!!

Here is the code:

Code: [Select]
Private Sub BGW1_DoWork(sender As Object, e As ComponentModel.DoWorkEventArgs) Handles BGW1.DoWork
        If SQL.HasConnection = True Then
            SQL.RunQuery("SELECT * FROM TB01_DP_TestData WHERE [SerialNumber] = '" & StaSerialNumber & "'")
        End If     
End Sub

Private Sub BGW1_ProgressChanged(sender As Object, e As ComponentModel.ProgressChangedEventArgs) Handles BGW1.ProgressChanged
       
End Sub

Private Sub BGW1_RunWorkerCompleted(sender As Object, e As ComponentModel.RunWorkerCompletedEventArgs) Handles BGW1.RunWorkerCompleted
        If SQL.DS.Tables.Count > 0 Then                 'Returning from the call
            If SQL.DS.Tables(0).Rows.Count > 0 Then     'IF SerialNumber exist
                dgvData.DataSource = SQL.DS.Tables(0)
                'Label9.Text = SQL.DS.Tables(0).Rows(0).Item(2)
            Else
                'MsgBox("Not FOund")
            End If
        End If
End Sub

71
Support Questions / Keypad and problem with Min, Max Values
« on: August 11, 2016, 03:56:45 PM »
I tried setting up a keypad with min, max values, but it keep saying the value I entered is not within the range(92, 125), eventhough it is . I tried to add CDbl or Cint, since they are real numbers from PLC, but with the same result.
It works fine without the min, max range

Code: [Select]
Private Sub EnterTipNumber()
        Dim kpd As New MfgControl.AdvancedHMI.Controls.Keypad
        kpd.Font = New Font("Arial", 12, FontStyle.Bold)
        kpd.ForeColor = Color.AliceBlue
        kpd.Text = "Enter Tip Number:"
        kpd.MaxValue = CInt(PLC.Read("Sta0xPart.TipRange.HiLimit"))
        kpd.MinValue = CInt(PLC.Read("Sta0xPart.TipRange.LoLimit"))
        If kpd.ShowDialog = Windows.Forms.DialogResult.OK Then
            PLC.Write("Sta0xPart.TipRange.Value", kpd.Value)
        End If
    End Sub

72
Support Questions / capturing HEX data of serial port continuously
« on: July 25, 2016, 11:47:11 AM »
I have a device that continuously sending hex data messages. The message format consist of MessageID, one or more parameters and checksum. The checksum is a 2's complement 8-bit checksum. 
On my DataReceived event, I validate the checksum condition, then display its data in a text box. But not all data is displayed. I think it is suffering the condition that was mentioned here http://www.sparxeng.com/blog/software/must-use-net-system-io-ports-serialport

I am not quite able to translate the code to VB using the online converter.

Here is my current code:

Code: [Select]
Dim RXArray() As Char ' Text buffer. Must be global to be accessible from more threads.
Dim RXCnt As Integer      ' Length of text buffer. Must be global too.

    Private Sub ComPort_DataReceived(sender As Object, e As SerialDataReceivedEventArgs) Handles ComPort.DataReceived
        Dim nbytes As Integer = ComPort.BytesToRead
        Dim comBuffer() As Byte = New Byte(nbytes - 1) {}        'create a byte array to hold the awaiting data
        ComPort.Read(comBuffer, 0, nbytes)                       ' {179,254,128,25,170,12}

        Dim intChkSum As Integer = 0                               'validate received data
        For i As Integer = 0 To nbytes - 1
            intChkSum = (intChkSum + comBuffer(i)) And &HFF
        Next
        If intChkSum = 0 Then
            'RXArray = Bytes2Hex(comBuffer)
            RXArray = BitConverter.ToString(comBuffer).Replace("-", " ").ToCharArray()   'B3 FE 80 19 AA 0C'
            RXCnt = RXArray.Length
        Else
            Exit Sub
        End If

        Me.Invoke(New MethodInvoker(AddressOf Display))

    End Sub

Private Sub Display()
        'Received.AppendText(New String(RXArray, 0, RXCnt) & Environment.NewLine)
        Received.AppendText(New String(RXArray, 0, RXCnt) & vbCrLf)
    End Sub

Could someone out there help me, please. Thanks!

73
Support Questions / Converting byte array to char array
« on: July 21, 2016, 09:48:06 PM »
I'd like to convert byte array to char array. Below is what I have:
Code: [Select]
       Dim nbytes As Integer = COMPort.BytesToRead
        Dim comBuffer() As Byte = New Byte(nbytes - 1) {}        'create a byte array to hold the awaiting data
        COMPort.Read(comBuffer, 0, nbytes)                       ' {179,254,128,25,170,12}
        Dim charArray() As Char
        Dim strTemp As String = ""
        strTemp = BitConverter.ToString(comBuffer).Replace("-", " ")    'BE FE 80 19 AA 0C
        charArray = System.Text.Encoding.ASCII.GetString(comBuffer).ToCharArray()
I can do charArray = strTemp.ToCharArray() but would like to avoid using strTemp if possible.
I need charArray looks to be the same strTemp that is 'BE FE 80 19 AA 0C'. Thanks.

74
Open Discussion / Function to Compute checksum of a hex string
« on: July 17, 2016, 04:21:04 PM »
It is a 2's complement 8-bit checksum. The string only contains [0-9,A-F], and is an even number of characters. Checksum is calculated by adding the byte values in the hex string,  negating, then masking the lowest 8-bits, finally add 1 to it. Checksum can then be added to the cmdString later. Let me know if you have a better way. Thanks.

Code: [Select]
' CmdString = "B6FE8019AA"
Private Function ComputeCheckSum(ByVal HexString As String) As String

        Dim ReturnValue As String 'Return value is 2-dig hex value representing the checksum
        Dim intchecksum As Integer = 0

        For i As Integer = 0 To HexString.Length - 1 Step 2
            Dim value As Integer = Integer.Parse(HexString.Substring(i, 2), NumberStyles.AllowHexSpecifier)
            intchecksum = (intchecksum + value) And &HFF
        Next
        ReturnValue = Hex(256 - intchecksum)                                      'instead of negating and add 1
        If Len(ReturnValue) = 1 Then ReturnValue = "0" & ReturnValue    'Make sure each converted byte value is 2 digits

        ComputeCheckSum = ReturnValue        '09

    End Function

To check if the message  was transmitted correctly: B6+FE+80+19+AA+09 = 300 
 (300 AND &0xFF) should equal 0
 
    A 'simple' 8-bit checksum per Markem-Imaje is actually a one complement checksum. The above routine can still be used, just change 256 to 255   


75
Support Questions / Populate combobox with PartNumbers from PLC
« on: July 12, 2016, 03:51:51 PM »
I would like to populate a combobox with part numbers from PLC.  The part numbers are UDT like below:

Partnum[0].PartNumber = '1234'                          'string
Partnum[1].PartNumber = '2345'                          'string
.....

Is there a good way that is similar to getting Com ports into combobox

Code: [Select]
myPort = IO.Ports.SerialPort.GetPortNames()       
 For i = 0 To UBound(myPort)
        cmbPort.Items.Add(myPort(i))
 Next
 cmbPort.Text = cmbPort.Items.Item(0)   

Pages: 1 ... 3 4 [5] 6