Hello Guest it is March 28, 2024, 07:00:27 PM

Author Topic: How to read/write Analog Inputs and Analog Outputs  (Read 2394 times)

0 Members and 1 Guest are viewing this topic.

Offline bcoop

*
  •  61 61
    • View Profile
How to read/write Analog Inputs and Analog Outputs
« on: May 09, 2020, 08:39:51 PM »
Can anyone tell me how to read and write the Analog input & output values, If I make an assignment as seen in the screen shot, how do I address Analog Input #1 in a script.
there must be an addressable means such as ISIG_INPUT1 for the analogs?

Bob
Bob

Offline thosj

*
  •  532 532
    • View Profile
Re: How to read/write Analog Inputs and Analog Outputs
« Reply #1 on: May 10, 2020, 08:02:19 AM »
Look down thread for a topic about Manual Spindle Start Switch. On the second page I outline how I've used two of those. Might give you a start on whatever you're looking to do.

Tom
--
Tom

Offline bcoop

*
  •  61 61
    • View Profile
Re: How to read/write Analog Inputs and Analog Outputs
« Reply #2 on: May 10, 2020, 10:42:21 AM »
Thanks Tom. that thread looks like a way to read the pokeys57 registers directly,  what i am attempting to do is utilize the Mach Analog inputs and outputs, assigning pokey and other devices to the Mach4 analogs and read/write within scripting. I would think there would be some tags associated with them
Bob

Offline jbuehn

*
  •  101 101
    • View Profile
Re: How to read/write Analog Inputs and Analog Outputs
« Reply #3 on: May 10, 2020, 11:52:54 AM »
There are specific API functions for analog that you can find in ZeroBrane. I think they just use the actual analog input/output #?
Re: How to read/write Analog Inputs and Analog Outputs
« Reply #4 on: May 10, 2020, 09:21:37 PM »
Hi,
the analogue values are stored in registers. The individual registers are 'owned' by the PoKeys board.

If you go to the Register Diagnostics page and expand the PoKeys register tree you will see the registers you require.

To read the value first you must get the handle of the register using mc.mcRegGetHandle() and then read the value with
mc.mcRegGetValue or mc.mcRegGetValueString().

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'

Offline bcoop

*
  •  61 61
    • View Profile
Re: How to read/write Analog Inputs and Analog Outputs
« Reply #5 on: May 10, 2020, 10:17:00 PM »
Craig, thanks for your response,  my question is not really related to Pokey registers, it is how to read Mach's "Analog Input #1" register.  I am just not finding anything in the API reference or any other documents. Also do not see any reference to the Mach Analog registers in the register plugin under diagnostics.

If I wanted to Read "Pokeys Analog Input 41" .........then i would use  PoKeys_50590/Analog input 41  (register)
if I wanted to Write "Output #1"  ..........................then I would use mc.OSIG_OUTPUT1   
if I wanted to Read "Input #1"  ............................then i would use  mc.ISIG_INPUT1 
if I wanted to Read "Analog Input #1"  ..................then what would i use ?
if I wanted to Write "Analog Output #1"  ...............then what would i use ?

Bob
Bob
Re: How to read/write Analog Inputs and Analog Outputs
« Reply #6 on: May 10, 2020, 11:27:35 PM »
Hi,

Quote
if I wanted to Read "Analog Input #1"  ..................then what would i use ?
if I wanted to Write "Analog Output #1"  ...............then what would i use ?

To my knowledge there is no such thing as 'Analog Input #1' or 'Analog Output #1'. You could certainly define registers like that
under iRegs0 for instance.

Your examples Output#1 and Input#1 are Boolean signals whereas an analogue value is a number and requires a register not a signal.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'

Offline jbuehn

*
  •  101 101
    • View Profile
Re: How to read/write Analog Inputs and Analog Outputs
« Reply #7 on: May 11, 2020, 03:39:25 AM »
value, rc = mc.mcAnalogInputRead(inst: number, analogInputNum: number)
value, rc = mc.mcAnalogOutputRead(inst: number, analogOutputNum: number)
rc = mc.mcAnalogOutputWrite(inst: number, analogOutputNum: number, value: number)

They don't look like they're in the API docs yet, but if you're in ZeroBrane they should come up as suggestions.

I've never used them, though I think analogInputNum and analogOutputNum is just the number of the input or output? So to read "Analog Input 1" it'd be mc.mcAnalogInputRead(inst, 1), given you have that assigned to something in Mach4's Config.
Re: How to read/write Analog Inputs and Analog Outputs
« Reply #8 on: May 11, 2020, 04:16:26 AM »
Hi,
I can't find that API in API.chm, neither does it come up in ZeroBrane.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'

Offline bcoop

*
  •  61 61
    • View Profile
Re: How to read/write Analog Inputs and Analog Outputs
« Reply #9 on: May 11, 2020, 08:09:30 AM »
Thank you all for your input on this, 

I have tried    local value1 = mc.mcAnalogInputRead(inst, 1 ) which always displays 0.0

directly reading the register assigned to Mach Analog Input #1,   displays the correct value,
    hReg= mc.mcRegGetHandle(inst, "PoKeys_50590/Analog input 41")
    local value2 = mc.mcRegGetValue(hReg)

I have tried numerous variations of reading the Reg Handle of Analog Input #1 without any luck
Possibly these have not been fully implemented yet, I will submit a ticket and see if i can find out anything more, will report back to this thread

Thanks again
Bob
Bob