Hi all,
I have inherited code from a former employee that was written for a Rabbit 2500 (which worked fully). My task was to port the code so that it would run on a 2600, since we needed more Digital I/Os. I had never used Dynamic C before so I’m learning as I go, and running into some very frustrating problems.
I’ll spare you the gory details of the project, but basically the Rabbit uses uC/OS-II and connects via TCP/IP to another computer. The Rabbit then sends the data from the Digital I/Os sixty times a second (as a hex string) to a Java program which takes the raw data and writes it to a text file.
My problems arise with the TCP/IP connection. When I run the code I ported on the 2600 it seems to run fine. When I start the javascript sometimes it’ll work, and sometimes it won’t, seemingly randomly. Specifically, sometimes the javascript will run successfully, create the file, and start pumping it full of data. Sometimes the javascript will create the file but nothing is ever written to it. Sometimes it’ll crash the connection and I have to restart the 2600, and sometimes it’ll say that no connection could be established. Again, there is absolutely NO seeming correlation to when I run the javascript and when it’ll work or not.
I believe the problem lies in the 2600 specifically. With all the uC/OS-II related code gone (no tasks, no definitions, etc) here is the code:
[i]#class auto
#define TCPCONFIG 1
#define TCP_PORT 23
#use “dcrtcp.lib”
tcp_Socket Socket0;
void initialize();
void main(){
initialize();
sock_close(&Socket0);
while(tcp_tick(&Socket0)) {
}
printf("out of while loop, socket is closed
");
}
void initialize(){
brdInit();
sock_init();
while (ifpending(IF_DEFAULT) == IF_COMING_UP) {
tcp_tick(NULL);
}
printf("init done
");
}[/i]
The 2500 code I inherited did not have the while loops that wait for the sock_init() to be completed, or the sock_close() to be completed, I added those. I find that the sock_init() always works, while the sock_close() hangs very often, but will randomly work. What I mean is, half the time when I run the code the printline below the while loop won’t ever display, it’s caught in the loop indefinitely. If I remove the loop and just run the code, half the time the javascript can connect, half the time it doesn’t. That code is straight out of the TCP/IP User Manual, why wouldn’t it work?
I guess the other thing that I’m wondering about is why you’d initialize a socket (in the void initialize() function) and as soon as you’re done, close it in main? Nowhere in the uC/OS-II code (that I’ve left out) does it re-establish a connection. That being said, it works. If I don’t close the socket, it never works.
I’m definitely a newbie to Dynamic C, have taken a semester of C++. These problems, however, are entirely beyond my comprehension. If you guys can help me out at all, I’d sure as heck appreciate it!