View previous topic :: View next topic |
Author |
Message |
nil_orally
Joined: 07 Jun 2010 Posts: 18
|
Posted: Tue Apr 22, 2014 1:36 pm Post subject: Printbin |
|
|
Hi Folks,
I am flailing about in a serial handling routine, and am trying to get printbin to work.
So I read the RS485 serial string, and take action based on the match in a CASE statement. That writes a few variables and sets flags as required.
Some codes are commands to operate relays and generally set fire to things, and some are requests for information from the board. If it a command the serial port sends a straightforward ack sequence, but if it is a request for info, the length of the response can be variable. All of this is binary data, so I can't use Print.
So the relevant bits of the info processing:
Code: |
$regfile = "m328pdef.dat"
$hwstack = 80 '32
$swstack = 32 '8
$framesize = 40
dim Rx_buff(20) as Byte
dim rx_string as string * 21 at Rx_buff overlay
dim Tx_buff(20) as Byte , buff_qty as byte
dim tx_string as string * 21 at tx_buff overlay
dim req_tx_reply as bit , std_tx_reply as bit , reply_tx_delay as byte
dim write_relays as Byte , relay_do as bit
select Case Rx_buff(5)
case &H01 : write_relays = Rx_buff(6) : set relay_do : set std_tx_reply 'Direct relay control
' yadda
' yadda
case &H2A : Tx_buff(4) = Rd_23017_0_db : set req_tx_reply : buff_qty = 1 'what is on the digital inputs?
' yadda
' yadda
End Select
|
The following gives me a nicely formatted 4 byte output response:
Code: |
if std_tx_reply = 1 then '5-10ms response time
incr reply_tx_delay
if reply_tx_delay > 1 then
reset reply_tx_delay
reset std_tx_reply
Tx_buff(1) = Header_d
Tx_buff(2) = Board_type
Tx_buff(3) = Rs485_add
Tx_buff(4) = MSG_ack
Printbin #1 , Tx_buff(1) ; 4
end if
End If
|
This below however is giving a response of 21 bytes. The first 4 are correct, and the rest are garbage (random crud from the balance of the array/string I guess).
Code: |
if req_tx_reply = 1 then
incr reply_tx_delay
if reply_tx_delay > 1 then
reset req_tx_reply
reset reply_tx_delay
buff_qty = buff_qty + 3 'allow for the header, board type and address preamble
Tx_buff(1) = Header_d
Tx_buff(2) = Board_type
Tx_buff(3) = Rs485_add 'board address
Printbin #1 , Tx_buff(1) ; buff_qty '4 in this case
endif
endif
|
This section is all inline code. No sub routines.
The way I read the help file on Printbin, I can set the number of bytes sent. If I hard code a number in, I get what I expect. If I use a variable, I seems to print out the entire string. Any ideas on how to correctly approach this?
(BASCOM-AVR version : 2.0.7.7 ) |
|
Back to top |
|
|
kimmi
Joined: 24 Feb 2006 Posts: 1922 Location: Denmark
|
Posted: Tue Apr 22, 2014 10:40 pm Post subject: Re: Printbin |
|
|
Printbin #1 , Tx_buff(1);4 ; buff_qty sent 4 bytes
See the help _________________ / Kim |
|
Back to top |
|
|
nil_orally
Joined: 07 Jun 2010 Posts: 18
|
Posted: Tue Apr 22, 2014 10:54 pm Post subject: |
|
|
' Morning Kimmi, (at least it is here).
I did avail myself of the help over several cups of coffee, but that is what got me to here.
I guess my question is does the number (in this case 4, but there will be others as the string is variable length) have to be hard-coded in or can it be a variable so i can do it in a semi-clever way, rather than another tree tree of case statements? |
|
Back to top |
|
|
kimmi
Joined: 24 Feb 2006 Posts: 1922 Location: Denmark
|
Posted: Wed Apr 23, 2014 12:43 am Post subject: |
|
|
printbin does not accept a variable to specify the amount of bytes to print. _________________ / Kim |
|
Back to top |
|
|
nil_orally
Joined: 07 Jun 2010 Posts: 18
|
Posted: Wed Apr 23, 2014 1:21 am Post subject: |
|
|
Thanks for the advice, Kimmi.
This works:
Code: |
if req_tx_reply = 1 then
incr reply_tx_delay
if reply_tx_delay > 1 then
reset req_tx_reply
reset reply_tx_delay
buff_qty = buff_qty + 3 'allow for the header, board type and address preamble
Tx_buff(1) = Header_d
Tx_buff(2) = Board_type
Tx_buff(3) = Rs485_add
select case buff_qty
Case 4 : Printbin #1 , Tx_buff(1) ; 4
Case 5 : Printbin #1 , Tx_buff(1) ; 5
Case 6 : Printbin #1 , Tx_buff(1) ; 6
Case 7 : Printbin #1 , Tx_buff(1) ; 7
Case 8 : Printbin #1 , Tx_buff(1) ; 8
Case 9 : Printbin #1 , Tx_buff(1) ; 9
Case 10 : Printbin #1 , Tx_buff(1) ; 10
Case 11 : Printbin #1 , Tx_buff(1) ; 11
Case 12 : Printbin #1 , Tx_buff(1) ; 12
Case 13 : Printbin #1 , Tx_buff(1) ; 13
Case 14 : Printbin #1 , Tx_buff(1) ; 14
Case 15 : Printbin #1 , Tx_buff(1) ; 15
case 16 : Printbin #1 , Tx_buff(1) ; 16
end select
endif
endif
|
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|