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 [2] 3 4 ... 6
16
Open Discussion / SQL REPLACE command
« on: June 13, 2020, 09:42:21 AM »
I have a Barcode column with some data like below:

Z1B1S1A           -- Zone 1 Bay 1 Shelf 1A
Z10B10S10B      -- Zone 10 Bay 10 Shelf 10B

want to replace them with:
01-01-01A          -- I think I can get by with  1-1-1A
10-10-10B

The zone , bay , shelf can go from 1 to 99. The problem for me is the inconsistent with 1 or 2 digit, and the last char 'B' can be mistaken for the Bay number.

Code: [Select]
SELECT Barcode, REPLACE(Barcode, '[Z]{1}[0-9]{1,2}[B]{1}[0-9]{1,2}[S]{1}%', 'X') AS NewBarcode
FROM TB_BarcodeTag

Thank you for any help.

17
Open Discussion / Start a process in minimized state
« on: June 02, 2020, 08:38:36 AM »
I have the code below to start a process in minimized state. It does work
Code: [Select]
            Dim psi As New ProcessStartInfo("notepad")
            psi.WindowStyle = ProcessWindowStyle.Minimized
            Process.Start(psi)

I want to combine them into one line, it start the process but not in minimized state. how do I fix this? TIA

Code: [Select]
Process.Start("notepad").StartInfo.WindowStyle = ProcessWindowStyle.Minimized

18
Tips & Tricks / Excel Remove Blank Rows From ALL Worksheets
« on: May 29, 2020, 09:53:17 AM »
While there are many solutions found by Google search, some of the solutions are potentially dangerous, some are painfully slow.
I found the code below works best:
Code: [Select]
Sub AllSheets()
 Dim ws As Worksheet
 For Each ws In Worksheets
With ws.UsedRange
'Not using first row
.Sort Key1:=.Range("A2"), Order1:=xlAscending, _
Key2:=.Range("B2"), Order2:=xlAscending, _
Key3:=.Range("C2"), Order3:=xlAscending, _
Header:= _
xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
xlSortNormal
End With
 Next ws
End Sub

19
Tips & Tricks / Finding ip address of an RTA module
« on: May 06, 2020, 01:59:02 PM »
RTA 435NBA, 435NBX is a great device for communicating between ASCII device and Controllogix PLC.
Normally, you can find the module ip address by running the IPSetup tool.

If not, you can reset it to factory default by using the pin hole or open up the box inside there is a reset button.

If that still does not work, then connect serially to port 0 using a null modem cable and run MTTTY tool and click connect.
Next, cycle the power and you will see its ip address:


20
Tips & Tricks / OPEN SOCKET FROM PLC TO a FTP server.
« on: April 19, 2020, 09:14:35 AM »
OPEN SOCKET FROM PLC TO a  FTP server.

1. FTP server can be enabled using Features in windows 10.
2. However, I want to use a portable FTP server.
3. BabyFTP seemed like a good candidate, but it stuck in binary mode and failed to create data socket
4. Xlight FTP, (rfc 959 IMPLEMENTATION) is my next candidate.
   First, add a new virtual server.
   Global Options include Install as service, deny/allow IP_address, Bandwidth limit, Firewall & broadband router, SSL certificate, ODBC DB config, Remote admin, logging even log to a DB. I am impressed! What a gem.
   Create a user or anonymous user with home directory.
   Hit Play to start the server.

From PLC, open socket to the target with port 21, then send commands
 // Not needed if send directly from PLC, Testing with Hercules
Code: [Select]
OPEN 192.168.0.44   
Response = 220 Xlight FTP Server 3.9 ready...

Your socket program need to check the response and act on it that is to give the USER as next command

Code: [Select]
USER ANONYMOUS$0D$0AResponse = 331 Anonymous login OK, send your e-mail as password

Code: [Select]
PASS FTP$0D$0AResponse = 230 Login OK

(not need TYPE ASCII)

Code: [Select]
EPSV$0D$0A              
229 Entering Passive Mode (|||54732|)

PLC needs to parse out and retain the port 54732

Code: [Select]
RETR TestData.txt$0D$0A150 Opening BINARY mode data connection for TestData.txt (30 bytes).

At this point, I need to connect to the data socket channel on port 54732 to view the content of the file:

Connected to 192.168.0.44
#CR#LF#CR#LFTHIS IS A TEST 99999  #CR#LF#CR#LF

Finally, parse the content to string tag




21
Open Discussion / Portable gem find XAMPP
« on: April 19, 2020, 08:02:02 AM »
came accross the portable app, I thought it's worth mentioning.

