Linux - AB KF2 Connectivity

scrawny

Member
Join Date
Nov 2008
Location
Brisbane
Posts
3
Hi!

I have a RedHat Linux box that is trying to read/send data through to an AB 1770-KF2 data highway via an RS-232 (serial) port. However the C code that manages it is returning an I/O-Timeout error. The code uses a "read" statement. Which returns a -1. However, a previous line "opens" the connection with no issues.

According to the linux header file (unistd.h), 'read' returns the number read or -1 for errors or 0 for EOF.

Has anyone come across this before? Is there any diagnosis that I can perform? I have previously connected an RS-232 line tester to make sure everything's ok and it lights up fine. The device ID has been declared properly as far as I can tell...

Please help!

-Scrawny

ps. The linux pc is an upgrade from an old Xenix pc which currently works with the same code with no issues.
 
Further to the above... I have been in contact with Rockwell and the response was to test the connection with some software called "RSLinx". So I went to their website and found that there's no RSLinx for Linux... I did actually tell them it was a linux pc. Anyway... I replied to their email asking for another suggestion... awaiting a reply... it's been 3 days now.
 
scrawny said:
Hi!

I have a RedHat Linux box that is trying to read/send data through to an AB 1770-KF2 data highway via an RS-232 (serial) port. However the C code that manages it is returning an I/O-Timeout error. The code uses a "read" statement. Which returns a -1. However, a previous line "opens" the connection with no issues.
Is there code that issues a command? There should be a write before the read. How do you make sure the write is actually sent? Usually you need to execute a flush() function.

According to the linux header file (unistd.h), 'read' returns the number read or -1 for errors or 0 for EOF.
EOF is normally defined as (-1)
#define EOF (-1)
It is not an error

Has anyone come across this before? Is there any diagnosis that I can perform? I have previously connected an RS-232 line tester to make sure everything's ok and it lights up fine. The device ID has been declared properly as far as I can tell...
You should make sure the input buffer if flushed before doing the write. There may be garbage including EOFs in the input buffer before you do the write.
 
No flushing in this part of the code. The code is merely establishing a successful connection before sending any data.

This is the code (status is being set to -1 after read... ignore the debug statements - just breaking the code to see if it has the right details):

getcpd()
{
extern int status;
char c;
long time();
uint alarm();

#define DLEN 120
static char dbuf[DLEN];
static char *dp = &dbuf[0];
static char *dop;
static int dcnt;
char df, dc;

debug("getcpd");
try_again:
(void)signal(SIGALRM,onint); /* set alarm signal for trap by onint*/
(void)alarm(IOSECS);

debug("read()");
status = read(iodevfdes,&c,1);
debug("post-read()");

(void)alarm(0);
(void)signal(SIGALRM,SIG_IGN);

if (status == -1) {
sprintf(&evstr[0],"AMGR: Getcpd (amgr): -1 status\n");
frrlog(&evstr[0]);
return (IO_TIMEOUT);
} else if (status == 0) {
sprintf(&evstr[0],"AMGR: Getcpd (amgr): 0 status\n");
frrlog(&evstr[0]);
sleep(1);
goto try_again;
} else {
return (c & 0377);
}
}
 

Similar Topics

Trying to write a bash script for BusyBox and I can't get the FTP command to accept the Username and Password. I have tried using FTP...
Replies
4
Views
1,177
Hello all, I have a client that needs to externally control some valves at a small plant, nothing fancy. (for which I just need digital IO)...
Replies
16
Views
3,953
I have a linux server (on prosumer hardware), debian stretch 10. There was some utility works in my area and they hit the power line. The server...
Replies
15
Views
3,205
Hi there PLC aficionados, I have a quick question for you. Do you use Linux in your integrator/automation engineer/Technician role? If, yes which...
Replies
20
Views
8,391
Long time reader here but don't post much as I usually find the answers I need in the forum search. I am trying to create a dynamic selection...
Replies
11
Views
2,300
Back
Top Bottom