Sample Serial Communication Program with PLC

1.  Visual BASIC 6/ VB 2008 Express Serial Communication Sample Program.
2.  Visual BASIC 6 to TLServer Communication DLL - submitted by user Mr Bruce Scow
3.  Visual Basic.NET Sample Program - submitted by user Mr Julian Stone of United Kingdon
4.  Serial communication using Apple Macintosh's UNIX system calls and POSIX library
   
- submitted by user Mr Fran Jarnjak of USA.

1. Visual BASIC 6 /VB2008 Express Serial Communication Sample Program

VBsample1.gif (9619







    bytes)

The above sample program is created using Visual Basic 6.0 that supports the MSComm controls. An alternative example is also created using Visual Basic 2008 Express (free download from Microsoft website) which uses the .NET frame to support the Serial I/O object.

This program lets you define the serial port, baud rate and comm format. It will then take your command string and send it to the PLC and obtain a response string from the PLC and display on the response box. It takes care of time-out (user- definable) and will not block the program if the PLC is not present.   We have tested it on a H-series as well as M-series PLC and it works well.  Please feel free to email to support@tri-plc.com if you have any feedback or suggestions.

Visual BASIC 6.0 Sample :

SerialComm.Zip

Visual BASIC 2008 Express Sample :

SerialComm-VB2008Express.zip

You can easily include this form into your project and display it for user to set the communication parameters as well as perform some quick test of the communication with the PLC. The full source code is provided for your convenience if you wish to make any modifications. There are a 3 public functions defined in this sample file which you can call from your own application programs directly:

1

Public Function sendCommand (cmd As String)

You supply the entire command string in "cmd" and call this function to send out the command to the PLC. It will then wait to the return the response string received from the PLC or if time-out, it will return an empty string to the caller. If "cmd" is supplied without the "@" sign, it will treat the cmd as a point-to-point command and automatically handle the "Ctrl-E" protocol handshaking.

 

2

 Public Function AppendFCS (ID As Integer, cmd As String)

This function converts a point-to-point command (without the "*" terminator) into a multi-point one. It first adds the "@nn" to the "cmd" string where nn is the ASCII hex representation of the ID, the FCS for the resultant string is then computed and appended to the end of the "@nn"+cmd string, followed by the "*" character.

E.g. command = AppendFCS(1, "RI00")

The variable "command" will receive the resultant string "@01RI005A*".

3

 Public Function computeFCS (cmd As String)

This function computes the FCS of a given string "cmd". It is used by the AppendFCS function and is may also be used by the user to verify the integrity of a received response string.

 

2. Bruce Scow of Shanghai Contributed the following DLL for connecting to TLServer

VISUAL BASIC TLServer Communication DLL

 

3. Julian Stone of The United Kingdom Contributed the following application notes:

VISUAL BASIC .NET Comm with M-series PLCs

 

4. Fran Jarnjak of USA Contributed the following application notes:

Apple Macintosh UNIX  Comm with M-series PLCs