punyforth icon indicating copy to clipboard operation
punyforth copied to clipboard

Receiving binary data via UDP

Open bob-g4bby opened this issue 4 years ago • 0 comments

Hi Attila, How are you? I'm revisiting Punyforth with the help of the glossary I wrote, if you remember. I'm successful in sending binary data from Punyforth to a PC - the data is read by a LabVIEW program just fine:-

\ UDP sender - array example

-UDP
marker: -UDP

1024 constant: arraysize

arraysize array: myarray		\ an array of 32 bit 'longs'

: !myarray					( -- ) \ initialise mybuffer with random data
	arraysize 0 do
		random i myarray !
	loop
;

"BOB-PC" 	constant: SERVER_IP
8005		constant: SERVER_PORT

: UDPsender
SERVER_PORT SERVER_IP UDP netcon-connect
begin
	!myarray										\ fill the array with random data
	dup 0 myarray arraysize 4 * netcon-send-buf	\ start address + byte count
	50 ms
	readchar-nowait 27 =							\ send it again until ESC pressed
until
netcon-dispose
;

UDPsender

What I can't seem to do is receive the same binary data from the PC with this code:-

 \ NETCON load beforehand

-UDP
marker: -UDP

"192.168.1.3" 	constant: HOST
1024 constant: datasize
8000 constant: PORT
datasize array: data

: UDPreceiver

PORT HOST netcon-udp-server
begin
	dup datasize 4 * 0 data netcon-read
	print: 'received bytes: ' . cr
	10 ms
	readchar-nowait 27 =
until
netcon-dispose
;

UDPreceiver

netcon-read never seems to return? Is that the right word to use with binary data or does it only accept ascii?

I can successfully read ascii data from the PC, using this:-

\ NETCON load beforehand

-UDP
marker: -UDP

"192.168.1.3" 	constant: HOST
128 constant: datasize
8000 constant: PORT
datasize buffer: data

: UDPreceiver

PORT HOST netcon-udp-server
begin
	dup datasize data netcon-readln
	print: 'received bytes: ' . cr
	data type cr
	10 ms
	readchar-nowait 27 =
until
netcon-dispose
;

UDPreceiver

bob-g4bby avatar Jun 06 '21 18:06 bob-g4bby