-->
Page 1 of 1

Hex commands through UART

PostPosted: Wed Mar 11, 2015 1:13 pm
by criscampos
Hi, I'm looking to send hex commands to a fingerprint sensor connected to a cp2101 board.
For that, i'm trying the following code (The sensor works only in 115200):

Code: Select all    uart.setup( 0,115200,8,0,1,0 )
    srv=net.createServer(net.TCP)
    srv:listen(80,function(conn)
       conn:on("receive",function(conn,payload)
          uart.write( 0, "0x55AA24010200010000000000000000000000000000002701")
          conn:send("<h1> Turning on LED.</h1>")
          end)
       conn:on("sent",function(conn) conn:close() end)
       end)


Is it ok to send an hex command in that way? What could be wrong?

Re: Hex commands through UART

PostPosted: Wed Mar 11, 2015 6:49 pm
by GerryKeely
Hi

uart.write can only send one byte at a time
try uart.write( 0, 0x55,0xAA,0x24,......).

Gerry

Re: Hex commands through UART

PostPosted: Thu Mar 12, 2015 9:42 am
by criscampos
Hi Gerry, thank you for your reply, I've tried and it worked perfectly.

It is just a little tedious to write every byte of 15 bytes-length command (I have to pass like 10 of this commands), but is the only way..

Thanks again!

Re: Hex commands through UART

PostPosted: Thu Mar 12, 2015 10:29 am
by GerryKeely
Hi
Would attached be any use
Code: Select allmsg = "55AA24010200010000000000000000000000000000002701"

for i = 1,string.len(msg),2 do
byte =("0x"..string.sub(msg,0+i,1+i))
uart.write(0,tonumber(byte))
end