yc_kok

Hi,

Good day !

I am using NAIS FP01 PLC Training Kit with 8 inputs and 6 outputs.

May I know how to use the VB 2005 SerialPort to turn on and off these PLC inputs

How do I map the COM Command to the SerialPort methods and properties for this purpose

Can you please show me an example using VB 2005

I try not to use ActiveX.

The COM Command of MEWTOCOL examples are:

Table of command

Command name Code Description

Read contact area RC

(RCS)

(RCP)

(RCC)

Reads the on and off status of contacts.

- Specifies only one point

- Specifies multiple contacts.

- Specifies a range in word units.

Write contact area WC

(WCS)

(WCP)

(WCC)

Turns contacts on and off.

- Specifies only one point

- Specifies multiple contacts.

- Specifies a range in word units.

Read data area RD Reads the contents of a data area.

Write data area WD Writes data to a data area.

Read timer/counter set value area RS Reads the value set for a timer/counter.

Write timer/counter set value area WS Writes a timer/counter setting value.

Read timer/counter elapsed value area RK Reads the timer/counter elapsed value.

Thanks.

Regards,

yc_kok



Re: Visual Basic General Use IO.Ports.SerialPort to turn on / off PLC input switch

yc_kok

I found out the following command for VB6,

But What is the equivalent for Visual Basic 2005

:

Dim Instring As String
' Use COM2.
MSComm1.CommPort = 2
' 9600 baud, odd parity, 8 data, and 1 stop bit.
MSComm1.Settings = "9600,O,8,1"
' Tell the control to read entire buffer when Input
' is used.
MSComm1.InputLen = 0
' Open the port.
MSComm1.PortOpen = True
' Send the attention command to the modem.
MSComm1.Output = "%01#RCSY0000**" + Chr$(13)
' Wait for data to come back to the serial port.
Do
DoEvents
Loop Until MSComm1.InBufferCount >= 2
' Read the "OK" response data in the serial port.
Instring = MSComm1.Input
' Close the serial port.
MSComm1.PortOpen = False





Re: Visual Basic General Use IO.Ports.SerialPort to turn on / off PLC input switch

Adam Leyshon

Try using the System.IO.Ports.SerialPort object on a form and setting PortName to "COM2"

Set all the attributes as required then use something like:

Code Snippet

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

SerialPort1.Write("%01#RCSY0000**" + Chr(13))

End Sub

Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As _

System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived

MsgBox(SerialPort1.ReadLine)

End Sub

I've used form load so that when you load the form it initialises your "modem" with the Init String, then used the datareceived

event to return the data sent back.

Hopefully this is useful.






Re: Visual Basic General Use IO.Ports.SerialPort to turn on / off PLC input switch

yc_kok

Thanks, "%01#RCSY0000** is used for reading on / off status of contact.

When I try to turn contact on using SerialPort1.Write("%01#RCSX0000**" + Chr(13)), the 1st light did not turn on. Not sure what is the problem.

Note Y is output contact, X is the input contact. 0000 is the 1st contact, 0001 is the 2nd contact.

The SerialPort1_Data_Received did not get called in any situation. May be hardware connection problem. But I can turn on using FPWin GR software for PLC. May be the VB code has problem.

Any advise





Re: Visual Basic General Use IO.Ports.SerialPort to turn on / off PLC input switch

yc_kok

For the 2nd line, i mean SerialPort1.Write("%01#WCSX0000**" + Chr(13). R is read, W is write.



Re: Visual Basic General Use IO.Ports.SerialPort to turn on / off PLC input switch

yc_kok

Hi,

Is there any problem here I am using COM1

Dim WithEvents serialPort As New IO.Ports.SerialPort

With serialPort

.PortName = "COM1"

.BaudRate = 9600

.Parity = IO.Ports.Parity.Odd

.DataBits = 8

.StopBits = IO.Ports.StopBits.One

End With

serialPort.Open()

serialPort1.Write("%01#WCSX0000**" + Chr(13))

Thanks.





Re: Visual Basic General Use IO.Ports.SerialPort to turn on / off PLC input switch

yc_kok

Hi,

Is there any problem here I am using COM1

Dim WithEvents serialPort As New IO.Ports.SerialPort

With serialPort

.PortName = "COM1"

.BaudRate = 9600

.Parity = IO.Ports.Parity.Odd

.DataBits = 8

.StopBits = IO.Ports.StopBits.One

End With

serialPort.Open()

serialPort.Write("%01#WCSX0000**" + Chr(13))

Thanks.





Re: Visual Basic General Use IO.Ports.SerialPort to turn on / off PLC input switch

Adam Leyshon

To be perfectly honest I can't see what could be causing the problem.

Try E-mailing the manufacturers.

Although i can't see anything wrong with this code.

If anyone else cares to try lol because im stumped

I tried that code but with a different string and sent it to a serial label printer we have here and it worked for me

I also tried an old modem we had lying around, it initialised aswell.

Try checking that you haven't fried the com port or the hardware. also try making sure that it is actually com1 (windows can be funny assigning com ports.)






Re: Visual Basic General Use IO.Ports.SerialPort to turn on / off PLC input switch

yc_kok

Hi Adam,

Thanks for your suggestions, you are not stump. May be I did not configure the hardware correctly and it is definitely not VB problems. I am still new in HMI, my understanding is still weak, so it is not your fault.

I am checking the KEPServerEX OPC Server.

Regards,

yc_kok





Re: Visual Basic General Use IO.Ports.SerialPort to turn on / off PLC input switch

yc_kok

Adam,

I found out why last time cannot work, it is because the command is short of 1 digit. I.e:
%01#WCSR0000**

To turn on internal relay R0, it should be:
%01#WCSR00001**

To turn off:
%01#WCSR00000**

So it is not VB problem.

Regards,
yc_kok.