One trick I use a lot - allows an imitation of the ternary operator in a lot of cases.
Boolean operations return 1 for true and 0 for false.
So use:
.v1 = (.v2 < 20) + 2. // 3 if v2 is < 20 else 2
.flag = (.v == 10) // flag true if v = 10
Martin
Search found 878 matches
- Fri Mar 15, 2024 6:18 am
- Forum: Feature Requests
- Topic: Ternary operator in calculation block?
- Replies: 7
- Views: 296
- Thu Mar 14, 2024 3:43 pm
- Forum: General
- Topic: Protocol j1587
- Replies: 80
- Views: 6761
Re: Protocol j1587
Is that 'in tractor' or only on the bench?
If it's in situ - how long are the leads to the Nextion display? Interfence might be affecting that?
If it's in situ - how long are the leads to the Nextion display? Interfence might be affecting that?
- Thu Mar 14, 2024 8:03 am
- Forum: General
- Topic: Protocol j1587
- Replies: 80
- Views: 6761
Re: Protocol j1587
Odd, how about waiting until the value changes from 128 - it sounds as though only the start byte is being received correctly. Can you just display (or send to uart) all the data received?
- Wed Mar 13, 2024 5:08 pm
- Forum: General
- Topic: Protocol j1587
- Replies: 80
- Views: 6761
Re: Protocol j1587
I tried this - I've used a timer interrupt to add data if running as a simulation.
- Wed Mar 13, 2024 4:24 pm
- Forum: General
- Topic: Protocol j1587
- Replies: 80
- Views: 6761
Re: Protocol j1587
I think the issue is - your code continually searches for 128 - and as soon as it is found - attempts to read 4 bytes from 'after' the 128.
These may not have been received yet...
So - one solution is wait for 128 to be found then wait until caunt_rx >= 4 and then display the values.
Martin
These may not have been received yet...
So - one solution is wait for 128 to be found then wait until caunt_rx >= 4 and then display the values.
Martin
- Wed Mar 13, 2024 9:44 am
- Forum: General
- Topic: Protocol j1587
- Replies: 80
- Views: 6761
Re: Protocol j1587
Just done a quick test I did PutArray(.test, 10) LookForValue(.seek, 1, true, true) Where test = {x,x,x,128,129...) where x is any value and seek[0] = 128 LookForValue just returns 1 if the search value is found. (would the index (or -1) be better?) Then GetByte returns the 'following' data So in th...
- Wed Mar 13, 2024 9:32 am
- Forum: General
- Topic: Protocol j1587
- Replies: 80
- Views: 6761
Re: Protocol j1587
You can set a character in a string to 128.as above. Each character is a byte. You can set values using a number as shown or a character (in single quotes) or set the whole string.
- Wed Mar 13, 2024 7:48 am
- Forum: General
- Topic: Protocol j1587
- Replies: 80
- Views: 6761
Re: Protocol j1587
You can use LookForValue with a byte array or a string.
byte or string .val[1] // Looking for 1 value
.val[0] = 128
Then use LookForValue(.val, 1, ...)
Martin
byte or string .val[1] // Looking for 1 value
.val[0] = 128
Then use LookForValue(.val, 1, ...)
Martin
- Sun Mar 10, 2024 11:47 am
- Forum: General
- Topic: Macro from external program memory
- Replies: 6
- Views: 296
Re: Macro from external program memory
There is a programming axiom "any program can be optimised by at least one instruction" - though taken to its logical conclusion it implies that the best programs have no instructions at all. I would suspect splitting some code to a second MCU will be quite tricky - why not just use one with more me...
- Sun Mar 10, 2024 7:26 am
- Forum: General
- Topic: Any Pin Interrupt
- Replies: 6
- Views: 232
Re: Any Pin Interrupt
Which MCU are you using. Some, such as the Atmega 328p in the Arduino only have hardware interrupts on specific pins. Other MCUs allow more pins to be used - look up custom interrupt in the Wiki. There is an Arduino library that mimics interrupts on any pin - but this just checks the pin state regul...