XAMPP is an integrated server package that contains many different tools such as mail, Web, FTP and WebDAV. Various open software packages are combined to power the various services including Apache, MariaDB, FileZilla, PHP, JSP Java, OpenSSL and more. Tomcat and Perl can be added using add-ons available from the website.

Note: XAMPP has many capabilities, including a portable MediaWiki or Wordpress installation.

22
Open Discussion / Send a message to multiple controllers
« on: April 14, 2020, 07:47:29 PM »
In the Logix 5000 Controllers Messages programming manual, Rockwell devoted a whole chapter to sending
message to mutiple controllers. The idea behind it was using just a single message instruction to communicate
with different controllers.
However, the chapter was written badly, incomplete and in some cases it was wrong as well.
Below is my take on sending message to  mutiple controllers. Hope that it will be usefull for someone in someday.
Any comments  or suggestions are super welcome.




23
Open Discussion / Symbol Factory with different Image file formats
« on: April 03, 2020, 12:05:53 PM »
From Symbol Factory, I exported some symbols to different image file formats like bmp, gif, jpg, png and svg. 
Size wise, bmp format retains her crown title. 
Little did I know, a unfamiliar svg format with smaller footprint stand out from the rest as shown in attached file.

24
Support Questions / Add comment to ini file
« on: March 15, 2020, 01:42:25 PM »
How do I add comment to the ini file ?

I tried a variety without success.

25
Tips & Tricks / INI file parser
« on: January 11, 2020, 10:26:53 AM »
I did not know that Archie already included a file-parser in AHMI, so I use Nuget to download a parser for ini file, Ini-Parser by Ricardo is what I chose. There are so many similar things in Nuget that makes it difficult to chose
which is the right package for what you need.

Anyway, it's easy to use

Code: [Select]
Imports IniParser
Imports IniParser.Model

    Dim parser = New FileIniDataParser()
    Dim parsedData As IniData = parser.ReadFile(".\Settings.ini")

...

Dim ZebraAddress As String = parsedData("Zebra")("Address")                'Section, KeyName

26
Open Discussion / Translating C#
« on: December 27, 2019, 02:47:56 PM »
How'd you translate these C# codes to VB? Thanks.
Code: [Select]
private static Settings _instance;
public static Settings Instance
        {
            get { return _instance ?? (_instance = new Settings()); }
        }

Code: [Select]
Private Shared _instance As Settings   
Public Shared ReadOnly Property Instance As Settings
        Get
            If (_instance Is Nothing) Then
                _instance = New Settings
            End If
           
            Return _instance
        End Get
End Property

27
Open Discussion / Clear a string array in RSLogix 5000
« on: December 16, 2019, 02:52:59 PM »
How do you clear an entire string array in RSLogix 5000 without creating another empty/null string array? STR_ARRAY[10]

I currently use FAL to do the job, but wondering if there is another way.

28
Open Discussion / Modbus Simulator
« on: December 07, 2019, 06:33:10 AM »
Is there a modbus simulator that can do master/slave similar feature like Hercules do client/server? TIA.

29
Open Discussion / Path for IniFileName under mono environment
« on: September 02, 2019, 04:46:14 PM »
Does anyone know what path to use for IniFileName under mono?

I have tried "." , "./" , ".\" and just the filename only.
Currently , to get it working, I use its absolute path which is sort of lame.

30
Open Discussion / Thread Safe Controls Translation
« on: April 20, 2019, 02:29:52 PM »
I am trying to translate some C# codes to VB, it seemed to work, but want to check if it's alright or some improvement ideas.  TIA.

Code: [Select]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ThreadSafeControls
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            label1.CustomInvoke(l => l.Text = "Thread Safe Controls");

        }
    }
    public static class MyInvoke
    {
        public static void CustomInvoke<T>(this T @control, Action<T> toPerform) where T : ISynchronizeInvoke
        {
            if (@control.InvokeRequired)
                @control.Invoke(toPerform, new object[] { @control });
            else
                toPerform(@control);
        }
    }
}



and the VB code that I translated :

Code: [Select]

Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports System.Windows.Forms

Imports System.ComponentModel

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Label1.CustomInvoke(Sub(l) l.Text = "Thread Safe Controls")
    End Sub
End Class

Public Module MyInvoke
    <System.Runtime.CompilerServices.Extension()>
    Public Sub CustomInvoke(Of T As ISynchronizeInvoke)(control As T, toPerform As Action(Of T))
        If control.InvokeRequired Then
            control.Invoke(toPerform, New Object() {control})
        Else
            toPerform(control)
        End If
    End Sub
End Module

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