[KLUG Programming] looking for suggestions
Dirk H Bartley
programming@kalamazoolinux.org
19 Aug 2003 10:02:48 -0400
On Tue, 2003-08-19 at 05:51, Adam Williams wrote:
> > I am looking to accomplish a task at work. What I want to do be able to
> > communicate to cnc machines which have serial ports for file transfers.
> > A standard way is to have an m$ box next to the cnc machine with some
> > standard communication software capable of transferring files back and
> > forth between them. Then network the host.
>
> We're you able to make this work.
Not yet. I have been working on this for the last few days.
Thursday and Friday between other fires and the heat, I was able to
confirm that using ser2net and netcat I could transfer to and from both
a laptop and our new cnc machine from a linux serial port.
Yesterday and this morning I have been doing a little struggling. I'm
attempting to program in perl using the following program to recieve
_____
#!/usr/bin/perl -w
open( TEMPFILE, ">/tmp/cnc" );
print ">> Receive Client Program <<\n";
use IO::Socket::INET;
$MySocket=new IO::Socket::INET->new(PeerPort=>7011,
Proto=>'tcp',
PeerAddr=>'tristar');
#Timeout=>1);
$sockaddr = $MySocket->peerhost();
print "host ".$sockaddr."\n";
$counter=0;
print "\nbegin counter = ".$counter." sdfsdsf\n";
while(1)
{
$MySocket->recv($text,128);
$counter++;
#print "line ".$counter." ";
open( TEMPFILE, ">>/tmp/cnc" );
print TEMPFILE $text;
close( TEMPFILE );
print $text;
print "\ncounter = ".$counter."\n";
}
_______
This program receives perfectly. The problem with it is that it waits
for the next receive. I need to have a receipt of a file from the cnc
defined by a receipt of some bits followed by a number of seconds
without any bits flowing from the cnc. This program just sits and waits
for more bits. I need a timeout or to fork into the background of the
listen so I can sleep for a second and check to see the size of the
recieved bits has or has not changed.
The program or piece of experimental code to send as follows fails
miserably. The result is that the m$ laptop I am sending to (to
simulate a cnc) only get the first hundred or so bits.
_____
#!/usr/bin/perl -w
print ">> Send Client Program <<\n";
use IO::Socket::INET;
$MySocket=new IO::Socket::INET->new(PeerPort=>7011,
Proto=>'tcp',
PeerAddr=>'tristar');
$sockaddr = $MySocket->peerhost();
print "host ".$sockaddr."\n";
$cnt=0;
while($msg=<STDIN>)
{
#chomp $msg;
print $msg;
if($MySocket->send($msg))
{
#print ".....<done>","\n";
#print $def_msg;
} else {
print "DANGER WILL ROBINSON IN THE tcp SEND " }
$MySocket->autoflush(1);
$cnt++;
}
_______
The autoflush was an attempt to get it working. I'd like to blame
ser2net for this problem since it is sending over tcp succesfully
verified by ethereal. netcat sends marvelously though.
Ideally I would like to invoke the command system(inpipe | netcat >
outpipe ) and then use perl to poll inpipe and outpipe. Is this
possible?
Dirk
>
> _______________________________________________
> Programming mailing list
> Programming@kalamazoolinux.org
> http://www.kalamazoolinux.org/mailman/listinfo/programming