Excellent, Pierre, thx for uploading!
I use the async serial comm as well, to send out NMEA 0183-packages from the simulator. That way i can allow a user to connect additional nav hardware and be able to see the data for the own vessel in whatever external electonics he/she connects. Atm. i send only a few packages, of which one looks typically like this:
'$GPRMC,160504.00,A,6008.812841,N,02458.795638,E,02.183,235.973,240613,,,A*59',⎕TC[3 2]
The code builds up the package, then adds a checksum and pushes out asynchronously:
check←{a←≠⍀↑(⌽8,⍴⍵)⍴11 ⎕DR ⍵ ⋄ '0123456789ABCDEF'[1+,83 ⎕DR 2 ¯8↑2 4⍴a[⍴⍵;]]}p ⍝ XOR checksum, into 2 hex chars
{}#.SERIAL.STREAMS[iPort].WriteAsync(⊂83 ⎕DR a),0,⍴a←'$',p,'*',check,⎕TC[3 2]
That's it. Heartbeats by a que system, to for example once per second. No waiting for incoming, and most relevantly: No hang (we are in a game loop, would freeze the action). Calling this pkg build function and sending the result has practically no impact at all - it happens in milli- or microseconds! Thanks again to APL for being faster than the eye with small data!
Serial ports are tricky, much trickier than IP comm. They may behave badly, lock the system, hang, be slow, incompatible or hard to configure. But once the settings are correct, it's a go. One additional thing to perhaps also mention in the wiki article could be how to mechanically manage the port. Ie., computers no longer have 9/25-pin serial ports, as we know. So what you do is go to the IT shop and buy a USB<->RS232-adapter. Windows will smootly install it's driver, and after that you have the place to plug in a 9-pin serial cable. The price of an adapter is typically 20-30 euros here.
Re. the USB part, i'd however object against your logic. You use a
:If ⎕TSYNC{task.Wait ⍵}&(_PortTimeOut)
but the whole point with async is to NOT hang and wait. Even if this happens in a separate APL thread, imho one shouldn't synchronize inside that thread. UDP, by nature, has absolutely no synchronisation. Packets shall go and may come in at any point in time, and no assumptions can exist. Hence i'd rather propose doing it with the callback logic i posted earlier. Coupling Send and Receive can ofc work in certain conditions but is more of a special case. Also to note is that a UDP packet may be big and hence segmented, plus that UDP packets can arrive in unexpected, "wrong" order.