PDA

View Full Version : need help hserin/hserout cmucam4



siyete
- 15th December 2012, 13:34
hi i need help to receive the data as a string then parse it.
im new to programming so please help me..


1. if i enter like HSEROUT ["AG 0",13] the cmucam4 will return either ACK\r or NCK\r

Dim B1 As Byte
test_ag:
HSerOut ["ag 0",13]
HSerIn [B1]

'if the data received is NCK\r it will repeat test_ag:
'while if its ACK\r it will move to the next part of the code
'or if possible to detect only ACK or NCK without the \r


2. if i enter HSEROUT ["TC",13] it will return
NCK\r
or
ACK\r
T mx my x1 y1 x2 y2 pixels confidence\r


dont know how it would look like

Dim B2 As Byte
Dim tc_mx As Byte
Dim tc_my As Byte
Dim tc_x1 As Byte
Dim tc_y1 As Byte
Dim tc_x2 As Byte
Dim tc_y2 As Byte
Dim tc_p0 As Byte
Dim tc_c0 As Byte
main:
HSerOut ["TC",13]
HSerIn [B2]


'if the data received is NCK\r it will repeat main:
'while i need to save the values of mx my pixels and confidence.
'mx to tc_mx
'my to tc_my
'pixels to p0
'confidence to c0
'all data recieved are numbers like this:

ACK\r
T 79 59 0 0 159 119 255 255\r

mister_e
- 16th December 2012, 08:45
Many different way to skin a cat, but sometime, Hserin timeout feature can be handy.

HSERIN 500, main,[WAIT("ACK\r"), SKIP 1, tc_mx, tc_my,SKIP 4, p0, c0, SKIP 2]

OR something like this will also work
Packet VAR BYTE [11]
tc_mx VAR Packet[1]
tc_my VAR Packet[2]
p0 VAR Packet[7]
c0 VAR Packet[8]

HSERIN 500, main,[WAIT("ACK\r"), STR Packet\11]

may looks like a mess of variable, BUT...

siyete
- 17th December 2012, 03:46
so the code will look like:



Dim tc_mx As Byte
Dim tc_my As Byte
Dim tc_x1 As Byte
Dim tc_y1 As Byte
Dim tc_x2 As Byte
Dim tc_y2 As Byte
Dim tc_p0 As Byte
Dim tc_c0 As Byte
main:
HSerOut ["TC",13]
HSerIn 500, main,[WAIT("ACK\r"), SKIP 1, tc_mx, tc_my, tc_x1, tc_y1, tc_x2, tc_y2, tc_p0, tc_c0, SKIP 2]

will it repeat main: if ACK\r doesnt appear?.. like when it recieves NCK\r

and how about #1?
if i enter like HSEROUT ["AG 0",13] the cmucam4 will return either ACK\r or NCK\r

Dim B1 As Byte
test_ag:
HSerOut ["ag 0",13]
HSerIn [B1]
'if the data received is NCK\r it will repeat test_ag:
'while if its ACK\r it will move to the next part of the code

mister_e
- 17th December 2012, 22:49
How about trying it and see what happen. Those are guideline, really more than enough to begin.

Serial signal sniffer comes handy in those situations.