Home AMX User Forum NetLinx Studio
Options

need help Buffer polling and BAND

Hello Guys

please can you help me ?

I get a 8 bytes String as a feedback signal into my buffer calls: IO64EG_BUFF
In each byte is the information of 8 inputs.
So each of the 8 bits represents a state
8 bytes x 8 bits are the 64 states to be polled
The information of each bit, 0 or 1 should
be written into a variable.

That will work like this: ??
What about the buffer, the buffer must be cleared by querying all the 8 bytes?



DEFINE_PROGRAM (* polling*)

WAIT 3
{

SEND_STRING IO64EG, "CallOut,$01,$00" //ask all Relay ports

STR1 = left_string(IO64EG_BUFF,1) // get first Byte
STR2 = mid_string(IO64EG_BUFF,2,1) // return 1 Byte starting at location 2
STR3 = mid_string(IO64EG_BUFF,3,1) // return 1 Byte starting at location 3
// and so on:
// STR4 = mid_str...
// STR5 = mid_str...


Rel_port1_Bit_8 = (STR1[1] BAND $80) // Input 8
Rel_port1_Bit_7 = (STR1[1] BAND $40) // Input 7
Rel_port1_Bit_6 = (STR1[1] BAND $20) // Input 6
Rel_port1_Bit_5 = (STR1[1] BAND $10) // Input 5
Rel_port1_Bit_4 = (STR1[1] BAND $08) // Input 4
Rel_port1_Bit_3 = (STR1[1] BAND $04) // Input 3
Rel_port1_Bit_2 = (STR1[1] BAND $02) // Input 2
Rel_port1_Bit_1 = (STR1[1] BAND $01) // Input 1

Rel_port2_Bit_8 = (STR2[1] BAND $80) // Input 16
Rel_port2_Bit_7 = (STR2[1] BAND $40) // Input 15
Rel_port2_Bit_6 = (STR2[1] BAND $20) // Input 14
Rel_port2_Bit_5 = (STR2[1] BAND $10) // Input 13
Rel_port2_Bit_4 = (STR2[1] BAND $08) // Input 12
Rel_port2_Bit_3 = (STR2[1] BAND $04) // Input 11
Rel_port2_Bit_2 = (STR2[1] BAND $02) // Input 10
Rel_port2_Bit_1 = (STR2[1] BAND $01) // Input 9

Rel_port3_Bit_8 = (STR3[1] BAND $80) // Input 24
Rel_port3_Bit_7 = (STR3[1] BAND $40) // Input 23
Rel_port3_Bit_6 = (STR3[1] BAND $20) // Input 22
Rel_port3_Bit_5 = (STR3[1] BAND $10) // Input 21
Rel_port3_Bit_4 = (STR3[1] BAND $08) // Input 20
Rel_port3_Bit_3 = (STR3[1] BAND $04) // Input 19
Rel_port3_Bit_2 = (STR3[1] BAND $02) // Input 18
Rel_port3_Bit_1 = (STR3[1] BAND $01) // Input 17


if (Rel_port1_Bit_1 = 1)
{
// do something
}
else
{
// do something
}
}


Thanks for help !

André

Comments

  • Options
    ericmedleyericmedley Posts: 4,177
    I'm not quite sure exactly what you're asking... But...

    How I'd approach what you're describing is to make a function that would ferret the bit values from each byte. There is not an easy way in Netlinx to quickly mine the bits from a hex char. You do have the usual bitwise operators.

    So a routine that made

    chr_buff=$a2. Would populate an 8 cell integer array

    1,0,1,0,0,0,1,0. For example.

    You'd probably need to create a data table from an array and basically evaluate the hex value and relate it to the integer array and transfer the value of the data table into the status array.

    Bottom line is that there's just not a slick way to do this.
  • Options
    jjamesjjames Posts: 2,908
    Can't help you with the parsing but . . . first thing's first. Your routine that you've put in define_program only runs once every 3/10 of a second, including the parsing. You are not parsing on the response from the device - which should be done in the STRING event of it. Instead, you're probably parsing from a previous response, not the one you just issued. If you're going to stick with this routine / logic, I would put your SEND_STRING at the bottom of the block rather than first thing.

    May I kindly suggest you take (or re-take) AMX's Programming 1 course. The logic you've displayed is terribly flawed, not to mention everything you're trying to do is covered in the first course of programming. Also, I'm sure tech support would be willing to help - that is if you have a valid dealer ID number when you call in. If you (or your boss) cannot afford P1 training, you can use Google to search for some documents that are (unfortunately) floating around.

    Good luck!
  • Options
    PhreaKPhreaK Posts: 966
    It sounds like you're a man (presumably) who could benefit greatly from learning about loops. For example, for your situation if you wanted to parse that info into a 64 element array of 0 / 1 values you could use something like the following:
    define_function char[64] parseToStateArray(char rxString[8]) {
    	stack_var char i
    	stack_var char j
    	stack_var char state[64]
    	for (i = 0; i < 8; i++) {
    		for (j = 7; j >= 0; j--) {
    			state[i << 3 + 8 - j] = rxString[i + 1] & 1 << j
    		}
    	}
    	return state
    }
    

    Much neater (and easier) than explicitly assigning all those values.

    I'd highly recommend having a browse through the NetLinx help files, and definitely get yourself to some AMX training, or even better some generic programming / logic training. The internet is your friend.

    Also, as jjames mentioned, you might want to reconsider the way you're handling that parsing.
Sign In or Register to comment.