CON _CLKMODE = XTAL1 + PLL16X _XINFREQ = 5_000_000 ' ======<< Ascii control Characters >>===== soh = %00000001 '01, $01, %00000001 stx = %00000010 '02, $02, %00000010 etx = %00000011 '03, $03, %00000011 eot = %00000100 '04, $04, %00000100 ack = %00000110 '06, $06, %00000110 nak = %00010101 '21, $15, %00010101 syn = %00010110 '22, $16, %00010110 '=====<< Misc constants >>===== MaxPacketSize = 60 SureBaud = 19200 #0,Sure OBJ Ser: "FourPortSerial" '4 serial ports 1 cog PUB Start(TxPin) '' Create and send a Packet of data then receive a Packet of data and display it '' Packet sent consists of the board name (ABoard), the packet number, the error count '' The B board modifys the packet by adding its name, packet number, error count and returns the packet '============ Assign the serial ports and Start things ================== ser.Init ser.AddPort(Sure, -1, TxPin,-1,-1,0, 0,SureBaud) 'Port,Rx,Tx,Cts,Rts,Threshold,Mode,Baud ser.Start {{ ------------------------------------------------------------------------------ Sender -- Sends a block of bytes Each block begins with and a followed by the data (1 to 60) bytes and the . There are no restrictions on the contents of the data. The checksum is the mod 256 sum of the data not including soh,stx,count or cksum ::= ::= ::= stx ::= stx ::= ::= Sum mod 256 ::= | ::= $00..$FF ::= 0..60 --------------------------------------------------------------------------------}} Pub SendPacket(Rts, Count, Packet) | cksum, i, Char i := 0 waitpeq(|) Ser.Tx(Sure,Long[Packet][i++]) ' Send byte to transceiver Ser.Tx(Sure,cksum//256) ' Send the checksum mod 256 {{------------------------------------------------------------------------ These are utility routines used to move data from and into the packet --------------------------------------------------------------------------}} Pub Pack(N,Size,i,dst)| j ' Packs Size bytes into Packet beginning at i repeat j from 0 to Size-1 ' Can be used for Words, Longs. Long[dst][Long[i]++] := N.Byte[j] Pub UnPack(size,i,Src):N | j ' UnPack Size bytes from packet beginning at i into N repeat j from 0 to Size-1 N.byte[j] := Long[Src][long[i]++] Pub StrCp(i,src,dst) ' Copies string from Src to Dst bytemove(dst,src,strsize(src)+1) 'Plus one includes the string terminator Long[i] += strsize(src)+1 Pub ClearPacket(Packet) longfill(Packet,0,MaxPacketSize)