Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

How-to use Serial Port

 [1/2] 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 ] ; +-------------+ ; | 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

 [2/2] from: santilli:gabriele::gmail at: 9-Oct-2010 18:49

On Sat, Oct 9, 2010 at 5:41 PM, <> wrote:
> serial-port: open/lines/direct/no-wait serial://port1/9600/8/none/1
I suspect the /LINES/DIRECT/NO-WAIT combination does not work as you would expect. It does not really wait for the end of the line to return something. It's probably better to avoid /LINES in this case and look out for the newline character yourself. (You copy from the port, and append to a buffer; then search for the newline char in the buffer and if there is one grab the line.) Maybe this could be reported as a bug (it would be nice if it worked how you were expecting it to)... but, I don't think you'd want to wait for a R2 update. :-)