[REBOL] How-to use Serial Port
From: zokie:ml:libero:it at: 9-Oct-2010 17:41
Hi all,
I'm writing a short script to capture the output of RFID reader. It dumps an
ASCII string for each RFID tags which is near enough.
I want to put a box with 12 RFID tags and gets their unique marks. The script
dumps how many tags are passed near the reader, so I detect if there are
defective ones into the box under test!
The script is below. To simulate the reader and the capture machine I use two
PC with Windows. One runs the "script", the other one is used to type mark by
hands. I open Serial Port with:
serial-port: open/lines/direct/no-wait serial://port1/9600/8/none/1
After I type something like this line:
insert serial-port rejoin [["01 M00CD7DD2 N 23" newline "01 M00CD7DD2 N 24"
newline "01 M00CD7D D2 N 25" "" newline]
What I get on the other PC is something like this:
Lettura Tag RFID
Number of Tags (current test) 1
Number of Tags (total) 1
["01 M00CD"]
Number of Tags (current test) 4
Number of Tags (total) 5
["7DD2 N 23" "01 M00CD7DD2 N 24" "01 M00CD7D D2 N 25" ""]
May you help me to understand why I get so bed output?
Thank you in advance.
/* Full Script */
REBOL []
either exists? %ztools.r [
do %ztools.r
][
do load-thru http://utenti.multimania.it/zlab/pub/rebol/ztools/ztools.r
]
; +-------------+
; | Serial Port |
; +-------------+
my-serial-port: "com1"
my-serial-port: to-word my-serial-port
insert system/ports/serial my-serial-port
serial-port: open/lines/direct/no-wait serial://port1/9600/8/none/1
;serial-port: open/lines/no-wait serial://port1/9600/8/none/1
; +-----------+
; | File Init |
; +-----------+
infilename: %TagReport_FULL_DB.txt
ofilename: %Test_Hyperterminal.TXT
; +---------------+
; | Emulator Init |
; +---------------+
emulation: FALSE
emulatedtags: copy [
"=0201 M00CD7DD2 N 22=03"
"=0201 M00CF00B6 N 51=03"
"=0201 M10101010 Y 20=03"
"=0201 M00CF4414 N 20=03"
]
; +-----------+
; | Main Init |
; +-----------+
print "Lettura Tag RFID"
tagscounter: 0
if exists? ofilename [delete ofilename]
; +--------------+
; | Reading loop |
; +--------------+
forever [
if TRUE = emulation [serial-port: copy emulatedtags ]
tags: copy serial-port
either none = tags [
ntags: 0
][
ntags: length? tags
]
if 0 < ntags [
tagscounter: tagscounter + ntags
print ["Number of Tags (current test)" ntags newline "Number of Tags
(total)" tagscounter]
foreach tag tags [
write/append ofilename rejoin [tag newline]
]
probe tags
wait 5
]
]
; Exit
;close serial-port
print "Ready."
halt