how to implement this protocol to read the registers in plc....????

swapnil

Member
Join Date
Jul 2003
Location
india
Posts
33
plz any body out there help me to implement this protocol in c or VB 6.0 plzzzz,i need some code to implement this using com1 port of pc,for sending queries from computer and rechieving data from plc only.plz help me by providing some code for this.
the required data of protocol are as follows only i need is the code.


COMMUNICATION PARAMETERS:

1. Baud Rate = 9600.
2. Number of data bits= 8.
3. Parity= ODD.
4. Number of stop bits= 1.

FRAME FORMAT:
|10h 02h HEADER | length | comman byte | data field | cs check |

PARAMETERS USED:

LN : Number of commands from & including command bytes but excluding CS byte.
CS : Binary addition of the characters from header of data.

Data Field Includes :

TT - type of bit/word (register)
00 for O/P
01 for I/P
nn - hexadecimal num 'n' indicating num of bits/words.
AL AH - Offset address in Hex.
DL DH- Data in Hex returned by PLC.

LIST OF COMMANDS :

01 - Read 'n' consecutive words
15 - Force
11 - Write 'n' consecutive words
1A - CPU command
CC - =01 for put PLC in RUN mode
=02 for put PLC in STOP mode
=03 for INITIALIZE PLC.

COMMUNICATION PATTERN :


COMMAND DETAILS :

1. CPU commands:
10 02 02 1A CC CS
10 02 01 5A CS

2. Read commands
10 02 05 01 nn TT AL Ah CS
10 02 2n+1 41 DL1 DL2 DL3...DLn DHn CS

3.Write commands
10 02 15 TT AL AH CS
10 02 01 55 CS
 
Parity=EVEN ?

Hi,

I'll try this protocol. It's look well. But I think Parity=EVEN is correct, isn't it ?
 
VB

You really don't need to use basic to do the initial tests yourself.
Set up hyperterminal and start sending commands and look for responses. I will post the basic VB code as follows, this code is for DF1 communications with a SLC but should give you basics on how to do it.

Dim MyArray(25) As Byte
Dim i, Total As Integer

MyArray(0) = 16
MyArray(1) = 2
MyArray(2) = 5 'Dest
MyArray(3) = 0 'Source
MyArray(4) = 15 'Command
MyArray(5) = 0 'STS
MyArray(6) = TNS 'Transaction number
MyArray(7) = 0 'Transaction number
MyArray(8) = 128 'Function
MyArray(9) = 1 'Mode 1 = Program, 6 = Run
MyArray(10) = 16
MyArray(11) = 3
Total = 0
For i = 2 To 9
Total = Total + MyArray(i)
Next

While Total > 256
Total = Total - 256
Wend

Total = Total Xor 255

MyArray(12) = Total + 1
strXMIT = ""
For i = 0 To 12
strXMIT = strXMIT & Chr(MyArray(i))
Next

MSComm1.Output = MyArray
 
I'd tried this code. However, the PLC doesn't reply correctly. Could you explain me more about protocol.


VARIANT var;
BYTE element1[]={0x10,0x02,0x02,0x1A,0x01,0x1F,0x16};

SAFEARRAY m_aElement[1];
long Index=0;

// init safe array
m_aElement[0].cbElements=1; // size of one element
m_aElement[0].cDims=1; // one dimention
m_aElement[0].cLocks=0; // ignore timeout
m_aElement[0].fFeatures=FADF_AUTO; // Array is allocated on the stack
m_aElement[0].rgsabound[0].cElements=7; // length of array
m_aElement[0].rgsabound[0].lLbound=0; // beginning of index
m_aElement[0].pvData=element1; // pointer to array

// assign to variant type
var.vt= VT_ARRAY|VT_UI1;
var.parray=m_aElement;
m_wndComm.SetOutput(var);


VariantClear(&var);
 
Hi Swapnil,

Do you have any suggest for me about PPI protocol, pls send me via email [email protected] I am trying to discover it and have something about it such as token, frame, Mem_erea. However, there are many part that I don't know what it is. I wonder if you can help me ?

Thanks
 

Similar Topics

Dear all, I want a communication between pc and fx5u. I am considering SLMP protocol. I think it is well documented. But many of the third party...
Replies
4
Views
128
Here is a post that I just finished. I thought that it would be worth sharing here. Let me know what you think. Thank you, Garry...
Replies
35
Views
35,067
Let's say I have an inverter fed three phase induction motor drive where in the braking phase (when the motor operates in a generator mode) the...
Replies
2
Views
155
I want to improve a semi custom product I am delivering to a customer with implementation of safety relays. The system is fairly simple with just...
Replies
5
Views
623
I'm struggling to implement the test case which is highlighted. What ends up happening is the servo starts when I turn the cycle on, but it...
Replies
3
Views
1,085
Back
Top Bottom