Sign in to follow this  
Followers 0
Pavan

writing data to plc

6 posts in this topic

Hi all, The vb code for reading data from PLC is (using of A compatible 1E frame command of MC protocol): TxCommand = "01ff000a4420000000000500" Buffer = System.Text.Encoding.Default.GetBytes(TxCommand.ToCharArray) 'Sending a read command Client.GetStream().Write(Buffer, 0, Buffer.Length) 'Waiting for a response from an Ethernet adapter While Not Client.GetStream().DataAvailable() Application.DoEvents() End While If Client.GetStream().DataAvailable() Then Client.GetStream().Read(InBuff, 0, InBuff.Length) RxResponse = System.Text.Encoding.Default.GetString(InBuff) SubHeader = Mid$(RxResponse, 3, 2) If SubHeader = "00" Then 'Normal response Temp = "" 'Initialization of an output character string For j = 0 To 4 DregStr$ = Mid(RxResponse, j * 4 + 5, 4) Dreg(j) = Val("&H" + DregStr$) Temp = Temp + Format(Dreg(j), "#####0") + " " Next lstOutput.Items.Insert(lstOutput.Items.Count, Temp) ElseIf SubHeader = "5B" Then ' In an abnormal response, an abnormal code is added. Temp = "Terminate Code = " & SubHeader & " Error Code = " & Mid$(RxResponse, 5, 2) lstOutput.Items.Insert(lstOutput.Items.Count, Temp) Else Temp = "Terminate Code = " & SubHeader lstOutput.Items.Insert(lstOutput.Items.Count, Temp) End If lstOutput.SelectedIndex = lstOutput.Items.Count - 1 End If ' Line disconnection processing Client.GetStream().Close() Client.Close() Can any one help me vb code for writing data to PLC.

Share this post


Link to post
Share on other sites
I'm no VB guy, but it looks to me that your code is for reading data. Writing is pretty much the same, so since you've managed to get the reading part to work, what's the problem with writing data?

Share this post


Link to post
Share on other sites
thanks for your response.. My actual need is for writing data to PLC the command is TxCommand = "03ff000a4420000000000100" (writing data to D0 register) so how to link up the command with our giving values(which is given by text box). for example i create one text box(which is used for giving values from ours) and 1 button in vb.net.When i pressed the button the the value which is given by us should be hit D0 register of PLC. Can you help me in that.................

Share this post


Link to post
Share on other sites
Where exactly is your problem? It looks to me like you know how to write the telegram itself, so what you need is "how to get the value from the textbox"...!?? I would look into int16.parse(textbox.text) or something like that in vb.net. As mentioned I'm no vb/vb.net guy but something like the command on the left will parse/convert a text value into an 16bit int which you can use to put into the value part of your telegram. Note that you should also use a RegEx or something similar to check for invalid values.... Is this what you need?

Share this post


Link to post
Share on other sites
My exact need is vb code.Actually for writing data to PLC we use some command like "03ff000a4420000000000100" it can be transfer to PLC by following code Try Client.Connect(IpAddress, PortNum) Catch ex As Exception MsgBox("Connection with the server failed, and the following code was returned:" & ex.Message, 0, "connection error") Exit Sub End Try 'Read D0 to D4 (5 points) with the A-compatible 1E frame command. TxCommand = "01ff000a4420000000000500" Buffer = System.Text.Encoding.Default.GetBytes(TxCommand.ToCharArray) 'Sending a read command Client.GetStream().Write(Buffer, 0, Buffer.Length) 'Waiting for a response from an Ethernet adapter While Not Client.GetStream().DataAvailable() Application.DoEvents() End While.my need is how to link up command with our values(which are given by user).

Share this post


Link to post
Share on other sites
Not really sure I can help you any further, but I really don't see the problem: Since you can succesfully read data from the PLC, what's stopping you from writing the commands needed to send data to the PLC?? I've never written the MC protocol in a computer enivronment, only in PLCs so I'm really not sure how I can help you any further.... But as mentioned: When you have already written all the read commands, there shouldn't be any problem writing the write commands in vb.....

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0