10-20-2010 02:03 PM - edited 10-20-2010 02:04 PM
If you close a UDP port and try to open it a nanosecond later, it is possible that the OS hasn't released it yet. There is absolutely no need to ever do that.
UDP is a connectionless protocol, so just open the port and keep it open for the duration of the program run.
Can you show us some code?
10-20-2010 04:55 PM
here is the simple version of the code. thx
10-20-2010 08:12 PM - edited 10-20-2010 08:19 PM
@sbz wrote:
here is the simple version of the code. thx
Well, that code is exceedingly complicated. All that logic mess can be replaced with autoindexing. The delay has an error in/out, so no sequence is needed.
Why is there no top-level while loop? Are you running this on demand or are you using the "continuous run" button?
You are only sending commands via UDP and you never receive anything. Since you seem to run an UDP client, the local port should be unimportant. Maybe you should leave it unwired so the OS can pick an unused ephemeral port and you don't need to rely for a certain local port to be unused. Even if your server (instrument) sends replies back, you can program it to reply to whatever the source port of the request is, again making the local port of the client irrelevant.
You should only set a fixed local port if you are planning to run it as a server where clients establish new connections from the outside.
Anyway, you should only open the UDP session once for the entire duration of the program.
Here's a quick rewrite that does basically the same thing. Whenever you press the button, both instruments are contacted.
The local port is kept open until the program ends. Let me know if it makes sense.
10-21-2010 12:52 PM
hi,
thanks for taking the time & modifying the code. the code i sent you is just part of a huge code, and the part i sent you only triggers the lasers. the problem is not with the code, it works fine with 1 device but not with 2. i ran your code & it doesn't run but again thanks for your time.
sbz
10-21-2010 01:16 PM
One thing I noticed is that the "con\n" constant is set to normal display mode. I believe the intent here is to send "con" followed by a linefeed. In this case you need to change the display mode of that constant to '\' codes display and remove one of the backslashes that will appear once you do this. Also, some of the other strings have spaces at the end. Don't know if that matters.
10-21-2010 01:23 PM