Why does AvailableSerialPortInput() block?

Just starting out? Need help? Post your questions and find answers here.
swhite
Enthusiast
Enthusiast
Posts: 727
Joined: Thu May 21, 2009 6:56 pm

Why does AvailableSerialPortInput() block?

Post by swhite »

Hi

I have a situation where a USB cable is attached to the PC but not connected to a device. PureBasic opens the serial port but the AvailableSerialPortInput() blocks. I would have thought it would have returned with 0. I am using PB 5.45 on Linux OpenSuse 43.2. Since the AvailableSerialPortInput() blocks my application is locked with no way to continue. What happened was that a technician took the device but left the cable connected to the PC and I am looking for some way to handle this without locking up the application.

Thanks,
Simon
Simon White
dCipher Computing
infratec
Always Here
Always Here
Posts: 6883
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Why does AvailableSerialPortInput() block?

Post by infratec »

Why do I not know what you have programmed :?:

No working example... (with the behaviour) no help.

In all my codes I have no problems with this.
swhite
Enthusiast
Enthusiast
Posts: 727
Joined: Thu May 21, 2009 6:56 pm

Re: Why does AvailableSerialPortInput() block?

Post by swhite »

Hi

The following line blocks when the USB cable is left attached to the PC but no device is attached to the other end of the USB cable.

Code: Select all

If AvailableSerialPortInput(goParam\Mag\Port)   

Simon White
dCipher Computing
normeus
Enthusiast
Enthusiast
Posts: 415
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: Why does AvailableSerialPortInput() block?

Post by normeus »

on windows 7 pro
If the device was removed while you program was running after you opened the port then
if you check for the port with "IsSerialPort()" it will tell you it is OK, even if the port is not there anymore.

Then if you try AvailableSerialPortInput() even if the device is not there you'll get a number
and I assume you do a "ReadSerialPortData()" which in fact blocks.

so the problem is how to test if device is removed.

or open the port only when you are going to read data and not at the beginning of your program.

testcode:

Code: Select all

If OpenSerialPort(0, "COM4", 300, #PB_SerialPort_NoParity, 8, 1, #PB_SerialPort_NoHandshake, 1024, 1024)
    Debug "Success"
  Else
    Debug "Failed"
 EndIf
 MessageRequester("TEST", "Remove device")
 If IsSerialPort(0)        ; I WISH THIS COMMAND WOULD TEST IF THE PORT IS STILL THERE
 Debug AvailableSerialPortInput(0)

Else
   MessageRequester("HEY BUDDY", "Device removed no need to check for input")
EndIf
Norm.
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
swhite
Enthusiast
Enthusiast
Posts: 727
Joined: Thu May 21, 2009 6:56 pm

Re: Why does AvailableSerialPortInput() block?

Post by swhite »

Hi

I have a suspicion that problem is related to a faulty debugger. I discovered that when debugging the debugger stops on the line right after the break point when I am using the Step button in the IDE. It just so happened that the break point was the line prior to the AvailableSerialPortInput() function. This is happening at other break points as well. All the debugger buttons become grayed out. I am running PB 5.45 on linux Opensuse 43.2. The strange things is that the debugger was working earlier in the week but today it is not.

Simon
Simon White
dCipher Computing
Post Reply