Connecting Tech Pros Worldwide Forums | Help | Site Map

I have to unplug and plug my USB device every time to communicate :(

Newbie
 
Join Date: Aug 2009
Posts: 2
#1: Aug 19 '09
I am using a linux machine with an USB port and I have to communicate with a temperature controller which has an UART port and for this I am using a USB to UART Serial Adapter.
port name on my machine is /dev/ttyUSB0
Expand|Select|Wrap|Line Numbers
  1. $port = "/dev/ttyUSB0";
  2. open(SERIALPORT,"+>$port") || die("ERROR SENDING DATA\n");
  3. SERIALPORT->autoflush();
  4.  
  5. ## in between I am sending data 
  6.  
  7. print $FILEHANDLE $data;
  8.  
and receiving back from that temperature controller ##

after all that process I am closing that file handle.
Expand|Select|Wrap|Line Numbers
  1. close(SERIALPORT);
  2.  
code is working fine one time . I am getting correct result .

but when I am trying to run the script second time then it hands at the step when I am sending data to temperature controller
Expand|Select|Wrap|Line Numbers
  1.  
  2. print $FILEHANDLE $data;
  3.  
and for this I have to unplug and plug that USB serial adapter again.after that it is working fine.

I am unable to find out what is the problem.
Can u people figure out what may be the possible reasons for it.

Thanks for your reply in advance.

KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,091
#2: Aug 19 '09

re: I have to unplug and plug my USB device every time to communicate :(


Quote:

Originally Posted by ashishchauhan View Post

I am using a linux machine with an USB port and I have to communicate with a temperature controller which has an UART port and for this I am using a USB to UART Serial Adapter.
port name on my machine is /dev/ttyUSB0

$port = "/dev/ttyUSB0";
open(SERIALPORT,"+>$port") || die("ERROR SENDING DATA\n");
SERIALPORT->autoflush();

## in between I am sending data

print $FILEHANDLE $data;

and receiving back from that temperature controller ##

after all that process I am closing that file handle.
close(SERIALPORT);

code is working fine one time . I am getting correct result .

but when I am trying to run the script second time then it hands at the step when I am sending data to temperature controller
print $FILEHANDLE $data;

and for this I have to unplug and plug that USB serial adapter again.after that it is working fine.

I am unable to find out what is the problem.
Can u people figure out what may be the possible reasons for it.

Thanks for your reply in advance.

What is the filehandle you are using? Is it $FILEHANDLE or SERIALPORT
Newbie
 
Join Date: Aug 2009
Posts: 2
#3: Aug 20 '09

re: I have to unplug and plug my USB device every time to communicate :(


oh sorry . it is SERIALPORT .
Reply

Tags
perl, port, serial communication, uart, usb