News:

  • August 18, 2026, 12:12:06 AM

Login with username, password and session length

Author Topic: Do-More to MySQL Server  (Read 65021 times)

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6172
  • Yes Pinky, Do-more will control the world!
Re: Do-More to MySQL Server
« Reply #30 on: January 15, 2018, 02:18:14 PM »
Should be obvious...Head and Tail default to 0, and I will frequently zero out Head and Tail when empty. Flushing the Queue is just setting Head and Tail to zero.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

Bolt

  • Hero Member
  • *****
  • Posts: 598
Re: Do-More to MySQL Server
« Reply #31 on: January 15, 2018, 06:10:01 PM »
Head and Tail index....write to Head, then increment...read from Tail, then increment. Empty when Head == Tail, full when Adjusted(Tail+1) == Head. I generally make the wrap happen at powers of two (mask off the wrapped value), but it is arbitrary.

Should be obvious...Head and Tail default to 0, and I will frequently zero out Head and Tail when empty. Flushing the Queue is just setting Head and Tail to zero.

Thank you, I got it thinkered out.  I was overlooking the fact that the slots do not need to be emptied, per-say.

Do you mean full when Head+1 == Tail?

Can you explain the masking the wrap?  Currently I have a $tTopOfScan run if HeadPointer==64, HeadPointer=0, and the same for TailPointer.

What is the point of zeroing out the pointers when empty?

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6172
  • Yes Pinky, Do-more will control the world!
Re: Do-More to MySQL Server
« Reply #32 on: January 15, 2018, 06:39:10 PM »
Yeah sorry...when Head bumps Tail it's full.

Wrapping can be done by masking the upper bits...in your example 64 is 0x40, masked with (ANDed) 0x3F also yields 0. Can be done in the same math operation that you increment the index...Head=(Head+1)&0x3F.

No need to zero them. Just easier to read when debugging.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

plcnut

  • Hero Member
  • *****
  • Posts: 815
    • premiersi.com
Re: Do-More to MySQL Server
« Reply #33 on: January 15, 2018, 09:07:58 PM »
It is pretty amazing that a PLC can do it to begin with, and then to have so much flexibility is pretty cool!

And pretty sure that server won't run 19 axes of closed loop motion or 34 concurrent Modbus/RTU comm sessions, all while slapping 1K of relays at 100Hz.  ;)

Exactly!
I have a PC on a project that can do that sort of thing, but just the license to allow me to turn on the software is more than an entire Do-more system.
Circumstances don't determine who we are, they only reveal it.

~Jason Wolthuis
Premier Systems Integration, LLC
http://premiersi.com

Bolt

  • Hero Member
  • *****
  • Posts: 598
Re: Do-More to MySQL Server
« Reply #34 on: January 26, 2018, 11:56:57 AM »
Could you point me in the right direction regarding my head an tail pointers?

I have if Head > Tail, JMP to sending Stage.

How do I robustly preform the wrap around, when Head + 1 jumps from 127 to 0, how do I keep the sending stage active if needed?  I have tried a few things like if Head = 0, SET a bit, and when Tail = 0, RST the bit, but nothing seems to be 100% fail proof for me.  What direction do I need to be looking?

Is this why BobO suggested frequently zeroing out the head and the tail when empty?

plcnut

  • Hero Member
  • *****
  • Posts: 815
    • premiersi.com
Re: Do-More to MySQL Server
« Reply #35 on: January 26, 2018, 12:08:15 PM »
One way is to have a MATH box with
Code: [Select]
Result:
V0
Equation:
IF(V0<127,V0+1,0)

BobO was talking about using a mask, which I find intriguing, but the above example is how I do it.
Circumstances don't determine who we are, they only reveal it.

~Jason Wolthuis
Premier Systems Integration, LLC
http://premiersi.com

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6172
  • Yes Pinky, Do-more will control the world!
Re: Do-More to MySQL Server
« Reply #36 on: January 26, 2018, 12:34:58 PM »
MATH TotalInQueue = IF(Head >= Tail, Head-Tail, Head+128-Tail)

If new record available
   if TotalInQueue < 127
      AddNewRecord(Head)
      MATH Head = (Head+1)&0x7F
   else
      Queue full

If TotalInQueue > 0 then
   RecordToProcess = Tail
   Tail = (Tail+1)&0x7F
   DoTheThing(RecordToProcess)

It might looks something like the attachments.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6172
  • Yes Pinky, Do-more will control the world!
Re: Do-More to MySQL Server
« Reply #37 on: January 26, 2018, 12:38:40 PM »
One way is to have a MATH box with
Code: [Select]
Result:
V0
Equation:
IF(V0<127,V0+1,0)

BobO was talking about using a mask, which I find intriguing, but the above example is how I do it.

Same/same. My way processes considerably faster...which means precisely nothing, because they are both plenty fast.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

plcnut

  • Hero Member
  • *****
  • Posts: 815
    • premiersi.com
Re: Do-More to MySQL Server
« Reply #38 on: January 26, 2018, 12:41:58 PM »
Very nice BobO!
I have a way of getting into those situations where that little bit of "Faster" can be very important :)
Circumstances don't determine who we are, they only reveal it.

~Jason Wolthuis
Premier Systems Integration, LLC
http://premiersi.com

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6172
  • Yes Pinky, Do-more will control the world!
Re: Do-More to MySQL Server
« Reply #39 on: January 26, 2018, 12:45:32 PM »
Very nice BobO!
I have a way of getting into those situations where that little bit of "Faster" can be very important :)

I realized I left out the queue full check...we'll leave that as an exercise for the student. ;)

The speed difference is not huge in practice, but everything in the masked version runs in the hardware accelerator. I think the IF() is software.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

Bolt

  • Hero Member
  • *****
  • Posts: 598
Re: Do-More to MySQL Server
« Reply #40 on: January 26, 2018, 03:50:35 PM »
Thanks for the tips.  Here's what I came up with, second MATH block handles full queue scenarios.