Hi, I'm trying to get values from 8 encoders using a 2-wire bus RS485 connection to a Red Lion Data Station. These will ultimately write values to strings in an AB compact logix controller via ethernet. The way these encoders work is that is needs a request signal for a specific encoder ID to receive any data. Here below is essentially the documentation on request needed to receive data.
REQUEST TO ENCODER
ID Command Carriage Return
1 byte X Bytes depending on command 0D(hex)
RECEIVE FROM ENCODER
ID Data Checksum
1 byte 8 bytes 1 byte
ADDRESS (ID)
The encoder only responds to commands if the ID byte responds to the programmed
encoder ID.
COMMANDS:
Command Function Data Returned
RT Request Encoder type 01 (00=RS232 : 01=RS485)
RP Request position 8 bytes position
The other problem is figuring out how to send the correct request data through the Red Lion Data Station code which is in C programming language. We have tried various codes similar to the code shown below:
// declare locals
PortPrint(3,":SRP/r");
//S is the ID, RP is the command to request position
int i;
int j;
int in = PortRead(3, 500);
// loop while there is data in the buffer, populating the array
while(in != -1) {
Array[i++] = in;
in = PortRead(3, 500);
}
// if something was received, build a string
if(i > 0) {
Data = "";
for(j = 0; j <= i; j ++) {
Data += Array[j];
}
}
If anyone has experience with this type of application, any help would be greatly appreciated.
Thanks,
Alex
REQUEST TO ENCODER
ID Command Carriage Return
1 byte X Bytes depending on command 0D(hex)
RECEIVE FROM ENCODER
ID Data Checksum
1 byte 8 bytes 1 byte
ADDRESS (ID)
The encoder only responds to commands if the ID byte responds to the programmed
encoder ID.
COMMANDS:
Command Function Data Returned
RT Request Encoder type 01 (00=RS232 : 01=RS485)
RP Request position 8 bytes position
The other problem is figuring out how to send the correct request data through the Red Lion Data Station code which is in C programming language. We have tried various codes similar to the code shown below:
// declare locals
PortPrint(3,":SRP/r");
//S is the ID, RP is the command to request position
int i;
int j;
int in = PortRead(3, 500);
// loop while there is data in the buffer, populating the array
while(in != -1) {
Array[i++] = in;
in = PortRead(3, 500);
}
// if something was received, build a string
if(i > 0) {
Data = "";
for(j = 0; j <= i; j ++) {
Data += Array[j];
}
}
If anyone has experience with this type of application, any help would be greatly appreciated.
Thanks,
Alex