None reponsive program

Both reading and writing. I’m not clear what you mean by providing infrastructure.

I am calling a couple of routines from the threads run event. What would posting some of the code in the threads run event show you?

Well a set of relevant methods that you are going to call from all over the place. To add text to a file, you’ve got to open it, write to it, and close it again. You don’t want to do all of those things every time you want, at some specific point in the code, to write a debugging line of information to the file. So you put all that in a method and then call it.

If you’re reading and writing, what methods are you using for that?

Okay, but what type of information would you normally write to a log that would be helpful to determine a hang problem?

I am using serial to send commands a line at a time reading the serial buffer for returns.

If SetBaud(8)Then
ConfigWriteSub // Clear any port acivity

If DeviceState Then //On
WriteSerial “PCC015” 'Config port C to Output
WriteSerial “PWC”+Str(output) 'set Port C to output
WriteSerial “PWA64” 'Pulse PWA Hex val to change state (turn on output)
WriteSerial “PWC0” 'Clear Output Selected
WriteSerial “PWA64” 'Pulse PWA Hex val to change state (turn on output)
WriteSerial “PWA0” 'Clear above Pulse
Else //Off
WriteSerial “PCC015” 'Config port C to Output
WriteSerial “PWC”+Str(output) 'set Port C to output button hit
WriteSerial “PWA128” 'Pulse PWA Hex val to change state (turn off output)
WriteSerial “PWC0” 'Clear Output Selected
WriteSerial “PWA128” 'Pulse PWA Hex val to change state (turn off output)
WriteSerial “PWA0” 'Clear above Pulse
End
End

Well, Serial seems to be depracated and that you should be using SerialConnection.

But even in the doc for Serial I don’t see DeviceState, WriteSerial, or SetBaud, are these your methods?

Yes, they are my methods. I spent considerable time trying to get serialconnection to work and was informed on the forum that serial would be around for a long time so stick with it since it was easier to use and worked fine. I’m the new kid on the block so fine with me.

Writeserial would be nothing more then this:

Var i As integer
write DataOut+Chr(13)

i= microseconds
while microseconds-i < 7000
wend

are those internal to your app (ones you wrote) or do they call out to other libraries, dll’s etc ?

deprecated ≠ removed
nor does new = better / fewer bugs

if serial works then use it until such time it doesnt and by then hopefully bugs have been worked out of the new stuff that replaces it

a loop[ like this wont yield and can lock things up

Why are you looping? Why not use flush() ?

Also, what does your read method look like? I hope you’re not looping there.

Ok, mine is currently 1148.
Looks like this number has been increased since then; thanks for pointing this out.

I loop to stall while the 232 WIZ controller has time to digest the command. I manually read the buffer after all command strings are sent:
ReceivedData = ReplaceAll(Readall,">","")

This technique seems to work fine and has for at least 11 years on RB 4.5 but I’m always open for a better way.

Is there a better way to wait to continue with more commands. Most of this code is in my thread but I may be having issues with this new thread. What might need yielding to? None of my code is processing while the thread is active. I place everything else on hold until the thread is complete so I don’t overlap commands to the controller.

a tight loop like that is almost certain to, at some points, cause things to block
A serial connection can be run “asynchronously” where you send a command off and eventually some data comes back in at some point in time
And you dont need to loop to write or read the data
But its a bit more work to handle things well

Only so I know, Where do you find this?

npalardy@server ~ % ulimit -a
-t: cpu time (seconds)              unlimited
-f: file size (blocks)              unlimited
-d: data seg size (kbytes)          unlimited
-s: stack size (kbytes)             8192
-c: core file size (blocks)         0
-v: address space (kbytes)          unlimited
-l: locked-in-memory size (kbytes)  unlimited
-u: processes                       5568
-n: file descriptors                256
npalardy@server ~ % 

in the macOS Terminal application and running the Unix command ulimit with the one option “-a”

1 Like

My apologises. I actually answered to the post above and it leads me to think we were talking about processes (applications); that’s why I mentioned there’s a limit about the number of processes that can be launched.
Reading all the remaining posts, I now realise this wasn’t that kind of “processes”. Sorry for the misleading.

1 Like

Methods I wrote if I’m following you about DeviceState, WriteSerial etc.

What does readall do if there is no data? In my case I also use readall (on a socket), but before doing it I pause the thread, and use the DataAvailable event to know when there is data. Then resume the thread in the event and only then do a readall in the thread.

For grins, I removed the wait and all did not go well. I have experimented with this over time and my controller just likes some time to return its recognition of the command I send. I think there are some collisions from the WIZ controller if I don’t wait. This will run for hours without a problem with the thread and now by removing the thread it ran all night. I think the read/write process may not actually be the issue since it works without the thread. The thread does have some advantages freeing the cursor and it would be nice to see it work. The bulldog syndrome.

DataAvailable has never worked well for me with this controller. I may flush the port and then send a series of commands to the controller with a pause for each command response. The controller won’t wait for a series to be sent, it’s dumb and has no CTS or RTS lines. Every command gets a response so I read the data buffer after the last command was sent. It will not hang if no data is available on the buffer read.

So you’ve tuned it for a given controller and given CPU in your Mac. If either of these changes, you’ll have to retune. Is why flush() would be better.